Skip to content
This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Commit 1467f50

Browse files
committed
ci: fix build scripts
1 parent d0477a0 commit 1467f50

File tree

3 files changed

+87
-21
lines changed

3 files changed

+87
-21
lines changed

.github/workflows/build.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ name: CI
22
on:
33
release:
44
types: [released, prereleased]
5-
workflow_dispatch: # allow manually running from the Actions tab
5+
workflow_dispatch: # allow manually running from the Actions tab
66

77
jobs:
88
build:
99
runs-on: ubuntu-latest
10-
env:
11-
BUILDX_PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
10+
strategy:
11+
matrix:
12+
include:
13+
- image: baseimage
14+
platform: linux/amd64,linux/arm64
15+
- image: alpine
16+
platform: linux/amd64
1217
steps:
1318
- uses: actions/checkout@v2
1419
- uses: docker/setup-qemu-action@v1
@@ -17,4 +22,4 @@ jobs:
1722
with:
1823
username: ${{ secrets.DOCKERHUB_USERNAME }}
1924
password: ${{ secrets.DOCKERHUB_PASSWORD }}
20-
- run: bash build.sh --publish
25+
- run: bash build.sh --publish -i ${{matrix.image}} -p ${{matrix.platform}}

build.sh

+77-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,93 @@
11
#!/bin/bash
22
set -e -o pipefail
3-
shopt -s expand_aliases
43

5-
./cp-static.sh
6-
tag=$(git describe --tags)
7-
platforms=${BUILDX_PLATFORMS:-linux/amd64}
8-
alias buildx_build="docker buildx build --platform=${platforms}"
4+
usage="$0 -i <image> [options]
5+
-i <image> \"baseimage\" or \"alpine\"
6+
-p <platform> Build images for this platform(s)
7+
--test Run tests after build
8+
--publish Run tests and push images after build
9+
"
10+
while getopts "h-:i:p:" opt; do
11+
case $opt in
12+
-)
13+
case $OPTARG in
14+
test)
15+
TEST=1
16+
;;
17+
publish)
18+
TEST=1
19+
PUBLISH=1
20+
;;
21+
*)
22+
echo "$usage"
23+
exit 1
24+
;;
25+
esac
26+
;;
27+
i)
28+
IMAGE="$OPTARG"
29+
;;
30+
p)
31+
PLATFORM="$OPTARG"
32+
;;
33+
h)
34+
echo "$usage"
35+
exit 0
36+
;;
37+
\?)
38+
echo "$usage"
39+
exit 1
40+
;;
41+
esac
42+
done
43+
if [ -z "$IMAGE" ]; then
44+
echo "$usage"
45+
exit 1
46+
fi
47+
shift $((OPTIND - 1))
48+
49+
tag=$(git describe --tags || echo "latest")
50+
platforms="${PLATFORM:-linux/amd64}"
951
echo "Building ${tag} for platforms ${platforms}"
52+
set -x
53+
./cp-static.sh
1054

11-
buildx_build --pull py3-baseimage -t "stevearc/pypicloud:latest"
12-
buildx_build --pull py3-alpine -t "stevearc/pypicloud:latest-alpine"
55+
case $IMAGE in
56+
baseimage)
57+
suffix=""
58+
;;
59+
alpine)
60+
suffix="-$IMAGE"
61+
;;
62+
*)
63+
echo "Unrecognized image $IMAGE"
64+
exit 1
65+
;;
66+
esac
67+
docker buildx build "--platform=${platforms}" --pull "py3-$IMAGE" -t "stevearc/pypicloud:latest${suffix}"
1368

14-
if [ "$1" == '--publish' ]; then
69+
if [ $TEST ]; then
70+
echo "Build and load single-platform image for test"
71+
if [[ $platforms =~ , ]]; then
72+
docker buildx build "--platform=linux/amd64" "py3-$IMAGE" --load -t "stevearc/pypicloud:latest${suffix}"
73+
else
74+
docker buildx build "--platform=${platforms}" "py3-$IMAGE" --load -t "stevearc/pypicloud:latest${suffix}"
75+
fi
76+
echo "Running tests"
77+
./test.sh "latest$suffix"
78+
echo "Tests passed"
79+
fi
80+
81+
if [ $PUBLISH ]; then
1582
if [ -n "$(git status --porcelain)" ]; then
1683
git status
1784
echo ""
1885
echo "Repo is not clean. Refusing to publish."
1986
exit 1
2087
fi
21-
echo "Running tests"
22-
./test.sh latest
23-
./test.sh latest-alpine
24-
echo "Tests passed"
25-
buildx_build --push py3-baseimage -t "stevearc/pypicloud:latest"
26-
buildx_build --push py3-alpine -t "stevearc/pypicloud:latest-alpine"
88+
docker buildx build "--platform=${platforms}" --push "py3-$IMAGE" -t "stevearc/pypicloud:latest$suffix"
2789
if git describe --tags --exact-match; then
28-
buildx_build --push py3-baseimage -t "stevearc/pypicloud:$tag"
29-
buildx_build --push py3-alpine -t "stevearc/pypicloud:$tag-alpine"
90+
docker buildx build "--platform=${platforms}" --push "py3-$IMAGE" -t "stevearc/pypicloud:${tag}${suffix}"
3091
else
3192
echo "Not pushing $tag because it is not an exact version"
3293
fi

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cleanup() {
99
trap cleanup SIGINT SIGTERM EXIT
1010

1111
docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
12-
docker run -d --name "$CONTAINER" -P "stevearc/pypicloud:$tag"
12+
docker run --pull never -d --name "$CONTAINER" -P "stevearc/pypicloud:$tag"
1313
sleep 5
1414

1515
port=$(docker inspect "$CONTAINER" | jq -r '.[0].NetworkSettings.Ports["8080/tcp"][0].HostPort')

0 commit comments

Comments
 (0)