-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (153 loc) · 6.56 KB
/
release.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
name: Release
on:
push:
tags:
- v*
workflow_dispatch: {}
permissions:
contents: write
jobs:
build:
name: Build
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
arch: amd64
- platform: linux/arm64
arch: arm64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare environment variables
run: cat .github/.env >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.6 # datasource=github-releases depName=golang/go
- name: Set up QEMU
if: contains(matrix.platform, 'linux/arm64')
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Login to DockerHub
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Configure AWS credentials
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
- name: Login to Amazon ECR Public
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Calculate new version number
id: version
run: echo VERSION=$(make version) | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: Build image
run: make image PLATFORM="${{ matrix.platform }}"
env:
GOOS: linux
GOARCH: ${{ matrix.arch }}
- name: Inspect container image
run: docker inspect "localhost:5000/$IMAGE_NAME" | jq -C .
- name: Test image
run: make test-image PLATFORM="${{ matrix.platform }}"
- name: Push to DockerHub
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
run: make push DOCKER_REPO="${DOCKER_REPO}" PLATFORM="${{ matrix.platform }}"
- name: Push to Amazon ECR Public
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
run: make push DOCKER_REPO="${PUBLIC_ECR_REPO}" PLATFORM="${{ matrix.platform }}"
outputs:
version: ${{ steps.version.outputs.VERSION }}
tag:
name: Tag
needs: build
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare environment variables
run: cat .github/.env >> $GITHUB_ENV
- name: Login to DockerHub
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Configure AWS credentials
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
- name: Login to Amazon ECR Public
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Reuse new version number
run: echo VERSION=${{ needs.build.outputs.version }} | tee -a $GITHUB_ENV
- name: Tag multiarch images for DockerHub
run: |
docker manifest create ${DOCKER_REPO}:v${VERSION} ${DOCKER_REPO}:v${VERSION}-linux-arm64 ${DOCKER_REPO}:v${VERSION}-linux-amd64
docker manifest push ${DOCKER_REPO}:v${VERSION}
docker manifest create ${DOCKER_REPO}:v${VERSION%.*} ${DOCKER_REPO}:v${VERSION}-linux-arm64 ${DOCKER_REPO}:v${VERSION}-linux-amd64
docker manifest push ${DOCKER_REPO}:v${VERSION%.*}
docker manifest create ${DOCKER_REPO}:v${VERSION%%.*} ${DOCKER_REPO}:v${VERSION}-linux-arm64 ${DOCKER_REPO}:v${VERSION}-linux-amd64
docker manifest push ${DOCKER_REPO}:v${VERSION%%.*}
docker manifest create ${DOCKER_REPO}:latest ${DOCKER_REPO}:v${VERSION}-linux-arm64 ${DOCKER_REPO}:v${VERSION}-linux-amd64
docker manifest push ${DOCKER_REPO}:latest
- name: Tag multiarch images for Amazon ECR Public
run: |
docker manifest create ${PUBLIC_ECR_REPO}:v${VERSION} ${PUBLIC_ECR_REPO}:v${VERSION}-linux-arm64 ${PUBLIC_ECR_REPO}:v${VERSION}-linux-amd64
docker manifest push ${PUBLIC_ECR_REPO}:v${VERSION}
docker manifest create ${PUBLIC_ECR_REPO}:v${VERSION%.*} ${PUBLIC_ECR_REPO}:v${VERSION}-linux-arm64 ${PUBLIC_ECR_REPO}:v${VERSION}-linux-amd64
docker manifest push ${PUBLIC_ECR_REPO}:v${VERSION%.*}
docker manifest create ${PUBLIC_ECR_REPO}:v${VERSION%%.*} ${PUBLIC_ECR_REPO}:v${VERSION}-linux-arm64 ${PUBLIC_ECR_REPO}:v${VERSION}-linux-amd64
docker manifest push ${PUBLIC_ECR_REPO}:v${VERSION%%.*}
docker manifest create ${PUBLIC_ECR_REPO}:latest ${PUBLIC_ECR_REPO}:v${VERSION}-linux-arm64 ${PUBLIC_ECR_REPO}:v${VERSION}-linux-amd64
docker manifest push ${PUBLIC_ECR_REPO}:latest
release:
name: Release
needs:
- tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch Git tags
run: git fetch --force --tags
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.6 # datasource=github-releases depName=golang/go
- name: Goreleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: 1.23.0 # datasource=github-releases depName=goreleaser/goreleaser
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}