-
Notifications
You must be signed in to change notification settings - Fork 56
226 lines (202 loc) · 6.92 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Docker Build
on:
push:
release:
types: [published, prereleased]
jobs:
build:
runs-on: ubuntu-latest
name: Build Docker Image
strategy:
matrix:
include:
- arch: linux/386
hass_arch: i386
- arch: linux/amd64
hass_arch: amd64
- arch: linux/arm/v6
hass_arch: armv6
- arch: linux/arm/v7
hass_arch: armv7
- arch: linux/arm64
hass_arch: aarch64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
# https://github.com/crazy-max/ghaction-docker-buildx/issues/172
- name: Hack Docker FS to Build cryptography on armv6/armv7
if: ${{ matrix.hass_arch == 'armv6' || matrix.hass_arch == 'armv7' }}
run: |
set -x
df -h
sudo swapon --show
sudo dd if=/dev/zero of=/swapfile1 bs=1M count=6K
sudo chmod 600 /swapfile1
sudo mkswap /swapfile1
sudo swapon /swapfile1
sudo swapon --show
sudo free -h
sudo systemctl stop docker
sudo mount -t tmpfs -o size=9G tmpfs /var/lib/docker
df -h
sudo systemctl start docker
- name: Cache Docker layers
uses: actions/[email protected]
continue-on-error: true
with:
path: /tmp/.buildx-cache
key: ${{ matrix.arch }}-${{ github.sha }}
restore-keys: |
${{ matrix.arch }}-
# label version as branch-run_number
- name: Build Branch
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
set -x
docker build \
--build-arg HASS_ARCH=${{ matrix.hass_arch }} \
--build-arg BUILD_VERSION=${GITHUB_REF##*/}-${{ github.run_number }} \
--tag ci:${{ github.run_number }} \
--platform ${{ matrix.arch }} \
--progress plain \
--file ./docker/Dockerfile \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
.
# label version as tag
- name: Build Tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
set -x
docker build \
--build-arg HASS_ARCH=${{ matrix.hass_arch }} \
--build-arg BUILD_VERSION=${GITHUB_REF##*/} \
--tag ci:${{ github.run_number }} \
--platform ${{ matrix.arch }} \
--progress plain \
--file ./docker/Dockerfile \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
.
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Inspect
run: |
set -x
docker image inspect ci:${{ github.run_number }}
docker history --no-trunc ci:${{ github.run_number }}
- name: Save tarball
run: |
set -x
docker save --output ci-${{ matrix.hass_arch }}-${{ github.run_number }}.tar.gz ci:${{ github.run_number }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ci-${{ matrix.hass_arch }}-${{ github.run_number }}
path: ci-${{ matrix.hass_arch }}-${{ github.run_number }}.tar.gz
publish:
needs: build
name: Publish Image
runs-on: ubuntu-latest
if: ${{ !startsWith(github.ref, 'refs/pull/') && !startsWith(github.ref, 'refs/heads/dependabot/') }}
strategy:
matrix:
arch: [i386, amd64, armv6, armv7, aarch64]
registry:
- {
url: ghcr.io/hass-emulated-hue,
username: GCHR_USERNAME,
password: GHCR_PAT,
repo: ghcr.io/hass-emulated-hue/core,
}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download container artifact
uses: actions/download-artifact@v3
with:
name: ci-${{ matrix.arch }}-${{ github.run_number }}
- name: Import image
run: |
docker load --input ci-${{ matrix.arch }}-${{ github.run_number }}.tar.gz
- name: Docker login
run: |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }}
- name: Push image
# if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker/publish.py \
--tag ${GITHUB_REF##*/} \
--repo ${{ matrix.registry.repo }} \
--image \
--ci \
--arch ${{ matrix.arch }} \
--image-name ci:${{ github.run_number }} \
--latest
- name: Push image
# if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: ${{ github.ref != 'refs/heads/master' }}
run: |
docker/publish.py \
--tag ${GITHUB_REF##*/} \
--repo ${{ matrix.registry.repo }} \
--image \
--ci \
--arch ${{ matrix.arch }} \
--image-name ci:${{ github.run_number }}
create_manifest:
needs: publish
name: Create Manifest
runs-on: ubuntu-latest
strategy:
matrix:
registry:
- {
url: ghcr.io/hass-emulated-hue,
username: GCHR_USERNAME,
password: GHCR_PAT,
repo: ghcr.io/hass-emulated-hue/core,
}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Enable Experimental Docker Features
run: |
export DOCKER_CLI_EXPERIMENTAL="enabled"
echo "DOCKER_CLI_EXPERIMENTAL=${DOCKER_CLI_EXPERIMENTAL}" >> $GITHUB_ENV
- name: Docker login
run: |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }}
- name: Create Manifest
# if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker/publish.py \
--tag ${GITHUB_REF##*/} \
--repo ${{ matrix.registry.repo }} \
--manifest \
--ci \
--latest
- name: Create Manifest
# if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: ${{ github.ref != 'refs/heads/master' }}
run: |
docker/publish.py \
--tag ${GITHUB_REF##*/} \
--repo ${{ matrix.registry.repo }} \
--manifest \
--ci