-
Notifications
You must be signed in to change notification settings - Fork 3
182 lines (161 loc) · 6.07 KB
/
docker-build-release.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
name: build-release
on:
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- main
- master
push:
branches:
- main
- master
tags:
- 'v*'
env:
APP_NAME: nubeio-rubix-app-bbb-rest-py
GHCR_IMAGE: ghcr.io/nubeio/nubeio-rubix-app-bbb-rest-py
PLATFORMS: linux/amd64,linux/arm/v7
jobs:
context:
runs-on: ubuntu-latest
outputs:
shouldBuild: ${{ steps.context.outputs.decision_build }}
shouldPublish: ${{ steps.context.outputs.decision_publish }}
isRelease: ${{ steps.context.outputs.isTag }}
afterRelease: ${{ steps.context.outputs.isAfterMergedReleasePR }}
sha: ${{ steps.context.outputs.commitId }}
version: ${{ steps.context.outputs.version }}
fqn: ${{ env.APP_NAME }}-${{ steps.context.outputs.version }}-${{ steps.context.outputs.shortCommitId }}
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.NUBEIO_CI_GITHUBPROJECT_TOKEN }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v3
with:
git-user-signingkey: true
git-commit-gpgsign: true
git-tag-gpgsign: true
git-push-gpgsign: false
gpg-private-key: ${{ secrets.NUBEIO_CI_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.NUBEIO_CI_GPG_PASSPHARSE }}
- name: Project context
id: context
uses: zero88/gh-project-context@v1
with:
dry: false
mustSign: true
defaultBranch: master
build:
runs-on: ubuntu-latest
needs: context
if: needs.context.outputs.shouldBuild == 'true'
services:
registry:
image: zero88/gh-registry:latest
ports:
- 5000:5000
options: >-
-v /home/runner:/var/lib/registry
--name registry
steps:
- uses: actions/checkout@v2
- name: Fallback version to deal with GitHub Cache
run: sed -i "0,/${{ needs.context.outputs.version }}/s//0.0.0/" pyproject.toml
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /home/runner/docker
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-
- name: Validate cache
run: |
docker buildx imagetools inspect localhost:5000/${{ env.APP_NAME }}:buildcache || echo "Not Found"
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.GHCR_IMAGE }}
tag-latest: true
tag-sha: true
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Build artifact by docker
uses: docker/build-push-action@v2
if: ${{ needs.context.outputs.isRelease == 'true' }}
with:
context: .
file: docker/Dockerfile
platforms: ${{ env.PLATFORMS }}
build-args: |
BASE_IMAGE_VERSION=3.9
APP_VERSION=${{ needs.context.outputs.version }}
COMMIT_SHA=${{ needs.context.outputs.sha }}
cache-from: type=registry,ref=localhost:5000/${{ env.APP_NAME }}:buildcache
cache-to: type=registry,ref=localhost:5000/${{ env.APP_NAME }}:buildcache,mode=max
tags: localhost:5000/${{ env.APP_NAME }}:${{ needs.context.outputs.sha }}
pull: true
push: true
- name: Zip artifacts
if: ${{ needs.context.outputs.isRelease == 'true' }}
run: |
image=localhost:5000/${{ env.APP_NAME }}:${{ needs.context.outputs.sha }}
output=/usr/src/app/
mkdir -p /tmp/zip /tmp/images
IFS=',' read -ra ARR <<< "${{ env.PLATFORMS }}"
for plat in "${ARR[@]}"; do
p=$(echo "${plat//\//}")
p=$(echo "${p//linux/}")
perImage=$(docker buildx imagetools inspect $image | grep -B 2 $plat | grep Name: | awk '{print $2}')
artifact=${{ needs.context.outputs.fqn }}.$p
folder=/tmp/images/$artifact
docker create --name $artifact $perImage && docker cp $artifact:$output $folder && docker rm $artifact
cd $folder; zip -r /tmp/zip/$artifact.zip ./; cd -
done
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.NUBEIO_CI_GITHUB_PACKAGES_PAT }}
- name: Docker build
uses: docker/build-push-action@v2
with:
context: .
file: docker/Dockerfile
platforms: ${{ env.PLATFORMS }}
build-args: |
BASE_IMAGE_VERSION=3.9
APP_VERSION=${{ needs.context.outputs.version }}
COMMIT_SHA=${{ needs.context.outputs.sha }}
cache-from: type=registry,ref=localhost:5000/${{ env.APP_NAME }}:buildcache
cache-to: type=registry,ref=localhost:5000/${{ env.APP_NAME }}:buildcache,mode=max
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
pull: true
push: true
- name: Cleanup Docker build cache if any
run: |
docker buildx imagetools inspect localhost:5000/${{ env.APP_NAME }}:buildcache || echo "Inspection not working"
echo "======================================================"
docker buildx prune --filter until=72h --keep-storage 5GB -f
- name: Create Release
if: ${{ needs.context.outputs.isRelease == 'true' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.context.outputs.version }}
name: Release v${{ needs.context.outputs.version }}
draft: false
prerelease: false
files: |
/tmp/zip/${{ needs.context.outputs.fqn }}.*.zip