-
Notifications
You must be signed in to change notification settings - Fork 221
252 lines (228 loc) · 9.06 KB
/
build_dockers_workflow.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
---
name: Build docker images - workflow_call/on-demand
'on':
workflow_call:
secrets:
DOCKER_PROVIDER:
required: true
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
inputs:
toolchain:
type: string
description: 'Rust toolchain'
default: nightly-2024-07-07
arch:
type: string
default: x86-64
features:
type: string
default: 'safe,grpc'
version:
type: string
description: 'build tag/version'
tag_alias:
type: string
description: 'build tag alias'
build_items:
type: string
default: minotari_sha3_miner
description: 'build images'
platforms:
type: string
# linux/arm64, linux/amd64
default: linux/amd64
env:
LAUNCHPAD_REPO: tari-project/tari-launchpad
LAUNCHPAD_BRANCH: main
DAYS_to_EXPIRE: 30
permissions: {}
jobs:
envs_setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set_matrix.outputs.matrix }}
steps:
- name: checkout tari-launchpad
uses: actions/checkout@v4
with:
repository: ${{ env.LAUNCHPAD_REPO }}
ref: ${{ env.LAUNCHPAD_BRANCH }}
path: tari-launchpad
- name: Set Matrix
id: set_matrix
shell: bash
run: |
build_items=${{ inputs.build_items }}
echo "Building with ${build_items}."
if [ -z "${build_items}" ] || [ "${build_items}" = "minotari_all" ] ; then
echo "Build all Minotari images"
matrix_selection=$( jq -s -c '.[]' tari-launchpad/tarisuite.json )
elif [ "${build_items:0:9}" = "minotari_" ] ; then
echo "Build only selected minotari images - ${build_items}"
matrix_selection=$( jq --arg jsonVar "${build_items}" -r '[. []
| select(."image_name"==$jsonVar)]' tari-launchpad/tarisuite.json )
elif [ "${build_items}" = "all" ] ; then
echo "Build all images"
matrix_selection=$( jq -c '. += input' tari-launchpad/tarisuite.json tari-launchpad/3rdparty.json )
elif [ "${build_items:0:8}" = "3rdparty" ] ; then
echo "Build only 3rdparty images - ${build_items}"
matrix_selection=$( jq -s -c '.[]' tari-launchpad/3rdparty.json )
else
echo "Build only selected 3rdparty images - ${build_items}"
matrix_selection=$( jq --arg jsonVar "${build_items}" -r '[. []
| select(."image_name"==$jsonVar)]' tari-launchpad/3rdparty.json )
# "!! Broken selection? !!"
# exit 1
fi
# ToDo: Add error checking
# Setup the json build matrix
matrix=$(echo ${matrix_selection} | jq -s -c '{"builds": .[]}')
echo $matrix
echo $matrix | jq .
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
docker_build:
name: Docker building ${{ matrix.builds.image_name }}
needs: envs_setup
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.envs_setup.outputs.matrix) }}
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: checkout tari
uses: actions/checkout@v4
with:
path: tari
- name: checkout tari-launchpad
uses: actions/checkout@v4
with:
repository: ${{ env.LAUNCHPAD_REPO }}
ref: ${{ env.LAUNCHPAD_BRANCH }}
path: tari-launchpad
- name: Declare TestNet for tags
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
source tari/buildtools/multinet_envs.sh ${{github.ref_name}}
echo ${TARI_NETWORK}
echo "TARI_NETWORK=${TARI_NETWORK}" >> $GITHUB_ENV
echo ${TARI_TARGET_NETWORK}
echo "TARI_TARGET_NETWORK=${TARI_TARGET_NETWORK}" >> $GITHUB_ENV
- name: Setup expiration for none releases
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
echo "EXPIRATION=${{ env.DAYS_to_EXPIRE }}d" >> $GITHUB_ENV
- name: environment setup
shell: bash
run: |
IMAGE_NAME=${{ matrix.builds.image_name }}
if [ -z "${{ inputs.version }}" ] ; then
echo "Get tari version"
TARI_SOURCE_ROOT="tari/"
VAPP=$(awk -F ' = ' '$1 ~ /^version/ \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"${TARI_SOURCE_ROOT}/applications/minotari_node/Cargo.toml")
VBRANCH=$(git --git-dir ${TARI_SOURCE_ROOT}/.git branch --show-current)
VSHA_SHORT=$(git --git-dir ${TARI_SOURCE_ROOT}/.git rev-parse --short HEAD)
VERSION="v${VAPP}_${VBRANCH}_$(date -u '+%Y%m%d')_${VSHA_SHORT}"
else
VERSION=${{ inputs.version }}
fi
echo "Setting ${VERSION} as docker tag"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
if [ ! -z "${{ inputs.tag_alias }}" ] ; then
if [ -z "${{ env.TARI_NETWORK }}" ] ; then
echo "Setup tag_alias"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ matrix.builds.image_name }}:${{ inputs.tag_alias }}" >> $GITHUB_ENV
else
echo "Setup tag_alias with network"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ matrix.builds.image_name }}:${{ inputs.tag_alias }}-${{ env.TARI_NETWORK }}" >> $GITHUB_ENV
fi
fi
if [ "${IMAGE_NAME:0:9}" = "minotari_" ] ; then
echo "Minotari builds"
mkdir -p tari/buildtools/docker_rig
cp -v tari-launchpad/docker_rig/start_tari_app.sh tari/buildtools/docker_rig/start_tari_app.sh
echo "DOCKERFILE=tarilabs" >> $GITHUB_ENV
echo "APP_NAME=${{ matrix.builds.app_name }}" >> $GITHUB_ENV
echo "APP_EXEC=${{ matrix.builds.app_exec }}" >> $GITHUB_ENV
else
echo "3rd Party builds - ${IMAGE_NAME}"
if [ -f "./tari-launchpad/docker_rig/${IMAGE_NAME}.Dockerfile" ] ; then
echo "DOCKERFILE=${IMAGE_NAME}" >> $GITHUB_ENV
SUBTAG=$(awk -v search="^ARG ${IMAGE_NAME^^}?_VERSION=" -F '=' '$0 ~ search \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"./tari-launchpad/docker_rig/${IMAGE_NAME}.Dockerfile")
echo "Docker subtag - ${SUBTAG}"
echo "VERSION=${SUBTAG}_${VERSION}" >> $GITHUB_ENV
echo "DOCKER_SUBTAG=--build-arg ${IMAGE_NAME^^}_VERSION=${SUBTAG}" >> $GITHUB_ENV
else
"!! ${IMAGE_NAME}.Dockerfile file not found !!"
exit 1
fi
fi
- name: Set up QEMU for Docker
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
#name/${{ matrix.builds.image_name }}
ghcr.io/${{ github.repository_owner }}/${{ matrix.builds.image_name }}
tags: |
type=raw,value=latest-${{ env.TARI_NETWORK }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=ref,event=tag
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
labels: |
quay.expires-after=${{ env.EXPIRATION }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Image Provider
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_PROVIDER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker image build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./tari/
file: ./tari-launchpad/docker_rig/${{ env.DOCKERFILE }}.Dockerfile
platforms: ${{ inputs.platforms }}
push: true
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ env.VERSION }}
ARCH=${{ inputs.arch }}
FEATURES=${{ inputs.features }}
APP_NAME=${{ matrix.builds.app_name }}
APP_EXEC=${{ matrix.builds.app_exec }}
TARI_NETWORK=${{ env.TARI_NETWORK }}
TARI_TARGET_NETWORK=${{ env.TARI_TARGET_NETWORK }}
${{ env.DOCKER_SUBTAG }}
tags: |
${{ steps.meta.outputs.tags }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ matrix.builds.image_name }}:${{ env.VERSION }}
${{ env.TAG_ALIAS }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}