From dd6a2cc39e3513845a55d321b9180b86e3fd4426 Mon Sep 17 00:00:00 2001 From: Dmytro Bondar Date: Wed, 25 Oct 2023 15:24:57 +0200 Subject: [PATCH] Revert Dockerfile and enable cross-compilation --- Dockerfile | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5c7724c..49b0b21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,31 @@ ### Back-End -FROM golang:alpine AS go-base +FROM --platform=${BUILDPLATFORM} golang:alpine AS build-back ENV CGO_ENABLED=0 WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download - -FROM go-base AS build-back ARG COMMIT="N/A" -COPY . . -RUN go install -ldflags "-w -s -X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT::7}'" ./cmd/... +RUN --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + --mount=type=cache,target=/go/pkg \ + go mod download +ARG TARGETARCH TARGETOS +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -o /out/wg-gen-web -ldflags "-w -s -X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT::7}'" ./cmd/wg-gen-web ### Front-End -FROM node:18-alpine AS node-base +FROM --platform=${BUILDPLATFORM} node:18-alpine AS build-front WORKDIR /app COPY ui/package.json ui/package-lock.json ./ RUN npm ci --no-fund - -FROM node-base AS build-front -COPY ui/ . +COPY ui/ ./ RUN npm run build -### Final -FROM alpine AS final-base +FROM alpine RUN apk add -U --no-cache ca-certificates WORKDIR /app COPY .env . -COPY --from=build-back /go/bin/wg-gen-web . +COPY --from=build-back /out/wg-gen-web . COPY --from=build-front /app/dist ./ui/dist RUN chmod +x ./wg-gen-web EXPOSE 8080