From ed912eaed2e05383e863d7b9bddb440dea2c3f35 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Fri, 22 Mar 2024 16:59:29 +0300 Subject: [PATCH] Simplify build script in Docker --- docker/Dockerfile | 4 ++-- docker/build.sh | 39 +++++---------------------------------- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 48247984..0aa88a42 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,8 +2,8 @@ ARG BASE_IMAGE_VERSION="v3.9.0" FROM darthsim/imgproxy-base:${BASE_IMAGE_VERSION} -ARG BUILDPLATFORM -ARG TARGETPLATFORM +ARG TARGETARCH +ARG BUILDARCH COPY . . RUN docker/build.sh diff --git a/docker/build.sh b/docker/build.sh index 239f5d8d..e761a070 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -3,50 +3,21 @@ set -e # This is pretty dirty hack. Building imgproxy under Qemu is pretty slow. -# So we install Go binary native for the BUILDPLATFORM. -if [[ $BUILDPLATFORM != $TARGETPLATFORM ]]; then - case "$BUILDPLATFORM" in - amd64 | "linux/amd64") - BUILD_ARCH="amd64" - ;; - - arm64 | "arm64/v8" | "linux/arm64" | "linux/arm64/v8") - BUILD_ARCH="arm64" - ;; - - *) - echo "Unknown platform: $BUILDPLATFORM" - exit 1 - esac - - case "$TARGETPLATFORM" in - amd64 | "linux/amd64") - TARGET_ARCH="amd64" - ;; - - arm64 | "arm64/v8" | "linux/arm64" | "linux/arm64/v8") - TARGET_ARCH="arm64" - ;; - - *) - echo "Unknown platform: $TARGETPLATFORM" - exit 1 - esac - +# So we install Go binary native for the BUILDARCH. +if [[ $BUILDARCH != $TARGETARCH ]]; then GOLANG_VERSION=$(go version | sed -E 's/.*go([0-9]+\.[0-9]+(\.[0-9]+)?).*/\1/') rm -rf /usr/local/go - dpkg --add-architecture ${BUILD_ARCH} apt-get update - apt-get install -y --no-install-recommends libstdc++6:${BUILD_ARCH} + apt-get install -y --no-install-recommends libstdc++6:${BUILDARCH} - curl -Ls https://golang.org/dl/go${GOLANG_VERSION}.linux-${BUILD_ARCH}.tar.gz \ + curl -Ls https://golang.org/dl/go${GOLANG_VERSION}.linux-${BUILDARCH}.tar.gz \ | tar -xzC /usr/local export CGO_ENABLED=1 export GOOS=linux - export GOARCH=$TARGET_ARCH + export GOARCH=$TARGETARCH fi go build -v -ldflags "-s -w" -o /usr/local/bin/imgproxy