-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (191 loc) · 7.83 KB
/
job-95-container-push.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
---
name: job-95-container-push
# Consuming Projects Must Implement:
# - ./.github/scripts/step-setup-environment.sh
on:
workflow_call:
inputs:
BUILD_ARGS:
default: ""
description: "Optional, allows you define build arguments for the container build."
required: false
type: string
CONTEXT:
default: "."
description: "Optional, allows you define where the build context is located."
required: false
type: string
DOCKERFILE:
default: "./Dockerfile"
description: "Optional, allows you define where the Dockerfile is located with respect to the context."
required: false
type: string
IMAGE_NAME:
default: ""
description: "Optional, allows you to specify the image name, otherwise the configured script will generate one."
required: false
type: string
IMAGE_LATEST:
default: false
description: "Optional, allows you to designate this as the 'latest' image when pushed."
required: false
type: boolean
IMAGE_TAG:
default: ""
description: "Optional, allows you specify the image tag, otherwise the pushed branch or tag will be used."
required: false
type: string
PLATFORM:
default: ""
description: "Optional, allows you to specify the target platform of the container."
required: false
type: string
POST_BUILD_COMMAND:
default: ""
description: "Optional, a command to run after the build executes."
required: false
type: string
PRE_BUILD_COMMAND:
default: ""
description: "Optional, a command to run before build executes."
required: false
type: string
REGISTRY:
default: "ghcr.io"
description: "Optional, allows you to specify a Docker registry to use."
required: false
type: string
REMOTE_SCRIPT_DEFAULT_SETTER:
default: "ci/github/scripts/step-set-value-with-default.sh"
description: "Optional, allows you to specify different default value creation script."
required: false
type: string
REMOTE_SCRIPT_SET_VALUE:
default: "ci/github/scripts/step-set-value.sh"
description: "Optional, allows you to specify a workflow set value script."
required: false
type: string
REQUIRES_QEMU:
default: false
description: "Optional, allows you to use docker support for QEMU as part of your build."
required: false
type: boolean
TESTING_MODE:
default: false
description: "Optional, allows you to test a workflow failure."
required: false
type: boolean
VERBOSE_NOTIFICATIONS:
default: false
description: "Optional, allows you to adjust the notification verbosity."
required: false
type: boolean
WORKFLOW_NAME:
default: ""
description: "Identifies this workflow in notifications."
required: false
type: string
secrets:
REGISTRY_USERNAME:
description: "Optional, sets the username that will be used to login to the registry. Default: github.actor"
required: false
REGISTRY_PASSWORD:
description: "Optional, sets the password that will be used to login to the registry. Default: secrets.GITHUB_TOKEN"
required: false
SLACK_WEBHOOK:
description: "Optional, enables Slack notifications."
required: false
jobs:
run_docker_push:
runs-on: ubuntu-latest
steps:
- name: Push Container -- Checkout Repository
uses: actions/checkout@v4
- name: Push Container -- Setup Environment
env:
WORKFLOW_NAME: ${{ inputs.WORKFLOW_NAME }}
run: |
bash "./.github/scripts/step-setup-environment.sh"
shell: bash
- name: Push Container -- Install Toolbox
uses: ./.github/actions/action-00-toolbox
- name: Push Container -- Configure Registry
id: registry
run: |
bash "./.cicd-tools/boxes/active/${{ inputs.REMOTE_SCRIPT_DEFAULT_SETTER }}" \
-o "IMAGE_NAME" \
-d "${PROJECT_OWNER}/${PROJECT_NAME}" \
-s "${{ inputs.IMAGE_NAME }}"
bash "./.cicd-tools/boxes/active/${{ inputs.REMOTE_SCRIPT_DEFAULT_SETTER }}" \
-o "IMAGE_TAG" \
-d "${{ env.BRANCH_OR_TAG }}" \
-s "${{ inputs.IMAGE_TAG }}"
bash "./.cicd-tools/boxes/active/${{ inputs.REMOTE_SCRIPT_DEFAULT_SETTER }}" \
-o "REGISTRY_USERNAME" \
-d "${{ github.actor }}" \
-s "${{ secrets.REGISTRY_USERNAME }}"
bash "./.cicd-tools/boxes/active/${{ inputs.REMOTE_SCRIPT_DEFAULT_SETTER }}" \
-o "REGISTRY_PASSWORD" \
-d "${{ secrets.GITHUB_TOKEN }}" \
-s "${{ secrets.REGISTRY_PASSWORD }}"
shell: bash
- name: Push Container -- Set up QEMU
if: inputs.REQUIRES_QEMU == true
uses: docker/setup-qemu-action@v3
- name: Push Container -- Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Push Container -- Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.REGISTRY }}
username: ${{ steps.registry.outputs.REGISTRY_USERNAME }}
password: ${{ steps.registry.outputs.REGISTRY_PASSWORD }}
- name: Push Container -- Append Latest Tag
id: latest
run: |
LATEST=""
[[ "${{ inputs.IMAGE_LATEST }}" == "true" ]] && LATEST="${{ inputs.REGISTRY }}/${{ steps.registry.outputs.IMAGE_NAME }}:latest"
bash "./.cicd-tools/boxes/active/${{ inputs.REMOTE_SCRIPT_SET_VALUE }}" \
echo "${LATEST}"
- name: Push Container -- Pre Build Command
if: inputs.PRE_BUILD_COMMAND != ''
run: |
${{ inputs.PRE_BUILD_COMMAND }}
shell: bash
- name: Push Container -- Build and Push (with latest tag)
uses: docker/build-push-action@v5
with:
platforms: ${{ inputs.PLATFORM }}
build-args: |
${{ inputs.BUILD_ARGS }}
cache-from: type=gha,scope=${{ inputs.REGISTRY }}/${{ steps.registry.outputs.IMAGE_NAME }}:${{ steps.registry.outputs.IMAGE_TAG }}
cache-to: type=gha,scope=${{ inputs.REGISTRY }}/${{ steps.registry.outputs.IMAGE_NAME }}:${{ steps.registry.outputs.IMAGE_TAG }}
no-cache: true
context: ${{ inputs.CONTEXT }}
file: ${{ inputs.CONTEXT }}/${{ inputs.DOCKERFILE }}
push: true
pull: true
tags: |
${{ inputs.REGISTRY }}/${{ steps.registry.outputs.IMAGE_NAME }}:${{ steps.registry.outputs.IMAGE_TAG }}
${{ steps.latest.outputs.VALUE }}
- name: Push Container -- Post Build Command
if: inputs.POST_BUILD_COMMAND != ''
run: |
${{ inputs.POST_BUILD_COMMAND }}
shell: bash
- name: Push Container -- Report Job Status on Success
if: inputs.VERBOSE_NOTIFICATIONS == true
uses: ./.cicd-tools/boxes/active/ci/github/actions/action-00-generic-notification
with:
NOTIFICATION_MESSAGE: |
Docker Container has been built and pushed!
Pushed Image: ${{ inputs.REGISTRY }}/${{ steps.registry.outputs.IMAGE_NAME }}:${{ steps.registry.outputs.IMAGE_TAG }}
NOTIFICATION_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Push Container -- Report Job Status on Failure
if: failure() || inputs.TESTING_MODE == true
uses: ./.cicd-tools/boxes/active/ci/github/actions/action-00-generic-notification
with:
NOTIFICATION_EMOJI: ":x:"
NOTIFICATION_MESSAGE: "Docker Container Build/Push has failed!"
NOTIFICATION_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
TESTING_MODE: ${{ inputs.TESTING_MODE }}