-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (177 loc) Β· 8.28 KB
/
build-docker.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
name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- '*.*.*'
pull_request:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Version to build and deploy'
required: false
is_release:
description: 'Is this a release build?'
required: false
default: false
type: boolean
env:
REPO: 'artifact.aerospike.io/ecosystem-container-dev-local'
JFROG_CLI_BUILD_NAME: 'asvec'
JFROG_CLI_LOG_LEVEL: DEBUG
JFROG_CLI_BUILD_PROJECT: 'ecosystem'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install JFrog CLI
uses: jfrog/setup-jfrog-cli@v3
with:
version: 'latest'
- name: Login to Artifact Aerospike Docker Registry
run: |
jf docker login artifact.aerospike.io --username ${{ secrets.JFROG_USERNAME }} --password ${{ secrets.JFROG_ACCESS_TOKEN }}
env:
JFROG_CLI_OFFER_CONFIG: 'false'
- name: Configure JFrog CLI
run: |
jf c add \
--url https://artifact.aerospike.io/ \
--user ${{ secrets.JFROG_USERNAME }} \
--access-token ${{ secrets.JFROG_ACCESS_TOKEN }} \
artifact
jf c use artifact
env:
JFROG_CLI_OFFER_CONFIG: 'false'
- name: Set Version
run: |
# Initialize variables
VERSION_ARG=""
VERSION=""
IS_RELEASE="${{ github.event.inputs.is_release }}"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
# On tag push: Use the tag name as the version
VERSION="${GITHUB_REF#refs/tags/}"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# On manual trigger
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION_ARG="${{ github.event.inputs.version }}"
else
# If no version input provided, default to RELEASE file
VERSION_ARG=$(cat RELEASE)
fi
if [ "${IS_RELEASE}" == 'true' ]; then
# If release checkbox is checked, use version directly
VERSION="${VERSION_ARG}"
else
# If not release, append build ID
VERSION="${VERSION_ARG}-${GITHUB_RUN_NUMBER}"
fi
else
# In all other cases: Use RELEASE file content appended with build ID
VERSION_ARG=$(cat RELEASE)
VERSION="${VERSION_ARG}-${GITHUB_RUN_NUMBER}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Build Docker Image (No Push)
if: github.event_name == 'pull_request'
run: |
jf docker buildx bake \
--set asvec.tags.0=asvec:test-${{ github.run_id }} \
--file docker/asvec.docker/bake.hcl \
env:
DOCKER_BUILDKIT: '1'
- name: Build and Push Docker Image
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
run: |
jf docker buildx bake \
--set asvec.tags=${{ env.REPO }}/asvec:${{ env.VERSION }} \
--file docker/asvec.docker/bake.hcl \
--push \
--metadata-file=build-metadata
env:
DOCKER_BUILDKIT: '1'
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Extract Image Name and Digest
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
jq -r '.[] | {digest: .["containerimage.digest"], names: .["image.name"] | split(",")} | "(.digest)"' build-metadata > sha
echo ${{ env.REPO }}/asvec:${{ env.VERSION }}@$(cat sha) > meta-info
echo ${{ env.REPO }}/asvec:${{ env.VERSION }}@$(cat sha) > meta-info-latest
- name: Create Docker Build Info
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
jf rt build-docker-create \
--build-name "${{ env.JFROG_CLI_BUILD_NAME }}-container" \
--build-number "${{ env.VERSION }}" \
--image-file ./meta-info \
--project ecosystem \
ecosystem-container-dev-local
- name: Publish Build Info
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
export JFROG_CLI_LOG_LEVEL=DEBUG
jf rt build-collect-env --project ecosystem "${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
jf rt build-add-git --project ecosystem "${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
jf rt build-publish \
--detailed-summary \
--project ecosystem \
"${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
# All of the following steps are commented out because they are just to handle "latest" tag and it is typically not desired in a release bundle
# - name: Tag a release with latest (Release)
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
# run: |
# jf docker buildx imagetools create --tag ${{ env.REPO }}/asvec:latest ${{ env.REPO }}/asvec:${{ env.VERSION }}
# env:
# DOCKER_BUILDKIT: '1'
# - name: Create Docker Build Info for latest
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/')))
# run: |
# jf rt build-docker-create \
# --build-name "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" \
# --build-number "${{ env.VERSION }}" \
# --image-file ./meta-info \
# --project ecosystem \
# ecosystem-container-dev-local
# - name: Publish Build Info for latest
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
# run: |
# jfrog rt build-collect-env "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"
# jfrog rt build-add-git "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"
# jfrog rt build-add-dependencies "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}".
# jf rt build-publish \
# --detailed-summary \
# --project ecosystem \
# "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"
- name: Create Release Bundle
if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true'|| (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/')))
run: |
echo '{
"name": "${{ env.JFROG_CLI_BUILD_NAME }}",
"version": "${{ env.VERSION }}",
"description": "Release bundle for ${{github.repository}} version ${{ env.VERSION }}",
"files": [
{
"project": "ecosystem",
"build": "${{ env.JFROG_CLI_BUILD_NAME }}-container"
}
]
}' > release-bundle-spec.json
cat release-bundle-spec.json
jf release-bundle-create \
"${{ env.JFROG_CLI_BUILD_NAME }}" "${{ env.VERSION }}"\
--project ecosystem \
--spec release-bundle-spec.json \
--signing-key aerospike --sync