Skip to content

Commit 8dd7477

Browse files
committed
Adjust paths
1 parent 12b23aa commit 8dd7477

File tree

2 files changed

+240
-0
lines changed

2 files changed

+240
-0
lines changed
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
name: Build multi-arch image
2+
3+
on:
4+
workflow_call:
5+
###
6+
### Variables
7+
###
8+
inputs:
9+
name:
10+
description: 'Name of the service to build (used for job names only).'
11+
required: true
12+
type: string
13+
enabled:
14+
description: 'Determines wheather this workflow is enabled at all (will run or skip).'
15+
required: true
16+
type: boolean
17+
can_deploy:
18+
description: 'Determines wheather this workflow will also deploy (login and push).'
19+
required: true
20+
type: boolean
21+
version:
22+
description: 'The version build matrix as JSON string (list of PHP versions).'
23+
required: true
24+
type: string
25+
arch:
26+
description: 'The architecture build matrix as JSON string (list of architectures).'
27+
required: true
28+
type: string
29+
refs:
30+
description: 'The ref build matrix as JSON string (list of git refs to build/deploy).'
31+
required: false
32+
type: string
33+
###
34+
### Secrets
35+
###
36+
secrets:
37+
dockerhub_username:
38+
description: 'The username for Dockerhub.'
39+
required: false
40+
dockerhub_password:
41+
description: 'The password for Dockerhub.'
42+
required: false
43+
44+
jobs:
45+
46+
# -----------------------------------------------------------------------------------------------
47+
# JOB (1/3): CONFIGURE
48+
# -----------------------------------------------------------------------------------------------
49+
configure:
50+
name: Configure
51+
runs-on: ubuntu-latest
52+
outputs:
53+
can_login: ${{ steps.set-login.outputs.can_login }}
54+
has_refs: ${{ steps.set-matrix.outputs.has_refs }}
55+
matrix_build: ${{ steps.set-matrix.outputs.matrix_build }}
56+
matrix_deploy: ${{ steps.set-matrix.outputs.matrix_deploy }}
57+
manifest: ${{ steps.set-manifest-arch.outputs.manifest }}
58+
if: inputs.enabled
59+
steps:
60+
- name: "[EXPORT] Set Docker login capabilities"
61+
id: set-login
62+
shell: bash
63+
run: |
64+
if [ "${{ env.ENV_USER }}" = '' ] || [ "${{ env.ENV_PASS }}" = '' ]; then
65+
echo "::set-output name=can_login::0"
66+
else
67+
echo "::set-output name=can_login::1"
68+
fi
69+
env:
70+
ENV_USER: ${{ secrets.dockerhub_username }}
71+
ENV_PASS: ${{ secrets.dockerhub_password }}
72+
73+
- name: "[EXPORT] Set Build & Deploy Matrix"
74+
id: set-matrix
75+
shell: bash
76+
run: |
77+
if [ "${{ inputs.refs }}" != "" ]; then
78+
echo '::set-output name=matrix_build::{"version":${{ inputs.version }},"arch":${{ inputs.arch }},"refs":${{ inputs.refs }}}'
79+
echo '::set-output name=matrix_deploy::{"version":${{ inputs.version }},"refs":${{ inputs.refs }}}'
80+
echo '::set-output name=has_refs::1'
81+
else
82+
echo '::set-output name=matrix_build::{"version":${{ inputs.version }},"arch":${{ inputs.arch }}}'
83+
echo '::set-output name=matrix_deploy::{"version":${{ inputs.version }}}'
84+
echo '::set-output name=has_refs::0'
85+
fi
86+
87+
- name: "[EXPORT] Set Manifest 'Arch'"
88+
id: set-manifest-arch
89+
run: |
90+
ARCH="$( echo ${{ inputs.arch }} | sed 's/"//g' | sed 's/\[//g' | sed 's/\]//g' | sed 's/ //g' )"
91+
echo "::set-output name=manifest::${ARCH}"
92+
93+
- name: "[DEBUG] Workflow Inputs"
94+
shell: bash
95+
run: |
96+
echo 'name: ${{ inputs.name }} '
97+
echo 'enabled: ${{ inputs.enabled }} '
98+
echo 'can_deploy: ${{ inputs.can_deploy }} '
99+
echo 'refs: ${{ inputs.refs }} '
100+
echo 'version: ${{ inputs.version }} '
101+
echo 'arch: ${{ inputs.arch }} '
102+
103+
- name: "[DEBUG] Determined Settings"
104+
shell: bash
105+
run: |
106+
echo 'can_login=${{ steps.set-login.outputs.can_login }}'
107+
echo 'has_refs=${{ steps.set-matrix.outputs.has_refs }}'
108+
echo 'matrix_build=${{ steps.set-matrix.outputs.matrix_build }}'
109+
echo 'matrix_deploy=${{ steps.set-matrix.outputs.matrix_deploy }}'
110+
echo 'manifest=${{ steps.set-manifest-arch.outputs.manifest }}'
111+
112+
# -----------------------------------------------------------------------------------------------
113+
# JOB (2/3): BUILD
114+
# -----------------------------------------------------------------------------------------------
115+
build:
116+
needs: [configure]
117+
name: Build ${{ inputs.name }}-${{ matrix.version }} (${{ matrix.arch }}) ${{ matrix.refs }}
118+
runs-on: ubuntu-latest
119+
strategy:
120+
fail-fast: false
121+
matrix: ${{ fromJson(needs.configure.outputs.matrix_build) }}
122+
if: inputs.enabled
123+
steps:
124+
# ------------------------------------------------------------
125+
# Setup repository
126+
# ------------------------------------------------------------
127+
- name: "[SETUP] Checkout repository (current)"
128+
uses: actions/checkout@v2
129+
with:
130+
fetch-depth: 0
131+
if: needs.configure.outputs.has_refs == 0
132+
133+
- name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})"
134+
uses: actions/checkout@v2
135+
with:
136+
fetch-depth: 0
137+
ref: ${{ matrix.refs }}
138+
if: needs.configure.outputs.has_refs != 0
139+
140+
- name: "[SETUP] Setup QEMU environment"
141+
uses: docker/setup-qemu-action@v1
142+
with:
143+
image: tonistiigi/binfmt:latest
144+
platforms: all
145+
146+
- name: "[SETUP] Determine Docker tag"
147+
id: tag
148+
uses: cytopia/[email protected]
149+
150+
- name: "[SETUP] Determine Docker login"
151+
run: |
152+
echo ${{ needs.configure.outputs.can_login }}
153+
154+
# ------------------------------------------------------------
155+
# Build
156+
# ------------------------------------------------------------
157+
- name: Build
158+
uses: cytopia/[email protected]
159+
with:
160+
command: |
161+
make build ARCH=${{ matrix.arch }}
162+
163+
# ------------------------------------------------------------
164+
# Test
165+
# ------------------------------------------------------------
166+
- name: Test
167+
uses: cytopia/[email protected]
168+
with:
169+
command: |
170+
make test ARCH=${{ matrix.arch }}
171+
172+
# ------------------------------------------------------------
173+
# Deploy
174+
# ------------------------------------------------------------
175+
- name: Docker login
176+
uses: docker/login-action@v1
177+
with:
178+
username: ${{ secrets.dockerhub_username }}
179+
password: ${{ secrets.dockerhub_password }}
180+
if: needs.configure.outputs.can_login == 1 && inputs.can_deploy
181+
182+
- name: Docker push architecture image
183+
uses: cytopia/[email protected]
184+
with:
185+
command: |
186+
make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${{ matrix.arch }}
187+
if: needs.configure.outputs.can_login == 1 && inputs.can_deploy
188+
189+
# -----------------------------------------------------------------------------------------------
190+
# JOB (3/3): DEPLOY
191+
# -----------------------------------------------------------------------------------------------
192+
deploy:
193+
needs: [configure, build]
194+
name: Deploy ${{ inputs.name }}-${{ matrix.version }} ${{ matrix.refs }}
195+
runs-on: ubuntu-latest
196+
strategy:
197+
fail-fast: false
198+
matrix: ${{ fromJson(needs.configure.outputs.matrix_deploy) }}
199+
if: inputs.enabled && needs.configure.outputs.can_login == 1 && inputs.can_deploy
200+
steps:
201+
# ------------------------------------------------------------
202+
# Setup repository
203+
# ------------------------------------------------------------
204+
- name: "[SETUP] Checkout repository (current)"
205+
uses: actions/checkout@v2
206+
with:
207+
fetch-depth: 0
208+
if: needs.configure.outputs.has_refs == 0
209+
210+
- name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})"
211+
uses: actions/checkout@v2
212+
with:
213+
fetch-depth: 0
214+
ref: ${{ matrix.refs }}
215+
if: needs.configure.outputs.has_refs != 0
216+
217+
- name: "[SETUP] Determine Docker tag"
218+
id: tag
219+
uses: cytopia/[email protected]
220+
221+
# ------------------------------------------------------------
222+
# Deploy
223+
# ------------------------------------------------------------
224+
- name: "[DEPLOY] Login"
225+
uses: docker/login-action@v1
226+
with:
227+
username: ${{ secrets.DOCKERHUB_USERNAME }}
228+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
229+
230+
- name: "[DEPLOY] Create Docker manifest"
231+
uses: cytopia/[email protected]
232+
with:
233+
command: |
234+
make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="${{ needs.configure.outputs.manifest }}"
235+
236+
- name: "[DEPLOY] Publish Docker manifest: ${{ steps.tag.outputs.docker-tag }}"
237+
uses: cytopia/[email protected]
238+
with:
239+
command: |
240+
make manifest-push TAG=${{ steps.tag.outputs.docker-tag }}
File renamed without changes.

0 commit comments

Comments
 (0)