Skip to content

Commit 0f04441

Browse files
committedJul 3, 2024
Extracted workflow into re-useable workflow
1 parent 68abc0a commit 0f04441

File tree

2 files changed

+273
-235
lines changed

2 files changed

+273
-235
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
name: Build, test and push multi-platform Docker image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
rondb_version:
7+
required: true
8+
type: string
9+
rondb_x86_tarball_name:
10+
required: true
11+
type: string
12+
rondb_arm64_tarball_name:
13+
required: true
14+
type: string
15+
is_latest_rondb_release:
16+
required: true
17+
description: "Used to decide whether the Docker image will be using the 'latest' tag without a version number"
18+
type: boolean
19+
skip_test:
20+
required: true
21+
type: boolean
22+
23+
env:
24+
BASE_DOWNLOAD_URL: https://repo.hops.works/master
25+
ARM_IMAGE_NAME: rondb-standalone-arm64
26+
X86_IMAGE_NAME: rondb-standalone-amd64
27+
28+
jobs:
29+
check-git:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
is_highest_release: ${{ steps.is_highest_release.outputs.is_highest }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Check if current branch is the highest release branch
39+
if: github.repository == 'logicalclocks/rondb-docker'
40+
id: is_highest_release
41+
run: |
42+
ALL_RELEASES=$(git branch -r | grep 'origin/release-' | sed 's|origin/||')
43+
HIGHEST_RELEASE=$(echo "$ALL_RELEASES" | sort -V | tail -n 1)
44+
echo "Highest release branch is $HIGHEST_RELEASE"
45+
if [ "${GITHUB_REF_NAME}" = "$HIGHEST_RELEASE" ]; then
46+
echo "Current branch is the highest release branch."
47+
echo "is_highest=true" >> $GITHUB_ENV
48+
else
49+
echo "is_highest=false" >> $GITHUB_ENV
50+
fi
51+
52+
integration-test-x86:
53+
runs-on: ubuntu-latest
54+
if: inputs.skip_test == 'false'
55+
needs: [check-git]
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Build and run Docker Compose cluster with benchmarking
60+
run: |
61+
./run.sh -lv \
62+
--rondb-tarball-url $BASE_DOWNLOAD_URL/${{ inputs.rondb_x86_tarball_name }} \
63+
--rondb-version ${{ inputs.rondb_version }} \
64+
--size mini \
65+
--run-benchmark sysbench_single \
66+
--detached
67+
68+
- name: Wait for one container exit or timeout
69+
run: |
70+
start=`date +%s`
71+
while true; do
72+
end=`date +%s`
73+
runtime=$((end-start))
74+
if [ $( docker container ls --filter "status=exited" | grep rondb | wc -l ) -gt 0 ]; then
75+
echo "One container is down. We can continue"
76+
docker container ls --filter "status=exited"
77+
exit 0
78+
elif [ $runtime -gt 800 ]; then
79+
echo "The benchmarking seems to be stuck. We're aborting now."
80+
docker ps
81+
exit 1
82+
fi
83+
sleep 2
84+
done
85+
86+
- run: docker container ls
87+
- run: docker logs mgmd_1
88+
- run: docker logs ndbd_1
89+
- run: docker logs mysqld_1
90+
- run: docker logs rest_1
91+
- run: docker logs bench_1
92+
93+
# At this point we only know that one container has exited. We want to
94+
# check whether the bench container has exited with exit code 0. We need
95+
# both status and exit code to do so, since Docker reports exit code 0
96+
# for running containers.
97+
- name: Check Benchmarking Exit Code
98+
run: |
99+
if [ "$(docker inspect bench_1 --format='{{.State.Status}}')" != "exited" ]
100+
then
101+
echo "Some container other than bench_1 exited unexpectedly."
102+
docker ps -a
103+
exit 1
104+
elif [ "$(docker inspect bench_1 --format='{{.State.ExitCode}}')" != "0" ]
105+
then
106+
echo "Benchmarking failed."
107+
cat autogenerated_files/*/volumes/sysbench_single/sysbench_results/oltp_rw_0_0.res
108+
exit 1
109+
fi
110+
111+
- name: Printing Sysbench results
112+
run: cat autogenerated_files/*/volumes/sysbench_single/final_result.txt
113+
114+
build-x86:
115+
runs-on: ubuntu-latest
116+
if: inputs.skip_test == 'true'
117+
steps:
118+
- uses: actions/checkout@v4
119+
120+
- name: Build X86 image
121+
if: github.repository == 'logicalclocks/rondb-docker' && (startsWith(github.ref_name, 'release-') || github.ref_name == 'main')
122+
run: |
123+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
124+
docker buildx build . \
125+
--tag rondb-standalone:${{ inputs.rondb_version }}-$VERSION \
126+
--build-arg RONDB_VERSION=${{ inputs.rondb_version }} \
127+
--build-arg RONDB_TARBALL_LOCAL_REMOTE=remote \
128+
--build-arg RONDB_X86_TARBALL_URI=$BASE_DOWNLOAD_URL/$STABLE_X86_TARBALL_NAME
129+
130+
push-x86:
131+
runs-on: ubuntu-latest
132+
# It's always EITHER one or the other that will be run
133+
# https://github.com/actions/runner/issues/491#issuecomment-850884422
134+
needs: [integration-test-x86, build-x86]
135+
if: |
136+
always() &&
137+
(needs.integration-test-x86.result == 'success' || needs.integration-test-x86.result == 'skipped') &&
138+
(needs.build-x86.result == 'success' || needs.build-x86.result == 'skipped') &&
139+
github.repository == 'logicalclocks/rondb-docker' && (startsWith(github.ref_name, 'release-') || github.ref_name == 'main')
140+
steps:
141+
- name: Login to Dockerhub
142+
uses: docker/login-action@v2
143+
with:
144+
username: hopsworks
145+
password: ${{ secrets.DOCKERHUB_TOKEN }}
146+
147+
- name: Push standard versioned image
148+
run: |
149+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
150+
IMAGE_NAME=hopsworks/$X86_IMAGE_NAME:${{ inputs.rondb_version }}-$VERSION
151+
152+
docker tag rondb-standalone:${{ inputs.rondb_version }}-$VERSION $IMAGE_NAME
153+
docker push $IMAGE_NAME
154+
155+
# Our "latest" branch points to the latest *release* branch.
156+
- name: Push with "latest" tag (omit rondb-docker version)
157+
if: needs.check-git.outputs.is_highest_release == 'true'
158+
run: |
159+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
160+
IMAGE_NAME=hopsworks/$X86_IMAGE_NAME:${{ inputs.rondb_version }}-latest
161+
162+
docker tag rondb-standalone:${{ inputs.rondb_version }}-$VERSION $IMAGE_NAME
163+
docker push $IMAGE_NAME
164+
165+
- name: Push with "latest" tag (also omit rondb version)
166+
if: needs.check-git.outputs.is_highest_release == 'true' && inputs.is_latest_rondb_release == 'true'
167+
run: |
168+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
169+
IMAGE_NAME=hopsworks/$X86_IMAGE_NAME:latest
170+
171+
docker tag rondb-standalone:${{ inputs.rondb_version }}-$VERSION $IMAGE_NAME
172+
docker push $IMAGE_NAME
173+
174+
build-and-push-ARM64:
175+
runs-on: ubuntu-latest
176+
if: github.repository == 'logicalclocks/rondb-docker' && (startsWith(github.ref_name, 'release-') || github.ref_name == 'main')
177+
steps:
178+
- uses: actions/checkout@v4
179+
180+
- name: Set up QEMU
181+
uses: docker/setup-qemu-action@v2
182+
183+
- name: Set up Docker Buildx
184+
uses: docker/setup-buildx-action@v2
185+
186+
- name: Login to Dockerhub
187+
uses: docker/login-action@v2
188+
with:
189+
username: hopsworks
190+
password: ${{ secrets.DOCKERHUB_TOKEN }}
191+
192+
# We're skipping the benchmarking on ARM64 as we assume this will be run on a regular basis
193+
# during development. ARM64 images are only for development anyways. It is more important to add
194+
# all types of benchmarking to the tests.
195+
- name: Build and push ARM64 image
196+
run: |
197+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
198+
TAGS="--tag hopsworks/$ARM_IMAGE_NAME:${{ inputs.rondb_version }}-$VERSION"
199+
if [[ "${{ needs.check-git.outputs.is_highest_release }}" == "true" ]]; then
200+
TAGS+=" --tag hopsworks/$ARM_IMAGE_NAME:${{ inputs.rondb_version }}-latest"
201+
if [[ "${{ inputs.is_latest_rondb_release }}" == "true" ]]; then
202+
TAGS+=" --tag hopsworks/$ARM_IMAGE_NAME:latest"
203+
fi
204+
fi
205+
206+
docker buildx build . \
207+
$TAGS \
208+
--platform=linux/arm64 \
209+
--output type=registry \
210+
--build-arg RONDB_VERSION=${{ inputs.rondb_version }} \
211+
--build-arg RONDB_TARBALL_LOCAL_REMOTE=remote \
212+
--build-arg RONDB_ARM_TARBALL_URI=$BASE_DOWNLOAD_URL/${{ inputs.rondb_arm64_tarball_name }} \
213+
--cache-to type=registry,ref=hopsworks/rondb-standalone-cache,mode=max \
214+
--cache-from type=registry,ref=hopsworks/rondb-standalone-cache,mode=max
215+
216+
make-multi-platform-image:
217+
runs-on: ubuntu-latest
218+
if: github.repository == 'logicalclocks/rondb-docker' && (startsWith(github.ref_name, 'release-') || github.ref_name == 'main')
219+
needs: [push-x86, build-and-push-ARM64]
220+
steps:
221+
- uses: actions/checkout@v4
222+
223+
- name: Set up Docker Buildx
224+
uses: docker/setup-buildx-action@v2
225+
226+
- name: Login to Dockerhub
227+
uses: docker/login-action@v2
228+
with:
229+
username: hopsworks
230+
password: ${{ secrets.DOCKERHUB_TOKEN }}
231+
232+
- name: Create and push multi-platform image
233+
run: |
234+
VERSION="$(sed -e 's/^[[:space:]]*//' -e '/-SNAPSHOT$/s/.*/dev/' ./VERSION)"
235+
236+
docker buildx imagetools create -t hopsworks/rondb-standalone:${{ inputs.rondb_version }}-$VERSION \
237+
hopsworks/$X86_IMAGE_NAME:${{ inputs.rondb_version }}-$VERSION \
238+
hopsworks/$ARM_IMAGE_NAME:${{ inputs.rondb_version }}-$VERSION
239+
240+
if [[ "${{ needs.check-git.outputs.is_highest_release }}" == "true" ]]; then
241+
docker buildx imagetools create -t hopsworks/rondb-standalone:${{ inputs.rondb_version }}-latest \
242+
hopsworks/$X86_IMAGE_NAME:${{ inputs.rondb_version }}-latest \
243+
hopsworks/$ARM_IMAGE_NAME:${{ inputs.rondb_version }}-latest
244+
245+
if [[ "${{ inputs.is_latest_rondb_release }}" == "true" ]]; then
246+
docker buildx imagetools create -t hopsworks/rondb-standalone:latest \
247+
hopsworks/$X86_IMAGE_NAME:latest \
248+
hopsworks/$ARM_IMAGE_NAME:latest
249+
fi
250+
fi

0 commit comments

Comments
 (0)