-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (154 loc) · 5.61 KB
/
docker-build.yaml
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
name: Docker Build
on:
workflow_call:
inputs:
PROJECT:
type: string
required: true
FILE:
type: string
required: false
default: Dockerfile
TARGET:
type: string
required: false
default: null
BUILD_LATEST:
type: boolean
required: false
default: false
TAG_PREFIX:
type: string
required: false
default: null
TAG_SUFFIX:
type: string
required: false
default: null
GCP_PROJECT_ID:
type: string
required: true
GCP_REGISTRY:
type: string
required: false
default: "eu.gcr.io"
GAR_REGISTRY:
type: string
required: false
default: "europe-west3-docker.pkg.dev"
GAR_REPOSITORY:
type: string
required: false
default: "images"
CONTEXT:
type: string
default: .
BUILD_ARGS:
type: string
required: false
FULLNAME_OVERRIDE:
type: string
required: false
default: null
secrets:
SECRETS:
required: false
SSH_KEY:
required: false
BUILD_ARGS:
required: false
outputs:
DOCKER_METADATA_OUTPUT_VERSION:
value: ${{ jobs.docker-build.outputs.DOCKER_METADATA_OUTPUT_VERSION }}
DOCKER_METADATA_OUTPUT_TAGS:
value: ${{ jobs.docker-build.outputs.DOCKER_METADATA_OUTPUT_TAGS }}
DOCKER_METADATA_OUTPUT_LABELS:
value: ${{ jobs.docker-build.outputs.DOCKER_METADATA_OUTPUT_LABELS }}
DOCKER_METADATA_OUTPUT_ANNOTATIONS:
value: ${{ jobs.docker-build.outputs.DOCKER_METADATA_OUTPUT_ANNOTATIONS }}
DOCKER_METADATA_OUTPUT_JSON:
value: ${{ jobs.docker-build.outputs.DOCKER_METADATA_OUTPUT_JSON }}
jobs:
docker-build:
runs-on: ubuntu-22.04
outputs:
DOCKER_METADATA_OUTPUT_VERSION: ${{ steps.meta.outputs.version }}
DOCKER_METADATA_OUTPUT_TAGS: ${{ steps.meta.outputs.tags }}
DOCKER_METADATA_OUTPUT_LABELS: ${{ steps.meta.outputs.labels}}
DOCKER_METADATA_OUTPUT_ANNOTATIONS: ${{ steps.meta.outputs.annotations}}
DOCKER_METADATA_OUTPUT_JSON: ${{ steps.meta.outputs.json}}
steps:
- name: checkout
uses: actions/[email protected]
- name: set up qemu
uses: docker/[email protected]
- name: set up docker buildx
uses: docker/[email protected]
- name: add key to ssh-agent
uses: webfactory/[email protected]
if: "${{ env.SSH_KEY != ''}}"
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: lowercase things
id: lowercase
env:
project: ${{inputs.PROJECT}}
run: |
echo "project=${project,,}" >> "$GITHUB_OUTPUT"
- name: calculate tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: main,stage
create_annotated_tag: true
tag_prefix: ""
dry_run: true
- name: Docker Metadata action
uses: docker/[email protected]
id: meta
with:
flavor: |
latest=${{inputs.BUILD_LATEST}}
prefix=${{inputs.TAG_PREFIX}}
suffix=${{inputs.TAG_SUFFIX}}
images: |
name=${{ inputs.GCP_REGISTRY }}/${{ inputs.GCP_PROJECT_ID }}/${{ inputs.FULLNAME_OVERRIDE && inputs.FULLNAME_OVERRIDE || steps.lowercase.outputs.project }}
name=${{ inputs.GAR_REGISTRY }}/${{ inputs.GCP_PROJECT_ID }}/${{inputs.GAR_REPOSITORY}}/${{ inputs.FULLNAME_OVERRIDE && inputs.FULLNAME_OVERRIDE || steps.lowercase.outputs.project }}
tags: |
type=raw,value=${{ github.run_attempt == 1 && steps.tag_version.outputs.new_tag || steps.tag_version.outputs.previous_tag }},enable=${{ github.event_name != 'schedule' && github.ref_name == 'main'}}
type=schedule,pattern=nightly
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=pr
labels: |
org.opencontainers.image.ref.name=${{ github.ref }}
org.opencontainers.image.revision=https://github.com/${{ github.repository }}/commit/${{ github.sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.version=${{ (github.run_attempt == 1 && github.event_name != 'schedule') && steps.tag_version.outputs.new_tag || steps.tag_version.outputs.previous_tag }}
- name: build
uses: docker/[email protected]
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
with:
build-args: ${{inputs.BUILD_ARGS}}
cache-from: type=gha,scope=${{ inputs.PROJECT }}
cache-to: type=gha,mode=max,scope=${{ inputs.PROJECT }}
context: ${{inputs.CONTEXT}}
file: ${{inputs.FILE}}
labels: ${{ steps.meta.outputs.labels }}
load: false
outputs: type=docker,dest=./image_${{steps.lowercase.outputs.project}}.tar
push: false
secrets: ${{secrets.SECRETS}}
ssh: ${{ env.SSH_KEY != '' && 'default' || null }}
tags: ${{ steps.meta.outputs.tags }}
target: ${{inputs.TARGET}}
- name: upload
uses: actions/[email protected]
with:
name: artifacts_image_${{steps.lowercase.outputs.project}}
path: ./image_${{steps.lowercase.outputs.project}}.tar
retention-days: 1