Skip to content

Commit

Permalink
fix: cross system compiling fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Apr 28, 2024
1 parent 5057c56 commit 6e61c9e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# build stage
FROM --platform=$BUILDPLATFORM golang:1.21.6-bookworm AS build-env
ENV CGO_ENABLED=0
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN echo "Building for ${TARGETOS} ${TARGETARCH}"
RUN echo "Building for ${BUILDPLATFORM}"
RUN echo "Building for ${TARGETPLATFORM}"
WORKDIR /src
COPY . .
RUN go build -o goapp .
RUN echo "Building for ${TARGETOS} ${TARGETARCH}"
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=7 go build -ldflags="-w -s" -o goapp .

# final stage
FROM --platform=$BUILDPLATFORM debian:bookworm
FROM --platform=$TARGETPLATFORM debian:bookworm
RUN mkdir /app
RUN mkdir /data
WORKDIR /app
COPY --from=build-env /src/goapp /app/goapp
RUN chmod +x /app/goapp
RUN apt-get update -y && apt-get install -y ca-certificates
ENTRYPOINT bash
ENTRYPOINT /app/goapp

0 comments on commit 6e61c9e

Please sign in to comment.