Skip to content

Commit

Permalink
CI: fix choosing alpine image architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
nixargh committed Sep 4, 2024
1 parent 15a6578 commit ce57ad3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
5 changes: 4 additions & 1 deletion docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ RUN apk --no-cache add g++ git make curl bash tree
# Required by the built script for setting verion and cross-compiling.
ARG VERSION
ENV VERSION=${VERSION}

ARG ARCH
ENV GOARCH=${ARCH}

ARG ALPINE_ARCH

# Compile.
WORKDIR /src
COPY . .
Expand All @@ -24,7 +27,7 @@ RUN ./scripts/build/bin/build-raw.sh
# ${ARCH} specific architecture.
# To make portable our building process we base our final image on that same architecture as the binary
# to obtain a resulting ${ARCH} image independently where we are building this image.
FROM ${ARCH}/alpine:3
FROM ${ALPINE_ARCH}/alpine:3

COPY --from=build-stage /src/bin/sloth /usr/local/bin/sloth

Expand Down
31 changes: 23 additions & 8 deletions scripts/build/docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

set -e


[ -z "$VERSION" ] && echo "VERSION env var is required." && exit 1;
[ -z "$IMAGE" ] && echo "IMAGE env var is required." && exit 1;
[ -z "$DOCKER_FILE_PATH" ] && echo "DOCKER_FILE_PATH env var is required." && exit 1;
[ -z "$VERSION" ] && echo "VERSION env var is required." && exit 1
[ -z "$IMAGE" ] && echo "IMAGE env var is required." && exit 1
[ -z "$DOCKER_FILE_PATH" ] && echo "DOCKER_FILE_PATH env var is required." && exit 1

# By default use amd64 architecture.
DEF_ARCH=amd64
ARCH=${ARCH:-$DEF_ARCH}

IMAGE_TAG_ARCH="${IMAGE}:${VERSION}-${ARCH}"

# Guess Alpine image arch. Take the same as $ARCH by default.
case $ARCH in
arm64)
ALPINE_ARCH="arm64v8"
;;

arm)
ALPINE_ARCH="arm32v7"
;;

*)
ALPINE_ARCH="${ARCH}"
;;
esac

# Build image.
echo "Building image ${IMAGE_TAG_ARCH}..."
docker build \
--build-arg VERSION="${VERSION}" \
--build-arg ARCH="${ARCH}" \
-t "${IMAGE_TAG_ARCH}" \
-f "${DOCKER_FILE_PATH}" .
--build-arg VERSION="${VERSION}" \
--build-arg ARCH="${ARCH}" \
--build-arg ALPINE_ARCH="${ALPINE_ARCH}" \
-t "${IMAGE_TAG_ARCH}" \
-f "${DOCKER_FILE_PATH}" .

0 comments on commit ce57ad3

Please sign in to comment.