diff --git a/Dockerfile.j2 b/Dockerfile.j2 index 57e713e..1c7d0bd 100644 --- a/Dockerfile.j2 +++ b/Dockerfile.j2 @@ -1,3 +1,14 @@ +{% if ARCH == "arm" %} +FROM golang:1.13 as builder + +RUN set -x \ + && cd /opt \ + && git clone https://github.com/minio/mc -b {{ VERSION }} \ + && cd /opt/mc \ + && GOOS=linux GOARCH=arm64 go build -tags kqueue -o /usr/bin/mc \ + && test -f /usr/bin/mc +{% endif %} + FROM {{ IMAGE }} LABEL maintainer="RiotKit" \ @@ -33,14 +44,17 @@ ENV SOURCE_URL=http://primary.backups.example.org \ COPY bin/*.sh / {% if ARCH == "arm" %} +COPY --from=builder /usr/bin/mc /usr/bin/mc + RUN [ "cross-build-start" ] {% endif %} RUN apk add --update bash sed \ && addgroup -g 1050 mirroring_comrade \ && adduser -D -u 1050 -G mirroring_comrade mirroring_comrade \ - && chmod +x /*.sh \ + && chmod +x /*.sh {% if ARCH != "arm" %}\ && /download_minio_version.sh {{ VERSION }} + {% endif %} {% if ARCH == "arm" %} RUN [ "cross-build-end" ] diff --git a/Makefile b/Makefile index 250cdd0..49b1fea 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ build_x86_64: ## Build x86-64 image (args: VERSION) make generate_dockerfile _build ARCH=x86_64 IMAGE=alpine:3.9 VERSION=${VERSION} PUSH=${PUSH} build_arm: ## Build ARM image (args: VERSION) - make generate_dockerfile _build ARCH=arm IMAGE=balenalib/armv7hf-alpine:3.9 VERSION=${VERSION} PUSH=${PUSH} + make generate_dockerfile _build ARCH=arm IMAGE=balenalib/aarch64-alpine:3.9 VERSION=${VERSION} PUSH=${PUSH} _build: ${SUDO} docker build . -f ./Dockerfile -t quay.io/riotkit/riot-mc-mirror:${VERSION}-${ARCH} diff --git a/bin/download_minio_version.sh b/bin/download_minio_version.sh index 12958c3..b1d6084 100644 --- a/bin/download_minio_version.sh +++ b/bin/download_minio_version.sh @@ -1,6 +1,22 @@ #!/bin/bash +set -e + VERSION=$1 +ARCH=$2 + +if [[ $ARCH == "arm" ]]; then + echo " >> Compiling form ARM" + + cd /tmp + git clone https://github.com/minio/mc.git -b $VERSION + cd mc + GOOS=linux GOARCH=arm64 go build -tags kqueue -o /usr/bin/mc + chmod +x /usr/bin/mc + rm -rf /tmp/mc + + exit 0 +fi echo " >> Downloading Minio Client in version '${VERSION}'" wget "https://dl.minio.io/client/mc/release/linux-amd64/mc.${VERSION}" -O /usr/bin/mc || wget "https://dl.minio.io/client/mc/release/linux-amd64/archive/mc.${VERSION}" -O /usr/bin/mc || exit 1