Skip to content

Commit

Permalink
docker: Multiplatform cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Sep 11, 2023
1 parent a6219a0 commit 6d572b3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM golang:1.20-alpine3.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.18 as builder
WORKDIR $GOPATH/src/go.k6.io/k6
COPY . .
ARG TARGETOS TARGETARCH
RUN apk --no-cache add git=~2
RUN CGO_ENABLED=0 go install -a -trimpath -ldflags "-s -w -X go.k6.io/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --tags --always --long --dirty)"
RUN --mount=target=.,readonly \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -trimpath -o /usr/bin/k6

# Runtime stage
FROM alpine:3.18 as release

# hadolint ignore=DL3018
RUN apk add --no-cache ca-certificates && \
adduser -D -u 12345 -g 12345 k6
COPY --from=builder /go/bin/k6 /usr/bin/k6
COPY --from=builder /usr/bin/k6 /usr/bin/k6

USER k6
WORKDIR /home/k6
Expand Down

0 comments on commit 6d572b3

Please sign in to comment.