Build arm64 docker image in CI (#1099)

This commit is contained in:
Wes Morgan 2021-12-15 08:28:39 -07:00 committed by GitHub
parent 48a8f3ac18
commit bc0ae17e64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 36 deletions

View file

@ -3,6 +3,14 @@
# Check https://circleci.com/docs/2.0/language-clojure/ for more details # Check https://circleci.com/docs/2.0/language-clojure/ for more details
# #
version: 2.1 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: jobs:
jvm: jvm:
docker: docker:
@ -35,10 +43,6 @@ jobs:
export BABASHKA_FEATURE_POSTGRESQL=true export BABASHKA_FEATURE_POSTGRESQL=true
script/test script/test
script/run_lib_tests script/run_lib_tests
# - run:
# name: Run as tools.deps dependency
# command: |
# .circleci/script/tools.deps
- run: - run:
name: Run as lein command name: Run as lein command
command: | command: |
@ -229,14 +233,6 @@ jobs:
command: | command: |
git submodule init git submodule init
git submodule update git submodule update
- run:
name: "Short circuit on SNAPSHOT"
command: |
VERSION=$(cat resources/BABASHKA_VERSION)
if [[ "$VERSION" == *-SNAPSHOT ]]
then
circleci task halt
fi
- run: - run:
name: Install Clojure name: Install Clojure
command: | command: |
@ -449,16 +445,17 @@ jobs:
- ~/.m2 - ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }} key: v1-dependencies-{{ checksum "project.clj" }}
docker: docker:
docker: machine:
- image: circleci/buildpack-deps:bullseye image: ubuntu-2004:202111-01
steps: steps:
- checkout - checkout
- setup-docker-buildx
- attach_workspace: - attach_workspace:
at: /tmp at: /tmp
- setup_remote_docker:
version: 19.03.12
- run: - run:
name: Build Docker image name: Build Docker image
environment:
PLATFORM: linux/amd64,linux/arm64
command: .circleci/script/docker command: .circleci/script/docker
workflows: workflows:
@ -482,7 +479,9 @@ workflows:
- docker: - docker:
filters: filters:
branches: branches:
only: master only:
- master
requires: requires:
- linux - linux
- linux-static - linux-static
- linux-aarch64

View file

@ -4,6 +4,7 @@ set -eo pipefail
image_name="babashka/babashka" image_name="babashka/babashka"
image_tag=$(cat resources/BABASHKA_VERSION) image_tag=$(cat resources/BABASHKA_VERSION)
platform=${PLATFORM:-"linux/amd64"}
latest_tag="latest" latest_tag="latest"
if [[ $image_tag =~ SNAPSHOT$ ]]; then if [[ $image_tag =~ SNAPSHOT$ ]]; then
@ -15,29 +16,36 @@ else
fi fi
if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]; then 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 echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
tar zxvf "/tmp/release/babashka-${image_tag}-linux-amd64.tar.gz" IFS=',' read -r -a platforms <<< "$platform"
docker build -t "$image_name" -f Dockerfile.ci . for p in "${platforms[@]}"; do
docker tag "$image_name:$latest_tag" "$image_name:$image_tag" tarball_platform=${p//\//-}
rm -f bb 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 if [[ $snapshot == "false" ]]; then
tar zxvf "/tmp/release/babashka-${image_tag}-linux-amd64-static.tar.gz" echo "Building & pushing $platform Docker image(s) $image_name:$latest_tag"
docker build -t "$image_name:alpine" -f Dockerfile.alpine . docker buildx build -t "$image_name:$latest_tag" --platform "$platform" --push -f Dockerfile.ci .
docker tag "$image_name:alpine" "$image_name:$image_tag-alpine"
fi fi
# we only update latest when it's not a SNAPSHOT version for p in "${platforms[@]}"; do
if [ "false" = "$snapshot" ]; then rm -rf $p
echo "Pushing image $image_name:$latest_tag" done
docker push "$image_name:$latest_tag"
# 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" echo "Pushing image $image_name:alpine"
docker push "$image_name:alpine" docker push "$image_name:alpine"
fi 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 fi
else else
echo "Not publishing Docker image" echo "Not publishing Docker image"

View file

@ -4,7 +4,10 @@ RUN apt-get update \
&& apt-get install -y curl \ && apt-get install -y curl \
&& mkdir -p /usr/local/bin && 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 RUN chmod +x /usr/local/bin/bb