Files
wg-portal/Dockerfile
T

94 lines
3.2 KiB
Docker
Raw Normal View History

2020-11-10 09:57:49 +01:00
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
# This dockerfile uses a multi-stage build system to reduce the image footprint.
######
# Build frontend
######
2024-09-23 21:54:22 +02:00
FROM --platform=${BUILDPLATFORM} node:lts-alpine AS frontend
# Set the working directory
2020-11-10 09:57:49 +01:00
WORKDIR /build
# 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
2020-11-10 09:57:49 +01:00
######
# Build backend
######
2026-09-12 17:52:01 +02:00
FROM --platform=${BUILDPLATFORM} golang:1.27-alpine AS builder
# Set the working directory
WORKDIR /build
# Download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the sources to the working directory
2024-09-23 21:54:22 +02:00
COPY ./cmd ./cmd
COPY ./internal ./internal
# Copy the frontend build result
COPY --from=frontend /build/dist/ ./internal/app/api/core/frontend-dist/
2024-03-04 09:54:47 +01:00
# Set the build version from arguments
ARG BUILD_VERSION
# Split to cross-platform build
ARG TARGETARCH
2024-03-04 09:54:47 +01: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 09:57:49 +01:00
2024-09-23 21:54:22 +02:00
######
# Export binaries
######
FROM scratch AS binaries
COPY --from=builder /build/dist/wg-portal /
2026-11-10 23:20:12 +01:00
######
# Build the optional official AmneziaWG tools for the target architecture.
# These are diagnostic tools; the portal's native backend does not need them.
# The kernel module belongs on the host and is not built into this image.
######
FROM alpine:3.24 AS amneziawg-tools
RUN apk add --no-cache build-base linux-headers
ADD --checksum=sha256:22438f231d39ea27e4bdc69707ec3103357f3cecc9ad3eecba18a61e5b39c9b9 \
https://codeload.github.com/amnezia-vpn/amneziawg-tools/tar.gz/ee0f0a9aa34ff0a0da4b3433b9512781cfe02843 /tmp/amneziawg-tools.tar.gz
RUN mkdir /build && tar -xzf /tmp/amneziawg-tools.tar.gz -C /build --strip-components=1 \
&& make -C /build/src \
&& make -C /build/src install DESTDIR=/out PREFIX=/usr WITH_WGQUICK=yes WITH_BASHCOMPLETION=no WITH_SYSTEMDUNITS=no
######
# Final image
######
2026-11-10 23:20:12 +01:00
FROM alpine:3.24 AS runtime
2023-12-23 13:08:33 +01:00
# Install OS-level dependencies
RUN apk upgrade --no-cache
2025-09-22 18:45:41 +02:00
RUN apk add --no-cache bash curl iptables nftables openresolv wireguard-tools tzdata
2020-11-10 09:57:49 +01:00
# Setup timezone
2024-09-23 21:54:22 +02:00
ENV TZ=UTC
2021-04-08 09:23:48 +02:00
# Copy binaries
2022-11-11 17:10:41 +01:00
COPY --from=builder /build/dist/wg-portal /app/wg-portal
2020-11-10 09:57:49 +01:00
# Set the Current Working Directory inside the container
WORKDIR /app
2024-09-29 22:10:50 +02:00
# Expose default ports for metrics, web and wireguard
EXPOSE 8787/tcp
2023-10-26 12:42:18 +02:00
EXPOSE 8888/tcp
2024-09-29 22:10:50 +02:00
EXPOSE 51820/udp
2023-10-26 12:42:18 +02:00
# the database and config file can be mounted from the host
VOLUME [ "/app/data", "/app/config" ]
2020-11-10 09:57:49 +01:00
# Command to run the executable
2023-12-23 13:08:33 +01:00
ENTRYPOINT [ "/app/wg-portal" ]
2026-11-10 23:20:12 +01:00
# Optional image, built with --target amneziawg and published as *-amneziawg.
FROM runtime AS amneziawg
RUN apk add --no-cache iproute2
COPY --from=amneziawg-tools /out/usr/bin/awg /usr/bin/awg
COPY --from=amneziawg-tools /out/usr/bin/awg-quick /usr/bin/awg-quick
COPY --from=amneziawg-tools /build/COPYING /usr/share/licenses/amneziawg-tools/COPYING
# Keep the default image and its dependencies unchanged.
FROM runtime AS standard