babashka/.circleci/script/docker

62 lines
2.7 KiB
Text
Raw Normal View History

2019-08-09 12:51:42 +00:00
#!/usr/bin/env bash
2020-02-09 21:55:12 +00:00
set -eo pipefail
2021-01-01 10:26:31 +00:00
image_name="babashka/babashka"
2020-02-09 21:55:12 +00:00
image_tag=$(cat resources/BABASHKA_VERSION)
2021-12-15 15:28:39 +00:00
platform=${PLATFORM:-"linux/amd64"}
2019-08-09 12:51:42 +00:00
latest_tag="latest"
2022-01-11 20:38:43 +00:00
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}")
2019-08-09 12:51:42 +00:00
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
2021-12-15 15:28:39 +00:00
echo "Building & pushing $platform Docker image(s) $image_name:$image_tag"
2019-08-09 12:51:42 +00:00
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
2021-12-15 15:28:39 +00:00
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
done
2022-01-11 20:38:43 +00:00
docker buildx build -t "$image_name:$image_tag" --platform "$platform" "${label_args[@]}" --push -f Dockerfile.ci .
if [[ $snapshot == "false" ]]; then
2021-12-15 15:28:39 +00:00
echo "Building & pushing $platform Docker image(s) $image_name:$latest_tag"
2022-01-11 20:38:43 +00:00
docker buildx build -t "$image_name:$latest_tag" --platform "$platform" "${label_args[@]}" --push -f Dockerfile.ci .
2021-12-15 15:28:39 +00:00
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"
docker buildx build -t "$image_name:alpine" --platform=linux/amd64 "${label_args[@]}" -f Dockerfile.alpine .
rm -f bb
docker tag "$image_name:alpine" "$image_name:$image_tag-alpine"
echo "Pushing image $image_name:$image_tag-alpine"
docker push "$image_name:$image_tag-alpine"
if [[ $snapshot == "false" ]]; then
echo "Pushing image $image_name:alpine"
docker push "$image_name:alpine"
fi
2019-08-09 12:51:42 +00:00
else
echo "Not publishing Docker image"
fi
exit 0;