Browse Source

Another try to fix crossbuild of Docker images

DarthSim 10 months ago
parent
commit
6e4967a278
2 changed files with 20 additions and 29 deletions
  1. 20 5
      docker/Dockerfile
  2. 0 24
      docker/build.sh

+ 20 - 5
docker/Dockerfile

@@ -1,12 +1,27 @@
 ARG BASE_IMAGE_VERSION="v3.10.0"
 
-FROM darthsim/imgproxy-base:${BASE_IMAGE_VERSION}
+FROM --platform=${BUILDPLATFORM} darthsim/imgproxy-base:${BASE_IMAGE_VERSION} as base-native
+
+FROM darthsim/imgproxy-base:${BASE_IMAGE_VERSION} as build
 
-ARG TARGETARCH
 ARG BUILDARCH
+ARG TARGETARCH
+
+RUN dpkg --add-architecture ${BUILDARCH} \
+  && apt-get update \
+  && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libstdc++6:${BUILDARCH}
+
+# This is pretty dirty hack. Building imgproxy under Qemu is pretty slow.
+# So we install Go binary native for the BUILDARCH.
+RUN rm -rf /usr/local/go
+COPY --from=base-native /usr/local/go /usr/local/go
+
+ENV CGO_ENABLED=1
+ENV GOOS=linux
+ENV GOARCH=$TARGETARCH
 
 COPY . .
-RUN docker/build.sh
+RUN bash -c 'go build -v -ldflags "-s -w" -o /usr/local/bin/imgproxy'
 
 # ==================================================================================================
 # Final image
@@ -31,8 +46,8 @@ RUN apt-get update \
   && ln -s /usr/lib/$(uname -m)-linux-gnu/libtcmalloc_minimal.so.4 /usr/local/lib/libtcmalloc_minimal.so \
   && rm -rf /var/lib/apt/lists/*
 
-COPY --from=0 /usr/local/bin/imgproxy /usr/local/bin/
-COPY --from=0 /usr/local/lib /usr/local/lib
+COPY --from=build /usr/local/bin/imgproxy /usr/local/bin/
+COPY --from=build /usr/local/lib /usr/local/lib
 
 COPY docker/entrypoint.sh /usr/local/bin/
 

+ 0 - 24
docker/build.sh

@@ -1,24 +0,0 @@
-#!/bin/bash
-
-set -e
-
-# This is pretty dirty hack. Building imgproxy under Qemu is pretty slow.
-# 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 ${BUILDARCH}
-  apt-get update
-  apt-get install -y --no-install-recommends libstdc++6:${BUILDARCH}
-
-  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=$TARGETARCH
-fi
-
-go build -v -ldflags "-s -w" -o /usr/local/bin/imgproxy