-
-
Notifications
You must be signed in to change notification settings - Fork 628
143 lines (122 loc) · 4.13 KB
/
docker-build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Docker Image Build
on:
push:
branches:
- master
paths:
- '**'
- '!webview/**'
- '!website/**'
- '!.github/workflows/deploy-website.yaml'
- '!.github/workflows/build-webview.yaml'
- '!.github/workflows/build-balena-disk-image.yaml'
- '!.github/workflows/python-lint.yaml'
- '!.github/pull_request_template.md'
- '!README.md'
- '!docs/**'
- '!bin/install.sh'
- '!bin/upgrade_containers.sh'
- '!bin/start_development_server.sh'
- '!tests/**'
- '!docker/Dockerfile.dev'
jobs:
run-tests:
uses: ./.github/workflows/docker-test.yaml
buildx:
needs: run-tests
strategy:
matrix:
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi5', 'x86']
python-version: ["3.11"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: ~/.venv
installer-parallel: true
- name: Install dependencies
run: |
poetry install --only=docker-image-builder
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ matrix.board }}
restore-keys: |
${{ runner.os }}-${{ matrix.board }}
- name: Login to DockerHub
if: success() && github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Containers
run: |
poetry run python -m tools.image_builder \
--build-target=${{ matrix.board }} \
--push
balena:
if: ${{ github.ref == 'refs/heads/master' }}
needs: buildx
strategy:
matrix:
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi5']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Docker tag
run: |
echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BOARD=${{ matrix.board }}" >> $GITHUB_ENV
echo "SHM_SIZE=256mb" >> $GITHUB_ENV
- name: Prepare Balena file
run: |
# Generage a docker-compose file for Balena with the correct board
mkdir -p balena-deploy
# Copy in the Balena yaml file
cp balena.yml balena-deploy/
# Generate the docker-compose file
cat docker-compose.balena.yml.tmpl | \
envsubst > balena-deploy/docker-compose.yml
# Remove bind mounts to `/dev/vchiq` for Raspberry Pi 5
if [ "${{ matrix.board }}" == "pi5" ]; then
sed -i '/devices:/ {N; /\n.*\/dev\/vchiq:\/dev\/vchiq/d}' \
balena-deploy/docker-compose.yml
fi
- uses: balena-io/deploy-to-balena-action@master
id: build
continue-on-error: true
with:
balena_token: ${{ secrets.BALENA_TOKEN }}
fleet: screenly_ose/anthias-${{ matrix.board }}
source: balena-deploy
- name: Sleep random sleep before retry
if: ${{ failure() && steps.build.conclusion == 'failure' }}
run: |
sleep $((120 + RANDOM % 900));
# Balena deploy often fails with 'ESOCKETTIMEDOUT'.
# This adds some retry logic.
- uses: balena-io/deploy-to-balena-action@master
id: build-retry
if: ${{ failure() && steps.build.conclusion == 'failure' }}
with:
balena_token: ${{ secrets.BALENA_TOKEN }}
fleet: screenly_ose/anthias-${{ matrix.board }}
source: balena-deploy