babashka/.circleci/script/docker
Michiel Borkent 530177eefd Fix docker 🙏
2022-01-25 15:46:17 +01:00

61 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
set -eo pipefail
image_name="babashka/babashka"
image_tag=$(cat resources/BABASHKA_VERSION)
platform=${PLATFORM:-"linux/amd64"}
latest_tag="latest"
label_args=("--label" "'org.opencontainers.image.description=Native, fast starting Clojure interpreter for scripting'"
"--label" "org.opencontainers.image.title=Babashka"
"--label" "org.opencontainers.image.created=$(date -Iseconds)"
"--label" "org.opencontainers.image.url=${CIRCLE_REPOSITORY_URL}"
"--label" "org.opencontainers.image.documentation=${CIRCLE_REPOSITORY_URL}"
"--label" "org.opencontainers.image.source=${CIRCLE_REPOSITORY_URL}"
"--label" "org.opencontainers.image.revision=${CIRCLE_SHA1}"
"--label" "org.opencontainers.image.ref.name=${CIRCLE_TAG}:${CIRCLE_BRANCH}"
"--label" "org.opencontainers.image.version=${image_tag}")
if [[ $image_tag =~ SNAPSHOT$ ]]; then
echo "This is a snapshot version"
snapshot="true"
else
echo "This is a non-snapshot version"
snapshot="false"
fi
if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]; then
echo "Building & pushing $platform Docker image(s) $image_name:$image_tag"
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
IFS=',' read -r -a platforms <<< "$platform"
for p in "${platforms[@]}"; do
tarball_platform=${p//\//-}
if [[ $tarball_platform == "linux-arm64" ]]; then tarball_platform="linux-aarch64"; fi
mkdir -p $p
tar zxvf "/tmp/release/babashka-${image_tag}-${tarball_platform}.tar.gz" -C $p
# this overwrites, but this is to work around having built the uberjar/metabom multiple times
cp "/tmp/release/${tarball_platform}-metabom.jar" ./metabom.jar
done
docker buildx build -t "$image_name:$image_tag" --platform "$platform" "${label_args[@]}" --push -f Dockerfile.ci .
if [[ $snapshot == "false" ]]; then
echo "Building & pushing $platform Docker image(s) $image_name:$latest_tag"
docker buildx build -t "$image_name:$latest_tag" --platform "$platform" "${label_args[@]}" --push -f Dockerfile.ci .
fi
for p in "${platforms[@]}"; do
rm -rf $p
done
# build alpine image for linux-amd64 only (no upstream arm64 support yet)
tar zxvf "/tmp/release/babashka-${image_tag}-linux-amd64-static.tar.gz"
echo "Building & pushing Docker image $image_name:$image_tag-alpine"
docker buildx build -t "$image_name:$image_tag-alpine" --platform=linux/amd64 "${label_args[@]}" --push -f Dockerfile.alpine .
if [[ $snapshot == "false" ]]; then
echo "Building & pushing Docker image $image_name:alpine"
docker buildx build -t "$image_name:alpine" --platform=linux/amd64 "${label_args[@]}" --push -f Dockerfile.alpine .
fi
else
echo "Not publishing Docker image"
fi
exit 0;