Skip to content

Commit

Permalink
multistage build
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben Youssef committed Jan 10, 2024
1 parent 6a03566 commit 9a21375
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/emulator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ COPY . .

ARG TARGETOS
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ] ; then \
--mount=type=ssh \

FROM base AS build-amd64-target
RUN --mount=type=ssh \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GO111MODULE=on CGO_ENABLED=1 GOOS=$TARGETOS \
GOARCH=$TARGETARCH CC=arm-linux-gnueabi-gcc \
go build -ldflags "-extldflags -static" -o ./app ./cmd/emulator ; \
elif [ "$TARGETARCH" = "amd64" ] ; then \
--mount=type=ssh \
GOARCH=$TARGETARCH CC=arm-gcc \
go build -ldflags "-extldflags -static" -o ./app ./cmd/emulator

FROM base AS build-arm64-target
RUN --mount=type=ssh \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GO111MODULE=on CGO_ENABLED=1 GOOS=$TARGETOS \
GOARCH=$TARGETARCH CC=gcc \
go build -ldflags "-extldflags -static" -o ./app ./cmd/emulator ; \
fi
GOARCH=$TARGETARCH CC=arm-linux-gnueabi-gcc \
go build -ldflags "-extldflags -static" -o ./app ./cmd/emulator

FROM build-${TARGETARCH}-target AS final

## Add the binary to a fresh distroless image
FROM gcr.io/distroless/static
Expand Down

0 comments on commit 9a21375

Please # to comment.