-
-
Notifications
You must be signed in to change notification settings - Fork 1
211 lines (179 loc) · 7.15 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
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
---
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches:
- master
release:
types:
- released
schedule:
- cron: "30 8 * * *"
env:
DOCKER_NAMESPACE: wayofdev/php-dev
GHCR_NAMESPACE: ghcr.io/wayofdev/docker-php-dev
name: 🚀 Build docker images with latest tag
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: false
matrix:
os_name: ["alpine"]
php_version: ["8.1", "8.2", "8.3", "8.4"]
php_type: ["fpm", "cli", "supervisord"]
builder: [{arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "ubuntu-latest"}]
runs-on: ${{ matrix.builder.os }}
steps:
- name: 🌎 Set environment variables
run: |
php_version="${{ matrix.php_version }}"
tag="${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-${{ matrix.builder.arch }}"
php_version_slug="${php_version//./}"
target="php-${php_version_slug}-${{ matrix.php_type }}-${{ matrix.os_name }}"
echo "TARGET=${target}" >> "$GITHUB_ENV"
echo "PLATFORM_CACHE_TAG=${tag}" >> "$GITHUB_ENV"
- name: 📦 Check out the codebase
uses: actions/[email protected]
- name: 🤖 Generate dist files
run: ansible-playbook src/playbook.yml -l ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}
- name: 🖥️ Setup docker QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/${{ matrix.builder.arch }}
- name: 🛠️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/${{ matrix.builder.arch }}
buildkitd-flags: "--debug"
- name: 🐳 Extract docker meta data
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_NAMESPACE }}
${{ env.GHCR_NAMESPACE }}
tags: |
type=raw,event=branch,value=latest
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
flavor: |
latest=false
prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-
- name: ⚙️ Rename meta bake definition file
run: |
mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta-${{ env.PLATFORM_CACHE_TAG }}.json"
- name: 📤 Upload meta bake definition
uses: actions/upload-artifact@v4
with:
name: bake-meta-${{ env.PLATFORM_CACHE_TAG }}.json
path: /tmp/bake-meta-*.json
if-no-files-found: error
retention-days: 1
- name: 🔑 Login to docker-hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: 🔑 Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🚀 Bake image and push to docker-hub and GHCR
id: bake
uses: docker/[email protected]
with:
targets: ${{ env.TARGET }}
files: |
./docker-bake.hcl
/tmp/bake-meta-${{ env.PLATFORM_CACHE_TAG }}.json
set: |
*.tags=
*.platform=linux/${{ matrix.builder.arch }}
*.cache-from=type=gha,scope=build-${{ env.PLATFORM_CACHE_TAG }}
*.cache-to=type=gha,scope=build-${{ env.PLATFORM_CACHE_TAG }}
*.output=type=image,"name=${{ env.DOCKER_NAMESPACE }},${{ env.GHCR_NAMESPACE }}",push-by-digest=true,name-canonical=true,push=true
- name: 📥 Export digest
run: |
mkdir -p /tmp/digests
echo "Bake Metadata: ${{ steps.bake.outputs.metadata }}"
digest=$(echo '${{ steps.bake.outputs.metadata }}' | jq -r '.["${{ env.TARGET }}"]["containerimage.digest"]')
if [[ -z "$digest" || "$digest" == "null" ]]; then
echo "Digest not found."
exit 1
fi
echo "Digest: $digest"
touch "/tmp/digests/${digest#sha256:}"
- name: 📤 Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_CACHE_TAG }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
needs: build
runs-on: ubuntu-latest
steps:
- name: 📥 Download meta bake definitions
uses: actions/download-artifact@v4
with:
pattern: bake-meta-*
path: /tmp
merge-multiple: true
- name: 📥 Download meta bake definitions
uses: actions/download-artifact@v4
with:
pattern: digests-*
path: /tmp/digests
- name: 🔑 Login to docker-hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: 🔑 Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🖥️ Setup docker QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: 🛠️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
buildkitd-flags: "--debug"
- name: 📦 Check out the codebase
uses: actions/[email protected]
- name: 🚀 Create manifest list and push
working-directory: /tmp
run: |
variants=($(ls bake-meta-*.json | sed -E 's/bake-meta-//; s/-amd64.json|-arm64.json//g' | sort -u))
for variant in "${variants[@]}"; do
# Fetch digests for amd64 and arm64 architectures
DIGEST_AMD64=$(basename $(ls /tmp/digests/digests-${variant}-amd64/*))
DIGEST_ARM64=$(basename $(ls /tmp/digests/digests-${variant}-arm64/*))
echo "Digest AMD64: $DIGEST_AMD64"
echo "Digest ARM64: $DIGEST_ARM64"
# Create the manifest list for Docker Hub
docker buildx imagetools create $(jq -cr ".target.\"docker-metadata-action\".tags | map(select(startswith(\"${DOCKER_NAMESPACE}\")) | \"-t \" + .) | join(\" \")" /tmp/bake-meta-${variant}-amd64.json) \
"${DOCKER_NAMESPACE}@sha256:${DIGEST_AMD64}" \
"${DOCKER_NAMESPACE}@sha256:${DIGEST_ARM64}"
# Create the manifest list for GHCR
docker buildx imagetools create $(jq -cr ".target.\"docker-metadata-action\".tags | map(select(startswith(\"${GHCR_NAMESPACE}\")) | \"-t \" + .) | join(\" \")" /tmp/bake-meta-${variant}-amd64.json) \
"${GHCR_NAMESPACE}@sha256:${DIGEST_AMD64}" \
"${GHCR_NAMESPACE}@sha256:${DIGEST_ARM64}"
done
# - name: 🚀 Create manifest list and push
# shell: bash
# run: .github/scripts/build-images.sh
...