-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (182 loc) · 9.11 KB
/
ci-cd.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: CI/CD
on:
push:
branches: [main]
tags:
- "v*"
pull_request:
branches: [main]
workflow_run:
workflows: ["Weekly Tag"]
types:
- completed
jobs:
lint-and-test:
name: Lint and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5
with:
# renovate: datasource=github-tags depName=golang/go
go-version: "1.23.2"
- name: Print Go version
run: go version
- name: Run golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6
with:
# renovate: datasource=github-releases depName=golangci/golangci-lint
version: v1.61.0
- name: Run tests
run: go test -v ./...
build:
name: Build Binaries and Docker Images
needs: lint-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5
with:
# renovate: datasource=github-tags depName=golang/go
go-version: "1.23.2"
- name: Set git variables
id: git_vars
run: |
echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "GIT_REF=$(git describe --tags --always)" >> $GITHUB_OUTPUT
- name: Build binaries
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.gitHash=${{ steps.git_vars.outputs.GIT_HASH }} -X main.gitRef=${{ steps.git_vars.outputs.GIT_REF }}" -o aws-ecr-auth-proxy-amd64 ./cmd/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-X main.gitHash=${{ steps.git_vars.outputs.GIT_HASH }} -X main.gitRef=${{ steps.git_vars.outputs.GIT_REF }}" -o aws-ecr-auth-proxy-arm64 ./cmd/main.go
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Test binaries
run: |
chmod +x aws-ecr-auth-proxy-amd64
chmod +x aws-ecr-auth-proxy-arm64
./aws-ecr-auth-proxy-amd64 version
docker run --rm -v $(pwd):/workspace -w /workspace --platform linux/arm64 alpine ./aws-ecr-auth-proxy-arm64 version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Build Docker images
run: |
# Build AMD64 image
docker buildx build --platform linux/amd64 \
-t aws-ecr-auth-proxy:test-amd64 \
--build-arg ARCH=amd64 \
-f Dockerfile \
--load .
# Build ARM64 image
docker buildx build --platform linux/arm64 \
-t aws-ecr-auth-proxy:test-arm64 \
--build-arg ARCH=arm64 \
-f Dockerfile \
--load .
- name: Test Docker images
run: |
docker run --rm aws-ecr-auth-proxy:test-amd64 /app/aws-ecr-auth-proxy version
docker run --rm --platform linux/arm64 aws-ecr-auth-proxy:test-arm64 /app/aws-ecr-auth-proxy version
- name: Upload binaries
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: binaries
path: |
aws-ecr-auth-proxy-amd64
aws-ecr-auth-proxy-arm64
- name: Save Docker images
run: |
docker save aws-ecr-auth-proxy:test-amd64 > aws-ecr-auth-proxy-amd64.tar
docker save aws-ecr-auth-proxy:test-arm64 > aws-ecr-auth-proxy-arm64.tar
- name: Upload Docker images
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: docker-images
path: |
aws-ecr-auth-proxy-amd64.tar
aws-ecr-auth-proxy-arm64.tar
release:
name: Create Release
needs: build
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'workflow_run' && github.event.workflow_run.name == 'Weekly Tag' && github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Determine version number
id: version
run: |
if [[ ${{ github.event_name }} == 'push' && ${{ github.ref }} == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
git fetch --tags
VERSION=$(git describe --tags --abbrev=0)
VERSION=${VERSION#v}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Download binaries
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: binaries
- name: Download Docker images
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: docker-images
- name: Create Release
id: create_release
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.VERSION }}
release_name: Release v${{ steps.version.outputs.VERSION }}
draft: false
prerelease: false
- name: Upload AMD64 Asset
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./aws-ecr-auth-proxy-amd64
asset_name: aws-ecr-auth-proxy-amd64-v${{ steps.version.outputs.VERSION }}
asset_content_type: application/octet-stream
- name: Upload ARM64 Asset
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./aws-ecr-auth-proxy-arm64
asset_name: aws-ecr-auth-proxy-arm64-v${{ steps.version.outputs.VERSION }}
asset_content_type: application/octet-stream
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push and create multi-arch Docker images
env:
DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/aws-ecr-auth-proxy
run: |
docker load < aws-ecr-auth-proxy-amd64.tar
docker load < aws-ecr-auth-proxy-arm64.tar
docker tag aws-ecr-auth-proxy:test-amd64 $DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-amd64
docker tag aws-ecr-auth-proxy:test-amd64 $DOCKER_REPO:latest-amd64
docker tag aws-ecr-auth-proxy:test-arm64 $DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-arm64
docker tag aws-ecr-auth-proxy:test-arm64 $DOCKER_REPO:latest-arm64
docker push $DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-amd64
docker push $DOCKER_REPO:latest-amd64
docker push $DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-arm64
docker push $DOCKER_REPO:latest-arm64
docker manifest create $DOCKER_REPO:v${{ steps.version.outputs.VERSION }} \
$DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-amd64 \
$DOCKER_REPO:v${{ steps.version.outputs.VERSION }}-arm64
docker manifest push $DOCKER_REPO:v${{ steps.version.outputs.VERSION }}
docker manifest create $DOCKER_REPO:latest \
$DOCKER_REPO:latest-amd64 \
$DOCKER_REPO:latest-arm64
docker manifest push $DOCKER_REPO:latest