Skip to content

Commit

Permalink
use cross compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Apr 29, 2023
1 parent 8b61d35 commit 3bb5d86
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
FROM golang:1.19-alpine as gobuild
# Golang can cross-compile
FROM --platform=$BUILDPLATFORM golang:1.19-alpine as gobuild

WORKDIR /build
ADD go.mod go.sum /build/
RUN go mod download -x
ADD cmd /build/cmd
ADD pkg /build/pkg
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o ./s3driver ./cmd/s3driver

FROM alpine:3.17 AS downloader
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -ldflags '-extldflags "-static"' -o ./s3driver ./cmd/s3driver

FROM --platform=$BUILDPLATFORM alpine:3.17 AS downloader

WORKDIR /work

RUN apk add --no-cache curl

ARG TARGETPLATFORM
RUN ARCH=$(echo $TARGETPLATFORM | sed -e 's/^linux\///g') && \
curl https://github.com/yandex-cloud/geesefs/releases/latest/download/geesefs-linux-$ARCH -LfSso /work/geesefs
ARG TARGETOS
ARG TARGETARCH
RUN curl https://github.com/yandex-cloud/geesefs/releases/latest/download/geesefs-$TARGETOS-$TARGETARCH -LfSso /work/geesefs

FROM alpine:3.17
LABEL maintainers="Vitaliy Filippov <[email protected]>"
Expand Down

0 comments on commit 3bb5d86

Please sign in to comment.