-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdocker-multistage-push-image.yml
More file actions
142 lines (123 loc) · 4.69 KB
/
docker-multistage-push-image.yml
File metadata and controls
142 lines (123 loc) · 4.69 KB
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
---
name: "Push multistage docker images (multi -flavours, -versions, -architectures)"
on:
workflow_call:
###
### Variables
###
inputs:
matrix:
description: 'The build matrix'
required: true
type: string
stage:
description: 'The stage to build (Examples: base, mods, prod or work).'
required: true
type: string
artifact_prefix:
description: 'Unique artifact name prefix (to avoid overriding existing artifcats during parallel runs).'
required: true
type: string
can_deploy:
description: 'Determines whether this workflow will also deploy (login and push).'
required: true
type: boolean
has_refs:
description: 'The ref build matrix as JSON string (list of git refs to build/deploy).'
required: true
type: boolean
###
### Secrets
###
secrets:
dockerhub_username:
description: 'The username for Dockerhub.'
required: true
dockerhub_password:
description: 'The password for Dockerhub.'
required: true
jobs:
# -----------------------------------------------------------------------------------------------
# JOB: DEPLOY
# -----------------------------------------------------------------------------------------------
deploy:
name: ${{ matrix.NAME }}-${{ matrix.VERSION }}-${{ inputs.stage }} (${{ matrix.ARCH }}) ${{ matrix.REFS }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(inputs.matrix) }}
steps:
# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: "[SETUP] Checkout repository (current)"
uses: actions/checkout@v6
with:
fetch-depth: 0
if: ${{ !inputs.has_refs }}
- name: "[SETUP] Checkout repository (ref: ${{ matrix.REFS }})"
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ matrix.REFS }}
if: ${{ inputs.has_refs }}
- name: "[SETUP] Setup QEMU environment"
uses: docker/setup-qemu-action@v4
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: "[SETUP] Determine Docker tag"
id: tag
uses: cytopia/docker-tag-action@v0.4.26
- name: "[SETUP] Set artifact names"
id: set-artifact-name
run: |
VERSION="${{ matrix.VERSION }}"
ARCH="$( echo "${{ matrix.ARCH }}" | sed 's|/|-|g' )"
NAME_CURR="${{ inputs.artifact_prefix }}-${VERSION}-${ARCH}-${{ inputs.stage }}"
echo "curr=${NAME_CURR}" >> $GITHUB_OUTPUT
# ------------------------------------------------------------
# Artifact Import
# ------------------------------------------------------------
###
### Download and import previously built image
###
- name: "[Artifact Load] Download previously built image"
uses: cytopia/download-artifact-retry-action@v0.1.10
with:
name: ${{ steps.set-artifact-name.outputs.curr }}
- name: "[Artifact Load] Import previously built image"
uses: cytopia/shell-command-retry-action@v0.1.9
with:
command: |
make load INFILE=${{ steps.set-artifact-name.outputs.curr }}
# ------------------------------------------------------------
# Re-tag images
# ------------------------------------------------------------
- name: "[Docker Tag] Retag"
uses: cytopia/shell-command-retry-action@v0.1.9
with:
command: |
make tag VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} TAG=${{ steps.tag.outputs.docker-tag }}
- name: "[Docker Tag] Show images"
run: |
docker images
# ------------------------------------------------------------
# Login
# ------------------------------------------------------------
- name: Login
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
if: ${{ inputs.can_deploy }}
# ------------------------------------------------------------
# Push images
# ------------------------------------------------------------
- name: Push Image
uses: cytopia/shell-command-retry-action@v0.1.9
with:
command: |
make push VERSION=${{ matrix.VERSION }} STAGE=${{ inputs.stage }} FLAVOUR=${{ matrix.FLAVOUR }} ARCH=${{ matrix.ARCH }} TAG=${{ steps.tag.outputs.docker-tag }}
if: ${{ inputs.can_deploy }}