-
Notifications
You must be signed in to change notification settings - Fork 7
212 lines (185 loc) · 7.64 KB
/
continuous-delivery.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
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
# This workflow performs continuous delivery (CD).
# This workflow will build a container image and publish it to container registries.
name: Continuous Delivery (CD)
# When it's time to do a release,
# do a full cross-platform build for all supported architectures and
# push all of them to Docker Hub and GitHub Container Registry (GHCR).
on:
# "Build and publish" on merged
# Actually, there's no "merged" event.
# A "push" event is occurred after the pull request "close" event with "merged" true condition.
# The "push" event could replace "merged" event.
push:
branches:
- main
tags:
# Only trigger on semver shaped tags.
- "v*.*.*"
paths-ignore:
- ".github/**"
- "docs/**"
- "**.md"
- ".gitignore"
- "LICENSE"
- "CODEOWNERS"
env:
DOCKER_REGISTRY_NAME: cloudbaristaorg
GHCR_REGISTRY_NAME: ${{ github.repository_owner }}
IMAGE_NAME: ${{ github.event.repository.name }}
jobs:
publish-api-container-image:
name: Publish a container image
if: github.repository_owner == 'm-cmp'
# This job runs on Ubuntu-latest (Ubuntu 22.04 LTS checked on 2023-12-13)
# See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
# About billing for GitHub Packages
# https://docs.github.com/en/billing/managing-billing-for-github-packages/about-billing-for-github-packages
- name: Extract metadata from Git reference and GitHub events
id: meta
uses: docker/metadata-action@v5
with:
images: |
# image name for Docker Hub
${{env.DOCKER_REGISTRY_NAME}}/${{env.IMAGE_NAME}}-api
# image name for GitHub Container Registry (GHCR)
ghcr.io/${{env.GHCR_REGISTRY_NAME}}/${{env.IMAGE_NAME}}-api
tags: |
# See `tags` input: https://github.com/docker/metadata-action?tab=readme-ov-file#tags-input
## Tags for a push tag event
# minimal (e.g., 1.2.3)
type=semver,enable=true,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
## Tags for a push branch event
# Tags to reflect the last commit of the active branch
type=edge,enable=true
## Other types (currently the followings may be out of scope in this project)
## Tags for a push branch event
# minimal (short sha)
# type=sha,enable=true,format=short
## Tags for a push or pull_request event
# type=ref,event=branch
# type=ref,event=tag
# type=ref,event=pr
## Tags for a schedule event - handlebars with timezone (e.g. 20200110-093000)
# type=schedule,enable=true,pattern={{date 'YYYYMMDD-hhmmss' tz='Asia/Tokyo'}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-api-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-api-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and publish
id: docker_build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./api/Dockerfile.mcwebconsoleapi
target: deploy
platforms: linux/amd64 # linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
publish-front-container-image:
name: Publish a container image
if: github.repository_owner == 'm-cmp'
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Extract metadata from Git reference and GitHub events
id: meta
uses: docker/metadata-action@v5
with:
images: |
# image name for Docker Hub
${{env.DOCKER_REGISTRY_NAME}}/${{env.IMAGE_NAME}}-front
# image name for GitHub Container Registry (GHCR)
ghcr.io/${{env.GHCR_REGISTRY_NAME}}/${{env.IMAGE_NAME}}-front
tags: |
# See `tags` input: https://github.com/docker/metadata-action?tab=readme-ov-file#tags-input
## Tags for a push tag event
# minimal (e.g., 1.2.3)
type=semver,enable=true,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
## Tags for a push branch event
# Tags to reflect the last commit of the active branch
type=edge,enable=true
## Other types (currently the followings may be out of scope in this project)
## Tags for a push branch event
# minimal (short sha)
# type=sha,enable=true,format=short
## Tags for a push or pull_request event
# type=ref,event=branch
# type=ref,event=tag
# type=ref,event=pr
## Tags for a schedule event - handlebars with timezone (e.g. 20200110-093000)
# type=schedule,enable=true,pattern={{date 'YYYYMMDD-hhmmss' tz='Asia/Tokyo'}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-front-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-front-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and publish
id: docker_build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./front/Dockerfile.mcwebconsolefront
target: deploy
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}