-
Notifications
You must be signed in to change notification settings - Fork 5
197 lines (165 loc) · 5.6 KB
/
release-docker.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
#####################################
## Reusable workflow tests ##
#####################################
name: Release Docker
on:
workflow_call:
inputs:
botName:
description: 'The github bot name'
type: string
required: true
registryUrl:
description: 'The npm token if needed'
type: string
required: false
default: 'https://registry.npmjs.org'
all:
description: 'Describe if we want to publish all the container or not'
type: boolean
required: false
default: false
tag:
description: 'Describe which tag you want to publish'
type: string
required: false
default: 'latest'
semver:
description: 'Describe you want to publish semver version'
type: boolean
required: false
default: true
secrets:
NPM_TOKEN:
description: 'The npm token if needed'
required: false
GH_TOKEN:
description: 'The github bot-token'
required: true
AWS_ACCESS_KEY_ID:
description: 'The aws access key id'
required: true
AWS_SECRET_ACCESS_KEY:
description: 'The aws secret access key'
required: true
AWS_REGION:
description: 'The aws region'
required: true
PROJECT_CODE:
description: 'The project code name'
required: true
jobs:
affected-apps:
runs-on: ubuntu-20.04
outputs:
apps: ${{ steps.apps.outputs.apps }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- name: Get the affected apps
id: apps
uses: tractr/traxion/.github/actions/affected-apps@main
with:
all: ${{ inputs.all }}
# Take all the packages and release them
docker-release:
name: Release docker containers
# If we got some change inside apps/** we execute this job
if: |
!contains(github.event.commits[0].message, 'chore(release):') &&
!failure() &&
!contains(needs.affected-apps.outputs.apps, '[]')
needs: [affected-apps]
strategy:
matrix:
app: ${{ fromJSON(needs.affected-apps.outputs.apps) }}
node: [16.x]
os: [ubuntu-20.04]
runs-on: ['${{ matrix.os }}']
steps:
# First we checkout the code
- uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
# Setup the node js env
- name: use node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: ${{ matrix.node }}
registry-url: ${{ inputs.registryUrl }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Get some cache to speed up docker build
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-dockerbuild-${{ matrix.app }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-dockerbuild-${{ matrix.app }}-
- name: Extract version
id: extract_version
uses: Saionaro/[email protected]
with:
path: ./apps/${{ matrix.app }}
# Register some meta data to build docker
- name: Docker meta - latest
id: docker_meta
uses: docker/metadata-action@v3
with:
images:
${{ steps.login-ecr.outputs.registry }}/${{ secrets.PROJECT_CODE
}}/${{ matrix.app }}
tags: |
raw,value=${{ inputs.tag }}
type=semver,pattern={{version}},value=v${{ steps.extract_version.outputs.version }},enable=${{ inputs.semver }}
type=semver,pattern={{major}}.{{minor}},value=v${{ steps.extract_version.outputs.version }},enable=${{ inputs.semver }}
type=semver,pattern={{major}},value=v${{ steps.extract_version.outputs.version }},enable=${{ inputs.semver }}
# Setup QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# Setup buildx
- uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true
# Loggin to our docker registry
- name: Login to Container Registry
uses: docker/login-action@v1
with:
registry: ${{ steps.login-ecr.outputs.registry }}
# Build and push our docker images to the registry
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
file: ./apps/${{ matrix.app }}/Dockerfile
secret-files: npmrc=${{ env.NPM_CONFIG_USERCONFIG }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
build-args: |
app=${{ matrix.app }}
NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }}
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# Change the cache for buildx
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache