-
Notifications
You must be signed in to change notification settings - Fork 11
197 lines (191 loc) · 6.07 KB
/
Copy pathnexus-cd.yaml
File metadata and controls
197 lines (191 loc) · 6.07 KB
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
name: CD / Nexus
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
push:
branches:
- "master"
tags:
- 'v*.*.*'
permissions:
contents: read
env:
GOPATH: /home/runner/go
GOBIN: /home/runner/go/bin
GOPROXY: "https://proxy.golang.org"
REGISTRY_IMAGE: ghcr.io/pluralsh/nexus
DOCKER_METADATA_PR_HEAD_SHA: 'true'
jobs:
test:
name: Unit test
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: go/nexus
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go/nexus/go.mod
cache: true
- run: go mod download
- run: PATH=$PATH:$GOPATH/bin make test
build-nexus:
name: Build nexus image
needs: [test]
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'
strategy:
fail-fast: false
matrix:
platforms:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.platforms.runner }}
defaults:
run:
shell: bash
working-directory: go/nexus
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Prepare
run: |
platform=${{ matrix.platforms.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: google-github-actions/auth@v1
with:
workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github'
service_account: 'terraform@pluralsh.iam.gserviceaccount.com'
token_format: 'access_token'
create_credentials_file: true
- uses: google-github-actions/setup-gcloud@v1.0.1
- name: Login to GCR
run: gcloud auth configure-docker -q
- name: Login to Docker
uses: docker/login-action@v3
with:
username: mjgpluralsh
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: "./go/nexus"
file: "./go/nexus/Dockerfile"
tags: ${{ env.REGISTRY_IMAGE }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platforms.platform }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
GIT_COMMIT=${{ github.sha }}
VERSION=${{ steps.meta.outputs.version }}
BUILD_TIME=${{ env.BUILD_TIME }}
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digests-nexus-${{ env.PLATFORM_PAIR }}-${{ github.run_id }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish-nexus:
name: Publish nexus image
needs: [build-nexus]
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'
strategy:
fail-fast: false
matrix:
images:
- ghcr.io/pluralsh/nexus
- gcr.io/pluralsh/nexus
- docker.io/pluralsh/nexus
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v7
with:
path: ${{ runner.temp }}/digests
pattern: digests-nexus-*
merge-multiple: true
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: google-github-actions/auth@v1
with:
workload_identity_provider: 'projects/${{ secrets.GOOGLE_PROJECT_ID }}/locations/global/workloadIdentityPools/github/providers/github'
service_account: 'terraform@pluralsh.iam.gserviceaccount.com'
token_format: 'access_token'
create_credentials_file: true
- uses: google-github-actions/setup-gcloud@v1.0.1
- name: Login to GCR
run: gcloud auth configure-docker -q
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: mjgpluralsh
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Resolve tag version
id: tag_version
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.images }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
type=semver,pattern={{version}},value=${{ steps.tag_version.outputs.version }},enable=${{ steps.tag_version.outputs.version != '' }}
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event.inputs.tag != '' }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ matrix.images }}:${{ steps.meta.outputs.version }}