2020-11-10 08:57:49 +00:00
|
|
|
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
|
|
|
|
# This dockerfile uses a multi-stage build system to reduce the image footprint.
|
|
|
|
|
2024-03-04 08:32:47 +00:00
|
|
|
######
|
|
|
|
# Build frontend
|
|
|
|
######
|
|
|
|
FROM --platform=${BUILDPLATFORM} node:lts-alpine as frontend
|
|
|
|
# Set the working directory
|
2020-11-10 08:57:49 +00:00
|
|
|
WORKDIR /build
|
2024-03-04 08:32:47 +00:00
|
|
|
# Download dependencies
|
|
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
|
|
RUN npm ci
|
|
|
|
# Set dist output directory
|
|
|
|
ENV DIST_OUT_DIR="dist"
|
|
|
|
# Copy the sources to the working directory
|
|
|
|
COPY frontend .
|
|
|
|
# Build the frontend
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
|
######
|
|
|
|
# Build backend
|
|
|
|
######
|
2024-04-29 21:28:32 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} golang:1.22-alpine as builder
|
2024-03-04 08:32:47 +00:00
|
|
|
# Set the working directory
|
|
|
|
WORKDIR /build
|
|
|
|
# Download dependencies
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
# Copy the sources to the working directory
|
|
|
|
COPY . .
|
|
|
|
# Copy the frontend build result
|
|
|
|
COPY --from=frontend /build/dist/ ./internal/app/api/core/frontend-dist/
|
2024-03-04 08:54:47 +00:00
|
|
|
# Set the build version from arguments
|
|
|
|
ARG BUILD_VERSION
|
2024-03-04 08:32:47 +00:00
|
|
|
# Split to cross-platform build
|
|
|
|
ARG TARGETARCH
|
2024-03-04 08:54:47 +00:00
|
|
|
# Build the application
|
|
|
|
RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} go build -o /build/dist/wg-portal \
|
|
|
|
-ldflags "-w -s -extldflags '-static' -X 'github.com/h44z/wg-portal/internal.Version=${BUILD_VERSION}'" \
|
|
|
|
-tags netgo \
|
|
|
|
cmd/wg-portal/main.go
|
2020-11-10 08:57:49 +00:00
|
|
|
|
2024-03-04 08:32:47 +00:00
|
|
|
######
|
|
|
|
# Final image
|
|
|
|
######
|
2023-12-23 12:08:33 +00:00
|
|
|
FROM alpine:3.19
|
|
|
|
# Install OS-level dependencies
|
2024-03-04 10:10:09 +00:00
|
|
|
RUN apk add --no-cache bash curl iptables nftables openresolv
|
2020-11-10 08:57:49 +00:00
|
|
|
# Setup timezone
|
|
|
|
ENV TZ=Europe/Vienna
|
2021-04-08 07:23:48 +00:00
|
|
|
# Copy binaries
|
2022-11-11 16:10:41 +00:00
|
|
|
COPY --from=builder /build/dist/wg-portal /app/wg-portal
|
2020-11-10 08:57:49 +00:00
|
|
|
# Set the Current Working Directory inside the container
|
|
|
|
WORKDIR /app
|
2023-10-26 10:42:18 +00:00
|
|
|
# by default, the web-portal is reachable on port 8888
|
|
|
|
EXPOSE 8888/tcp
|
|
|
|
# the database and config file can be mounted from the host
|
|
|
|
VOLUME [ "/app/data", "/app/config" ]
|
2020-11-10 08:57:49 +00:00
|
|
|
# Command to run the executable
|
2023-12-23 12:08:33 +00:00
|
|
|
ENTRYPOINT [ "/app/wg-portal" ]
|