-
Notifications
You must be signed in to change notification settings - Fork 20
176 lines (134 loc) · 4.36 KB
/
build.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
name: "Build container image"
on:
push:
branches:
- main
tags:
- "*"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
env:
IMAGE_NAME: ghcr.io/octoprint/custopizer
jobs:
build:
name: "🏗 Build"
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tags[0] }}
digest: ${{ steps.docker_build.outputs.digest }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: "⬇ Checkout"
uses: actions/checkout@v4
- name: "🐳 Login to GHCR"
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔍️ Determine metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: "🐳 Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
- name: "🏗 Build & push by digest"
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./src
platforms: linux/amd64,linux/arm64
# metadata
labels: ${{ steps.meta.outputs.labels }}
# inline cache
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }}
cache-to: type=inline
# export
outputs: type=image,"name=${{ env.IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true
test:
name: "🧪 Test"
needs: build
strategy:
fail-fast: false
matrix:
os: [ "ubuntu-latest", "ubuntu-22.04-arm" ]
arch: [ "armhf", "arm64" ]
runs-on: "${{ matrix.os }}"
steps:
- name: "⬇ Checkout"
uses: actions/checkout@v4
- name: "🛠 Prepare workspace with a fresh RPi lite image"
shell: bash
run: |
DOWNLOAD_URL="https://downloads.raspberrypi.org/raspios_lite_${{ matrix.arch }}_latest.torrent"
HASH_URL="https://downloads.raspberrypi.org/raspios_lite_${{ matrix.arch }}_latest.sha256"
mkdir -p workspace
cd workspace
aria2c -d . --seed-time=0 "$DOWNLOAD_URL"
# verify checksum
curl -Ls $HASH_URL | sha256sum -c
# search for the image file
IMG_FILE=$(ls *.img.xz | head -n 1)
echo "Found compressed Image file: ${IMG_FILE}"
# extract the image file
xz -d "${IMG_FILE}"
DECOMPRESSED_FILE="${IMG_FILE%.xz}"
echo "Image file: ${DECOMPRESSED_FILE}"
# rename the image file
mv "${DECOMPRESSED_FILE}" input.img
- name: "🛠 Prepare test scripts"
shell: bash
run: |
mkdir -p scripts
cp .github/tests/00-hello-world scripts/
- name: 🧪 Perform test build
shell: bash
run: |
sudo modprobe loop
case "${{ matrix.arch }}" in
arm64)
EDITBASE_ARCH="arm64"
;;
*)
EDITBASE_ARCH="armv7l"
;;
esac
IMAGE="${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }}"
COMMAND="--rm --privileged -e EDITBASE_ARCH=$EDITBASE_ARCH -v ${{ github.workspace }}/workspace:/CustoPiZer/workspace -v ${{ github.workspace }}/scripts:/CustoPiZer/workspace/scripts $IMAGE"
echo "About to execute 'docker run $COMMAND'..."
docker run $COMMAND
deploy:
name: "📦 Deploy"
needs:
- build
- test
runs-on: "ubuntu-latest"
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: "🐳 Login to GHCR"
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔍️ Determine metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: "📦️ Tag image in registry"
run: |
IMAGE="${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }}"
TAGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
docker buildx imagetools create $TAGS $IMAGE