0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2025-04-02 16:46:52 +00:00

Revert Dockerfile and enable cross-compilation

This commit is contained in:
Dmytro Bondar 2023-10-25 15:24:57 +02:00
parent cafa72d864
commit dd6a2cc39e
No known key found for this signature in database
GPG Key ID: 8CC54FADB0C40187

View File

@ -1,31 +1,31 @@
### Back-End ### Back-End
FROM golang:alpine AS go-base FROM --platform=${BUILDPLATFORM} golang:alpine AS build-back
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
WORKDIR /app WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download

FROM go-base AS build-back
ARG COMMIT="N/A" ARG COMMIT="N/A"
COPY . . RUN --mount=type=bind,source=go.sum,target=go.sum \
RUN go install -ldflags "-w -s -X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT::7}'" ./cmd/... --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 ### Front-End
FROM node:18-alpine AS node-base FROM --platform=${BUILDPLATFORM} node:18-alpine AS build-front
WORKDIR /app WORKDIR /app
COPY ui/package.json ui/package-lock.json ./ COPY ui/package.json ui/package-lock.json ./
RUN npm ci --no-fund RUN npm ci --no-fund

COPY ui/ ./
FROM node-base AS build-front
COPY ui/ .
RUN npm run build RUN npm run build


### Final FROM alpine
FROM alpine AS final-base
RUN apk add -U --no-cache ca-certificates RUN apk add -U --no-cache ca-certificates
WORKDIR /app WORKDIR /app
COPY .env . 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 COPY --from=build-front /app/dist ./ui/dist
RUN chmod +x ./wg-gen-web RUN chmod +x ./wg-gen-web
EXPOSE 8080 EXPOSE 8080