-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
206 lines (193 loc) · 7 KB
/
action.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
name: "Publish to Lunni"
description: TODO
author: "[email protected]"
branding:
icon: "upload-cloud"
color: "orange"
inputs:
context:
description: "Build's context is the set of files located in the specified PATH or URL"
required: false
default: "./"
file:
description: "Path to the Dockerfile"
required: false
default: "Dockerfile"
image_name:
description: "Image name (excluding registry). Defaults to {{ github.repository }}."
required: false
default: ""
registry:
description: "Docker registry. Defaults to ghcr.io."
required: true
default: "ghcr.io"
username:
description: "Docker username. Defaults to {{ github.actor }}."
required: false
default: "${{ github.actor }}"
password:
description: "Docker password. Set this to {{ secrets.GITHUB_TOKEN }} if publishing to GHCR."
required: false
default: ""
lunni-webhook-url:
description: "Lunni service webhook"
required: false
default: ""
# https://github.com/docker/build-push-action/blob/master/action.yml -> inputs
build-args:
description: "List of build-time variables"
required: false
cache-from:
description: "List of external cache sources for buildx (e.g., user/app:cache, type=local,src=path/to/dir)"
required: false
default: type=gha
cache-to:
description: "List of cache export destinations for buildx (e.g., user/app:cache, type=local,dest=path/to/dir)"
required: false
default: type=gha,mode=max
platforms:
description: "List of target platforms for build (e.g. linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,etc)"
required: false
default: "linux/amd64"
provenance:
description: "Generate provenance attestation for the build"
required: false
ssh:
description: "List of SSH agent socket or keys to expose to the build"
required: false
tags:
description: "List of tags: https://github.com/docker/metadata-action#tags-input"
required: false
flavor:
description: "Defines a global behavior for tags: https://github.com/docker/metadata-action#flavor-input"
required: false
target:
description: "Sets the target stage to build"
required: false
default: ""
secrets:
description: "List of secrets to expose to the build (e.g., key=string, GIT_AUTH_TOKEN=mytoken)"
required: false
secret-files:
description: "List of secret files to expose to the build (e.g., key=filename, MY_SECRET=./secret.txt)"
required: false
docker-metadata-pr-head-sha:
description: "Set to `true` to tag images with the PR HEAD SHA instead of the merge commit SHA within pull requests."
required: false
default: "false"
outputs:
image:
description: "Docker image name"
value: ${{ inputs.registry }}/${{ steps.image_name.outputs.image_name }}
tag:
description: "Docker image tag"
value: ${{ steps.tag.outputs.output }}
metadata:
description: "Docker image metadata"
value: ${{ steps.get-metadata.outputs.metadata }}
runs:
using: "composite"
steps:
- name: Set image name
id: image_name
shell: bash
run: |
if [ "${{ inputs.image_name }}" = "" ]; then
echo 'image_name=${{ github.repository }}' >> "$GITHUB_OUTPUT"
else
echo 'image_name=${{inputs.image_name}}' >> "$GITHUB_OUTPUT"
fi
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
env:
# Annoyingly, docker computes the SHA tags independently of any checkout
# action. This option tells this action to use the PR HEAD SHA during a
# pull request. It will then use `github.event.pull_request.head.sha`
# instead of the merge commit (`github.sha`). This is useful for folks
# who want to avoid merge commits in their PRs (for hotfix workflows,
# tag predictability, builds on merge-conflicts, etc).
DOCKER_METADATA_PR_HEAD_SHA: ${{ inputs.docker-metadata-pr-head-sha }}
with:
# list of Docker images to use as base name for tags
images: |
${{ inputs.registry }}/${{ steps.image_name.outputs.image_name }}
# generate Docker tags based on the following events/attributes
tags: |
type=sha
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=long
${{ inputs.tags }}
flavor: ${{ inputs.flavor }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
- name: 'Install jq 1.6'
uses: dcarbone/[email protected]
with:
version: 1.6
force: 'true'
- uses: edwardgeorge/jq-action@main
id: tag
with:
compact: true
raw-output: true
input: ${{ steps.meta.outputs.json }}
script: '.tags | map(select(test("sha-\\w{8,}"))) | first | match("sha-\\w{8,}") | .string'
# docker context must be created prior to setting up Docker Buildx
# https://github.com/actions-runner-controller/actions-runner-controller/issues/893
- name: Set up Docker Context for Buildx
shell: bash
id: buildx-context
run: |
docker context create buildx-context || true
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
endpoint: buildx-context
- name: Login
uses: docker/login-action@v2
if: ${{ contains(inputs.registry, '.amazonaws.com') || ( inputs.username != '' && inputs.password != '' ) }}
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Build and push Docker images
uses: docker/build-push-action@v4
id: docker-build-push-action
with:
context: ${{ inputs.context }}
file: ${{ inputs.context }}/${{ inputs.file }}
pull: true
push: true
ssh: ${{ inputs.ssh }}
build-args: ${{ inputs.build-args }}
cache-from: ${{ inputs.cache-from }}
cache-to: ${{ inputs.cache-to }}
tags: ${{ steps.meta.outputs.tags }}
target: ${{ inputs.target }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
provenance: ${{ inputs.provenance }}
secrets: ${{ inputs.secrets }}
secret-files: ${{ inputs.secret-files }}
- name: Update service on Lunni
id: update-service
if: ${{ ( inputs.lunni-webhook-url != '' ) }}
shell: bash
run: |
curl --fail-with-body -X POST '${{ inputs.lunni-webhook-url }}'
- name: Get Metadata
id: get-metadata
shell: bash
run: |
metadata=$(echo '${{ steps.docker-build-push-action.outputs.metadata }}' | jq -c)
echo "metadata=$metadata" >> $GITHUB_OUTPUT
echo "Docker image metadata: $metadata"