-
Notifications
You must be signed in to change notification settings - Fork 7
179 lines (158 loc) · 5.44 KB
/
build-northbound-api.yml
File metadata and controls
179 lines (158 loc) · 5.44 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
name: Build agent containers
on:
workflow_call:
inputs:
agent:
default: 'node'
required: false
type: string
registry:
default: 'harbor.nbfc.io'
required: false
type: string
workflow_dispatch:
inputs:
agent:
default: 'node'
required: false
type: string
registry:
default: 'harbor.nbfc.io'
required: false
type: string
env:
REGISTRY: ${{ github.event.inputs.registry || 'harbor.nbfc.io' }}
REGISTRY_IMAGE: ${{ github.event.inputs.registry || 'harbor.nbfc.io' }}/mlsysops/northbound-api
RUNNER_ARCH_MAP: '[{"amd64":"x86_64", "arm64":"aarch64", "arm":"armv7l"}]'
jobs:
build:
name: Build Docker Image
runs-on: ${{ format('{0}-{1}', 'base-dind-2204', matrix.arch) }}
strategy:
matrix:
arch: ["arm64", "amd64"]
fail-fast: false
outputs:
digest-amd64: ${{ steps.set-outputs.outputs.digest-amd64 }}
digest-arm64: ${{ steps.set-outputs.outputs.digest-arm64 }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Login to registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.HARBOR_USER }}
password: ${{ secrets.HARBOR_SECRET }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=sha,prefix=${{ matrix.arch }}-
type=ref,event=branch,prefix=${{ matrix.arch }}-
- name: Build and push ${{ matrix.arch }} image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: ./northbound-api
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/${{ matrix.arch }}
push: true
file: ./northbound-api/Dockerfile
provenance: false
build-args: |
ARCHTAG=${{ fromJson(env.RUNNER_ARCH_MAP)[0][matrix.arch] }}
BRANCH=${{ github.event.ref_name || github.ref_name }}
- name: Set ${{ matrix.arch }} digest output
id: set-outputs
run: |
# Workaround for https://github.com/actions/runner/issues/2499
echo "digest-${{ matrix.arch }}=${{ steps.build-and-push.outputs.digest }}" \
>> "$GITHUB_OUTPUT"
shell: bash
create-manifest:
name: Create Merged Docker Image Manifest
needs: [build]
runs-on: 'base-dind-2204-amd64'
outputs:
digest-merged: ${{ steps.inspect.outputs.digest-merged }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Login to registry ${{ inputs.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.HARBOR_USER }}
password: ${{ secrets.HARBOR_SECRET }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=sha
type=ref,event=branch
type=raw,value=latest
- name: Create and push manifest
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< \
"$DOCKER_METADATA_OUTPUT_JSON") \
${{ env.REGISTRY_IMAGE }}@${{ needs.build.outputs.digest-amd64 }} \
${{ env.REGISTRY_IMAGE }}@${{ needs.build.outputs.digest-arm64 }}
shell: bash
- name: Inspect merged image
id: inspect
run: |
docker buildx imagetools inspect \
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
digest=$(docker buildx imagetools inspect \
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \
--format '{{json .Manifest}}' | jq -r '.digest')
if [[ -z "${digest}" ]]; then
echo "Could not get merged image digest"
exit 1
fi
echo "digest-merged=${digest}" >> "$GITHUB_OUTPUT"
shell: bash
sign:
name: Sign Docker Images
needs: [build, create-manifest]
runs-on: 'base-dind-2204-amd64'
permissions:
contents: read
id-token: write
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Verify Cosign installation
run: cosign version
- name: Login to registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.HARBOR_USER }}
password: ${{ secrets.HARBOR_SECRET }}
- name: Sign published Docker images
env:
DIGESTS: >-
${{ needs.create-manifest.outputs.digest-merged }}
${{ needs.build.outputs.digest-amd64 }}
${{ needs.build.outputs.digest-arm64 }}
run: |
for digest in ${DIGESTS}; do
cosign sign --yes ${{ env.REGISTRY_IMAGE }}@${digest} \
-a "repo=${{ github.repository }}" \
-a "workflow=${{ github.workflow }}" \
-a "ref=${{ github.sha }}" \
-a "author=Nubificus LTD"
done
shell: bash