Build arm64 docker image in CI (#1099)
This commit is contained in:
parent
48a8f3ac18
commit
bc0ae17e64
3 changed files with 46 additions and 36 deletions
|
|
@ -3,6 +3,14 @@
|
|||
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
|
||||
#
|
||||
version: 2.1
|
||||
commands:
|
||||
setup-docker-buildx:
|
||||
steps:
|
||||
- run:
|
||||
name: Create multi-platform capabale buildx builder
|
||||
command: |
|
||||
docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
docker buildx create --name ci-builder --use
|
||||
jobs:
|
||||
jvm:
|
||||
docker:
|
||||
|
|
@ -35,10 +43,6 @@ jobs:
|
|||
export BABASHKA_FEATURE_POSTGRESQL=true
|
||||
script/test
|
||||
script/run_lib_tests
|
||||
# - run:
|
||||
# name: Run as tools.deps dependency
|
||||
# command: |
|
||||
# .circleci/script/tools.deps
|
||||
- run:
|
||||
name: Run as lein command
|
||||
command: |
|
||||
|
|
@ -229,14 +233,6 @@ jobs:
|
|||
command: |
|
||||
git submodule init
|
||||
git submodule update
|
||||
- run:
|
||||
name: "Short circuit on SNAPSHOT"
|
||||
command: |
|
||||
VERSION=$(cat resources/BABASHKA_VERSION)
|
||||
if [[ "$VERSION" == *-SNAPSHOT ]]
|
||||
then
|
||||
circleci task halt
|
||||
fi
|
||||
- run:
|
||||
name: Install Clojure
|
||||
command: |
|
||||
|
|
@ -449,16 +445,17 @@ jobs:
|
|||
- ~/.m2
|
||||
key: v1-dependencies-{{ checksum "project.clj" }}
|
||||
docker:
|
||||
docker:
|
||||
- image: circleci/buildpack-deps:bullseye
|
||||
machine:
|
||||
image: ubuntu-2004:202111-01
|
||||
steps:
|
||||
- checkout
|
||||
- setup-docker-buildx
|
||||
- attach_workspace:
|
||||
at: /tmp
|
||||
- setup_remote_docker:
|
||||
version: 19.03.12
|
||||
- run:
|
||||
name: Build Docker image
|
||||
environment:
|
||||
PLATFORM: linux/amd64,linux/arm64
|
||||
command: .circleci/script/docker
|
||||
|
||||
workflows:
|
||||
|
|
@ -482,7 +479,9 @@ workflows:
|
|||
- docker:
|
||||
filters:
|
||||
branches:
|
||||
only: master
|
||||
only:
|
||||
- master
|
||||
requires:
|
||||
- linux
|
||||
- linux-static
|
||||
- linux-aarch64
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ set -eo pipefail
|
|||
|
||||
image_name="babashka/babashka"
|
||||
image_tag=$(cat resources/BABASHKA_VERSION)
|
||||
platform=${PLATFORM:-"linux/amd64"}
|
||||
latest_tag="latest"
|
||||
|
||||
if [[ $image_tag =~ SNAPSHOT$ ]]; then
|
||||
|
|
@ -15,29 +16,36 @@ else
|
|||
fi
|
||||
|
||||
if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]; then
|
||||
echo "Building Docker image $image_name:$image_tag"
|
||||
echo "Building & pushing $platform Docker image(s) $image_name:$image_tag"
|
||||
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
|
||||
tar zxvf "/tmp/release/babashka-${image_tag}-linux-amd64.tar.gz"
|
||||
docker build -t "$image_name" -f Dockerfile.ci .
|
||||
docker tag "$image_name:$latest_tag" "$image_name:$image_tag"
|
||||
rm -f bb
|
||||
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
|
||||
docker buildx build -t "$image_name:$image_tag" --platform "$platform" --push -f Dockerfile.ci .
|
||||
if [[ $snapshot == "false" ]]; then
|
||||
tar zxvf "/tmp/release/babashka-${image_tag}-linux-amd64-static.tar.gz"
|
||||
docker build -t "$image_name:alpine" -f Dockerfile.alpine .
|
||||
docker tag "$image_name:alpine" "$image_name:$image_tag-alpine"
|
||||
echo "Building & pushing $platform Docker image(s) $image_name:$latest_tag"
|
||||
docker buildx build -t "$image_name:$latest_tag" --platform "$platform" --push -f Dockerfile.ci .
|
||||
fi
|
||||
# we only update latest when it's not a SNAPSHOT version
|
||||
if [ "false" = "$snapshot" ]; then
|
||||
echo "Pushing image $image_name:$latest_tag"
|
||||
docker push "$image_name:$latest_tag"
|
||||
for p in "${platforms[@]}"; do
|
||||
rm -rf $p
|
||||
done
|
||||
|
||||
# alpine doesn't provide upstream arm64 images yet
|
||||
if [[ $platform == "linux-amd64" ]]; then
|
||||
tar zxvf "/tmp/release/babashka-${image_tag}-${platform}-static.tar.gz"
|
||||
docker build -t "$image_name:alpine" -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
|
||||
# we update the version tag, even if it's a SNAPSHOT version
|
||||
echo "Pushing image $image_name:$image_tag"
|
||||
docker push "$image_name:$image_tag"
|
||||
if [[ $snapshot == "false" ]]; then
|
||||
docker push "$image_name:$image_tag-alpine"
|
||||
fi
|
||||
else
|
||||
echo "Not publishing Docker image"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ RUN apt-get update \
|
|||
&& apt-get install -y curl \
|
||||
&& mkdir -p /usr/local/bin
|
||||
|
||||
COPY bb /usr/local/bin/bb
|
||||
ARG TARGETARCH
|
||||
ARG TARGETOS
|
||||
|
||||
COPY ${TARGETOS}/${TARGETARCH}/bb /usr/local/bin/bb
|
||||
|
||||
RUN chmod +x /usr/local/bin/bb
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue