use cross compiling

This commit is contained in:
motoki317 2023-04-22 12:24:02 +09:00
parent 6144c909a7
commit 7bea0a8dcf
No known key found for this signature in database
GPG key ID: EEFEAE0FAA3D3FC9

View file

@ -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 WORKDIR /build
ADD go.mod go.sum /build/ ADD go.mod go.sum /build/
RUN go mod download -x RUN go mod download -x
ADD cmd /build/cmd ADD cmd /build/cmd
ADD pkg /build/pkg 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 WORKDIR /work
RUN apk add --no-cache curl RUN apk add --no-cache curl
ARG TARGETPLATFORM ARG TARGETOS
RUN ARCH=$(echo $TARGETPLATFORM | sed -e 's/^linux\///g') && \ ARG TARGETARCH
curl https://github.com/yandex-cloud/geesefs/releases/latest/download/geesefs-linux-$ARCH -LfSso /work/geesefs RUN curl https://github.com/yandex-cloud/geesefs/releases/latest/download/geesefs-$TARGETOS-$TARGETARCH -LfSso /work/geesefs
FROM alpine:3.17 FROM alpine:3.17
LABEL maintainers="Vitaliy Filippov <vitalif@yourcmc.ru>" LABEL maintainers="Vitaliy Filippov <vitalif@yourcmc.ru>"