-
-
Notifications
You must be signed in to change notification settings - Fork 47
150 lines (142 loc) · 4.89 KB
/
main.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
name: 'Main'
on:
push:
tags: ['*']
branches: ['*']
pull_request:
branches: ['*']
workflow_dispatch:
permissions: {}
jobs:
build-common-stages:
name: 'Build common stages'
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
strategy:
matrix:
stage: ['build']
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Build and save image'
run: |
make \
IMAGE_REGISTRY="localhost" IMAGE_NAMESPACE="stage" IMAGE_PROJECT="${{ matrix.stage }}" \
IMAGE_BUILD_OPTS="--pull --target ${{ matrix.stage }} --build-arg BUILDKIT_INLINE_CACHE=1" \
build-native-image save-native-image
- name: 'Upload artifacts'
uses: 'actions/upload-artifact@v3'
with:
name: 'dist-common-stages'
path: './dist/'
retention-days: 1
build:
name: 'Build ${{ matrix.arch }} image'
needs: ['build-common-stages']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
strategy:
matrix:
arch: ['native', 'amd64', 'arm64v8']
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Download artifacts'
uses: 'actions/download-artifact@v3'
with:
name: 'dist-common-stages'
path: './dist/'
- name: 'Load common stages'
run: |
docker system prune --all --force
make IMAGE_REGISTRY="localhost" IMAGE_NAMESPACE="stage" IMAGE_PROJECT="build" load-native-image clean
- name: 'Register binfmt entries'
if: "matrix.arch != 'native'"
run: |
make binfmt-register
- name: 'Build and save image'
run: |
make \
IMAGE_BUILD_OPTS="--cache-from localhost/stage/build:latest" \
"build-${{ matrix.arch }}-image" "save-${{ matrix.arch }}-image"
- name: 'Upload artifacts'
if: "startsWith(github.ref, 'refs/tags/v') && matrix.arch != 'native'"
uses: 'actions/upload-artifact@v3'
with:
name: 'dist-${{ matrix.arch }}'
path: './dist/'
retention-days: 1
push:
name: 'Push ${{ matrix.arch }} image'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['build']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
strategy:
matrix:
arch: ['amd64', 'arm64v8']
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Download artifacts'
uses: 'actions/download-artifact@v3'
with:
name: 'dist-${{ matrix.arch }}'
path: './dist/'
- name: 'Login to Docker Hub'
uses: 'docker/login-action@v2'
with:
registry: 'docker.io'
username: '${{ secrets.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
- name: 'Load and push image'
run: |
make "load-${{ matrix.arch }}-image" "push-${{ matrix.arch }}-image"
push-manifest:
name: 'Push manifest'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['push']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Login to Docker Hub'
uses: 'docker/login-action@v2'
with:
registry: 'docker.io'
username: '${{ secrets.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
- name: 'Push manifest'
run: |
make push-cross-manifest
release-github:
name: 'Create GitHub release'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['push-manifest']
runs-on: 'ubuntu-latest'
permissions:
contents: 'write'
steps:
- name: 'Create release'
env:
GITHUB_PAT: '${{ secrets.GITHUB_TOKEN }}'
run: |
RELEASE_STATUS="$(curl -fs --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases/tags/${GITHUB_REF_NAME:?}" \
--header "Authorization: Bearer ${GITHUB_PAT:?}" \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--write-out '%{http_code}' --output /dev/null ||:)"
if [ "${RELEASE_STATUS:?}" = '200' ]; then exit 0; fi
RELEASE_ID="$(curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases" \
--header "Authorization: Bearer ${GITHUB_PAT:?}" \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--data "$(jq -rn --arg tag "${GITHUB_REF_NAME:?}" '{"name": $tag, "tag_name": $tag, "generate_release_notes": true}')" | jq -r '.id')"
if [ -z "${RELEASE_ID-}" ] || [ "${RELEASE_ID:?}" = 'null' ]; then exit 1; fi