-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
215 lines (203 loc) · 8.21 KB
/
action.yml
File metadata and controls
215 lines (203 loc) · 8.21 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
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
212
213
214
215
name: 'Docker and GitOps Commit'
description: 'Build and push the Docker image and commits the new version to your GitOps repo.'
author: 'Staffbase SE'
inputs:
docker-registry:
description: 'Docker Registry'
required: true
default: 'registry.staffbase.com'
docker-registry-api:
description: 'Docker Registry API'
required: false
default: 'https://registry.staffbase.com/v2/'
docker-image:
description: 'Docker Image'
required: true
docker-custom-tag:
description: 'Docker Custom Tag'
required: false
docker-username:
description: 'Username for the Docker Registry'
required: false
docker-password:
description: 'Password for the Docker Registry'
required: false
docker-file:
description: 'Path of the Dockerfile. Should be relative to input.working-directory'
required: true
default: './Dockerfile'
docker-build-args:
description: "List of build-time variables"
required: false
docker-build-secrets:
description: "List of secrets to expose to the build (e.g., key=string, GIT_AUTH_TOKEN=mytoken)"
required: false
docker-build-secret-files:
description: "List of secret files to expose to the build (e.g., key=filename, MY_SECRET=./secret.txt)"
required: false
docker-build-target:
description: "Sets the target stage to build"
required: false
docker-build-platforms:
description: "Sets the target platforms for build"
required: false
default: 'linux/amd64'
docker-build-provenance:
description: "Generate provenance attestation for the build"
required: false
default: 'false'
docker-build-outputs:
description: "Custom output destinations (e.g., type=registry,push=true,compression=zstd,force-compression=true). When set, this replaces the default push behavior - include push=true if pushing is desired."
required: false
docker-disable-retagging:
description: 'Disable retagging of existing images'
required: false
default: 'false'
gitops-organization:
description: 'GitHub Organization for GitOps'
required: true
default: 'Staffbase'
gitops-repository:
description: 'GitHub Repository for GitOps'
required: true
default: 'mops'
gitops-user:
description: 'GitHub User for GitOps'
required: true
default: 'Staffbot'
gitops-email:
description: 'GitHub User for GitOps'
required: true
default: 'staffbot@staffbase.com'
gitops-token:
description: 'GitHub Token for GitOps'
required: false
gitops-dev:
description: 'Files which should be updated by the GitHub Action for DEV'
required: false
gitops-stage:
description: 'Files which should be updated by the GitHub Action for STAGE'
required: false
gitops-prod:
description: 'Files which should be updated by the GitHub Action for PROD'
required: false
upwind-client-id:
description: 'Upwind Client ID'
required: false
upwind-organization-id:
description: 'Upwind Organization ID'
required: false
upwind-client-secret:
description: 'Upwind Client Secret'
required: false
working-directory:
description: 'The path relative to the repo root dir in which the GitOps action should be executed.'
required: false
default: '.'
outputs:
docker-tag:
description: 'Docker tag'
value: ${{ steps.preparation.outputs.tag }}
docker-digest:
description: 'Docker digest'
value: ${{ steps.docker_build.outputs.digest || steps.docker_retag.outputs.digest }}
runs:
using: "composite"
steps:
- name: Generate Tags
id: preparation
shell: bash
env:
INPUT_DOCKER_CUSTOM_TAG: ${{ inputs.docker-custom-tag }}
INPUT_DOCKER_DISABLE_RETAGGING: ${{ inputs.docker-disable-retagging }}
INPUT_DOCKER_REGISTRY: ${{ inputs.docker-registry }}
INPUT_DOCKER_IMAGE: ${{ inputs.docker-image }}
run: ${{ github.action_path }}/scripts/generate-tags.sh
- name: Verify Architecture Match
shell: bash
if: steps.preparation.outputs.build == 'true'
env:
RUNNER_ARCH: ${{ runner.arch }}
INPUT_DOCKER_BUILD_PLATFORMS: ${{ inputs.docker-build-platforms }}
run: ${{ github.action_path }}/scripts/verify-architecture.sh
- name: Set up Docker Buildx
if: inputs.docker-username != '' && inputs.docker-password != ''
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Login to Registry
if: inputs.docker-username != '' && inputs.docker-password != ''
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ${{ inputs.docker-registry }}
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}
- name: Build
id: docker_build
if: steps.preparation.outputs.build == 'true' && inputs.docker-username != '' && inputs.docker-password != ''
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: ${{ inputs.working-directory }}
push: ${{ inputs.docker-build-outputs == '' && steps.preparation.outputs.push || 'false' }}
file: ${{ inputs.working-directory }}/${{ inputs.docker-file }}
target: ${{ inputs.docker-build-target }}
build-args: ${{ inputs.docker-build-args }}
tags: ${{ steps.preparation.outputs.tag_list }}
secrets: ${{ inputs.docker-build-secrets }}
secret-files: ${{ inputs.docker-build-secret-files }}
platforms: ${{ inputs.docker-build-platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: ${{ inputs.docker-build-provenance }}
outputs: ${{ inputs.docker-build-outputs }}
- name: Retag Existing Image
id: docker_retag
if: steps.preparation.outputs.build == 'false'
shell: bash
env:
INPUT_DOCKER_USERNAME: ${{ inputs.docker-username }}
INPUT_DOCKER_PASSWORD: ${{ inputs.docker-password }}
INPUT_DOCKER_REGISTRY_API: ${{ inputs.docker-registry-api }}
INPUT_DOCKER_IMAGE: ${{ inputs.docker-image }}
INPUT_TAG: ${{ steps.preparation.outputs.tag }}
INPUT_LATEST: ${{ steps.preparation.outputs.latest }}
run: ${{ github.action_path }}/scripts/retag-image.sh
- name: Checkout GitOps Repository
if: inputs.gitops-token != ''
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ inputs.gitops-organization }}/${{ inputs.gitops-repository }}
token: ${{ inputs.gitops-token }}
path: .github/${{ inputs.gitops-repository }}
- name: Update Docker Image in Repository
id: update_image
if: inputs.gitops-token != ''
working-directory: .github/${{ inputs.gitops-repository }}
shell: bash
env:
INPUT_DOCKER_REGISTRY: ${{ inputs.docker-registry }}
INPUT_DOCKER_IMAGE: ${{ inputs.docker-image }}
INPUT_TAG: ${{ steps.preparation.outputs.tag }}
INPUT_PUSH: ${{ steps.preparation.outputs.push }}
INPUT_GITOPS_USER: ${{ inputs.gitops-user }}
INPUT_GITOPS_EMAIL: ${{ inputs.gitops-email }}
INPUT_GITOPS_TOKEN: ${{ inputs.gitops-token }}
INPUT_GITOPS_ORGANIZATION: ${{ inputs.gitops-organization }}
INPUT_GITOPS_REPOSITORY: ${{ inputs.gitops-repository }}
INPUT_GITOPS_DEV: ${{ inputs.gitops-dev }}
INPUT_GITOPS_STAGE: ${{ inputs.gitops-stage }}
INPUT_GITOPS_PROD: ${{ inputs.gitops-prod }}
run: ${{ github.action_path }}/scripts/update-gitops.sh
- name: Emit Image Build Event to Upwind.io
env:
UPWIND_CLIENT_SECRET: ${{ inputs.upwind-client-secret }}
if: "${{ inputs.upwind-client-id != '' && env.UPWIND_CLIENT_SECRET != '' && inputs.upwind-organization-id != '' }}"
uses: upwindsecurity/create-image-build-event-action@3099fc1e1e002c6c2d7b7c635699944a708d260d # v3
continue-on-error: true
with:
image: ${{ inputs.docker-image }}
image_sha: ${{ steps.docker_build.outputs.digest || steps.docker_retag.outputs.digest }}
upwind_client_id: ${{ inputs.upwind-client-id }}
upwind_client_secret: ${{ env.UPWIND_CLIENT_SECRET }}
upwind_organization_id: ${{ inputs.upwind-organization-id }}
branding:
icon: 'git-merge'
color: 'blue'