-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (186 loc) · 6.46 KB
/
docker-build-mysql-80.yaml
File metadata and controls
196 lines (186 loc) · 6.46 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
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
DOCKER_LOGIN:
type: boolean
required: false
default: false
secrets:
SECRETS:
required: false
SSH_KEY:
required: false
BUILD_ARGS:
required: false
GAR_HELM_REGISTRY_ACCOUNT:
required: false
GCR_JSON_KEY:
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}}
services:
mysql:
image: mysql:8.0
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: testdb
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
steps:
- name: checkout
uses: actions/checkout@v5.0.0
- name: set up qemu
uses: docker/setup-qemu-action@v3.6.0
- name: set up docker buildx
uses: docker/setup-buildx-action@v3.10.0
- name: login to gcr
if: "${{ inputs.DOCKER_LOGIN}}"
uses: docker/login-action@v3.5.0
with:
registry: ${{ inputs.GCP_REGISTRY }}
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- name: login to gar
if: "${{ inputs.DOCKER_LOGIN}}"
uses: docker/login-action@v3.5.0
with:
registry: ${{ inputs.GAR_REGISTRY}}
username: _json_key
password: ${{ secrets.GAR_HELM_REGISTRY_ACCOUNT }}
- name: add key to ssh-agent
uses: webfactory/ssh-agent@v0.9.1
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/github-tag-action@v6.2
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/metadata-action@v5.8.0
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=${{ steps.tag_version.outputs.new_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/build-push-action@v6.18.0
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/upload-artifact@v5.0.0
with:
name: artifacts_image_${{steps.lowercase.outputs.project}}
path: ./image_${{steps.lowercase.outputs.project}}.tar
retention-days: 1