From fc348bf395e0c56787aa0fe587275adf2f04c40b Mon Sep 17 00:00:00 2001 From: Nguyen Nhu Viet Date: Thu, 19 Oct 2023 22:14:42 +0200 Subject: [PATCH] chore: fix multiplatform builds (#2725) ## Overview This PR fixes the mismatch of architectures in build stages Same can happen in app like it happened for node Ref: - https://github.com/celestiaorg/celestia-node/pull/2862 - https://github.com/celestiaorg/devops/issues/527 ## Checklist - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords --- Dockerfile | 12 ++++++++++-- docker/Dockerfile_txsim | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b9c7424bc..1c3640e375 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,11 @@ # stage 1 Generate celestia-appd Binary FROM --platform=$BUILDPLATFORM docker.io/golang:1.21.3-alpine3.18 as builder + +ARG TARGETOS +ARG TARGETARCH + +ENV CGO_ENABLED=0 +ENV GO111MODULE=on # hadolint ignore=DL3018 RUN apk update && apk add --no-cache \ gcc \ @@ -10,10 +16,12 @@ RUN apk update && apk add --no-cache \ musl-dev COPY . /celestia-app WORKDIR /celestia-app -RUN make build +RUN uname -a &&\ + CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + make build # stage 2 -FROM --platform=$BUILDPLATFORM docker.io/alpine:3.18.4 +FROM docker.io/alpine:3.18.4 # Read here why UID 10001: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000 ARG UID=10001 diff --git a/docker/Dockerfile_txsim b/docker/Dockerfile_txsim index 8e14835e09..9126f9d37d 100644 --- a/docker/Dockerfile_txsim +++ b/docker/Dockerfile_txsim @@ -1,5 +1,11 @@ # Stage 1: generate celestia-appd binary FROM --platform=$BUILDPLATFORM docker.io/golang:1.21.3-alpine3.18 as builder + +ARG TARGETOS +ARG TARGETARCH + +ENV CGO_ENABLED=0 +ENV GO111MODULE=on # hadolint ignore=DL3018 RUN apk update && apk add --no-cache \ gcc \ @@ -12,10 +18,12 @@ COPY . /celestia-app WORKDIR /celestia-app # we need the celestia-appd build as we might want to create an account # internally for txsimulation -RUN make build && make txsim-build +RUN uname -a &&\ + CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + make build && make txsim-build # Stage 2: create a minimal image with the binary -FROM --platform=$BUILDPLATFORM docker.io/alpine:3.18.4 +FROM docker.io/alpine:3.18.4 # Use UID 10,001 because UIDs below 10,000 are a security risk. # Ref: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000