|
1 | 1 | #!/bin/bash
|
2 | 2 | set -e -o pipefail
|
3 |
| -shopt -s expand_aliases |
4 | 3 |
|
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}" |
9 | 51 | echo "Building ${tag} for platforms ${platforms}"
|
| 52 | +set -x |
| 53 | +./cp-static.sh |
10 | 54 |
|
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}" |
13 | 68 |
|
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 |
15 | 82 | if [ -n "$(git status --porcelain)" ]; then
|
16 | 83 | git status
|
17 | 84 | echo ""
|
18 | 85 | echo "Repo is not clean. Refusing to publish."
|
19 | 86 | exit 1
|
20 | 87 | 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" |
27 | 89 | 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}" |
30 | 91 | else
|
31 | 92 | echo "Not pushing $tag because it is not an exact version"
|
32 | 93 | fi
|
|
0 commit comments