forked from MiczFlor/RPi-Jukebox-RFID
-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (166 loc) · 6.91 KB
/
test_docker_debian_codename_sub.yml
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
name: Subworkflow Test Install Scripts Debian
on:
workflow_call:
inputs:
debian_codename:
required: true
type: string
platform:
required: true
type: string
docker_image_name:
required: false
type: string
default: rpi-jukebox-rfid
cache_scope:
required: false
type: string
default: ${{ github.ref }}-test-debian
local_registry_port:
required: false
type: number
default: 5000
runs_on:
required: false
type: string
default: ubuntu-latest
# let only one instance run the test so cache is not corrupted.
# cancel already running instances as only the last run will be relevant
concurrency:
group: ${{ inputs.cache_scope }}-${{ inputs.debian_codename }}-${{ inputs.platform }}
cancel-in-progress: true
jobs:
# Build container for test execution
build:
runs-on: ${{ inputs.runs_on }}
outputs:
cache_key: ${{ steps.vars.outputs.cache_key }}
image_file_name: ${{ steps.vars.outputs.image_file_name }}
image_tag_name: ${{ steps.vars.outputs.image_tag_name }}
docker_run_options: ${{ steps.vars.outputs.docker_run_options }}
# create local docker registry to use locally build images
services:
registry:
image: registry:2
ports:
- ${{ inputs.local_registry_port }}:5000
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
# network=host driver-opt needed to push to local registry
driver-opts: network=host
- name: Set Output pre-vars
id: pre-vars
env:
DEBIAN_CODENAME: ${{ inputs.debian_codename }}
DOCKER_IMAGE_NAME: ${{ inputs.docker_image_name }}
CACHE_SCOPE: ${{ inputs.cache_scope }}
PLATFORM: ${{ inputs.platform }}
run: |
PLATFORM=${PLATFORM////_}
echo "image_tag_name=${{ env.DOCKER_IMAGE_NAME }}:${{ env.DEBIAN_CODENAME }}-${PLATFORM}-test" >> $GITHUB_OUTPUT
echo "image_file_name=${{ env.DOCKER_IMAGE_NAME }}-${{ env.DEBIAN_CODENAME }}-${PLATFORM}.tar" >> $GITHUB_OUTPUT
echo "cache_scope=${{ env.CACHE_SCOPE }}-${{ env.DEBIAN_CODENAME }}-${PLATFORM}" >> $GITHUB_OUTPUT
- name: Set Output vars
id: vars
env:
LOCAL_REGISTRY_PORT: ${{ inputs.local_registry_port }}
PLATFORM: ${{ inputs.platform }}
run: |
echo "image_tag_name=${{ steps.pre-vars.outputs.image_tag_name }}" >> $GITHUB_OUTPUT
echo "image_tag_name_local_base=localhost:${{ env.LOCAL_REGISTRY_PORT }}/${{ steps.pre-vars.outputs.image_tag_name }}-base" >> $GITHUB_OUTPUT
echo "image_file_name=${{ steps.pre-vars.outputs.image_file_name }}" >> $GITHUB_OUTPUT
echo "image_file_path=./${{ steps.pre-vars.outputs.image_file_name }}" >> $GITHUB_OUTPUT
echo "cache_scope=${{ steps.pre-vars.outputs.cache_scope }}" >> $GITHUB_OUTPUT
echo "cache_key=${{ steps.pre-vars.outputs.cache_scope }}-${{ github.sha }}#${{ github.run_attempt }}" >> $GITHUB_OUTPUT
if [ "${{ env.PLATFORM }}" == "linux/arm/v6" ] ; then
echo "docker_run_options=-e QEMU_CPU=arm1176" >> $GITHUB_OUTPUT
fi
# Build base image for debian version name. Layers will be cached and image pushes to local registry
- name: Build Image - Base
uses: docker/build-push-action@v6
with:
context: .
load: false
push: true
file: ./ci/Dockerfile.debian
target: test-code
platforms: ${{ inputs.platform }}
tags: ${{ steps.vars.outputs.image_tag_name_local_base }}
cache-from: type=gha,scope=${{ steps.vars.outputs.cache_scope }}
cache-to: type=gha,mode=max,scope=${{ steps.vars.outputs.cache_scope }}
build-args: |
DEBIAN_CODENAME=${{ inputs.debian_codename }}
GIT_BRANCH=${{ github.head_ref || github.ref_name }}
GIT_URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name || github.repository }}
# Build new image with updates packages based on base image. Layers will NOT be chached. Result is written to file.
- name: Build Image - Update
uses: docker/build-push-action@v6
with:
context: .
load: false
push: false
file: ./ci/Dockerfile.debian
target: test-update
platforms: ${{ inputs.platform }}
tags: ${{ steps.vars.outputs.image_tag_name }}
cache-from: type=gha,scope=${{ steps.vars.outputs.cache_scope }}
# DON'T use 'cache-to' here as the layer is then cached and this build would be useless
outputs: type=docker,dest=${{ steps.vars.outputs.image_file_path }}
build-args: |
BASE_TEST_IMAGE=${{ steps.vars.outputs.image_tag_name_local_base }}
- name: Artifact Upload Docker Image
uses: actions/upload-artifact@v4
with:
name: ${{ steps.vars.outputs.image_file_name }}
path: ${{ steps.vars.outputs.image_file_path }}
retention-days: 2
# Run tests with build image
test:
needs: [build]
runs-on: ${{ inputs.runs_on }}
strategy:
fail-fast: false
matrix:
username: ['pi']
test_script: ['run_installation_classic.sh', 'run_installation_rfid.sh', 'run_installation_spotify.sh', 'run_installation_staticip_dhcpcd.sh', 'run_installation_autohotspot_dhcpcd.sh', 'run_installation_autohotspot_NetworkManager.sh']
include:
- username: 'hans'
test_script: 'run_installation_classic.sh'
steps:
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Artifact Download Docker Image
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.image_file_name }}
- name: Load Docker Image
run: |
docker load --input ${{ needs.build.outputs.image_file_name }}
# Run test
- name: Run Test ${{ inputs.debian_codename }}-${{ matrix.username }}-${{ matrix.test_script }}
uses: tj-actions/docker-run@v2
with:
image: ${{ needs.build.outputs.image_tag_name }}
options: ${{ needs.build.outputs.docker_run_options }} --platform ${{ inputs.platform }} --user ${{ matrix.username }} --init
name: ${{ matrix.test_script }}
args: |
./${{ matrix.test_script }}
# cleanup after test execution
cleanup:
# run only if tests didn't fail: keep the artifact to make job reruns possible
if: ${{ !failure() }}
needs: [build, test]
runs-on: ${{ inputs.runs_on }}
steps:
- name: Artifact Delete Docker Image
uses: geekyeggo/delete-artifact@v5
with:
name: ${{ needs.build.outputs.image_file_name }}
failOnError: false