-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
68 lines (50 loc) · 1.84 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# syntax=docker/dockerfile:1
# Build Backend
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine3.19 as builder
LABEL org.opencontainers.image.title="Minetest Skin Server"
LABEL org.opencontainers.image.description="Skin server for the Minetest engine"
LABEL org.opencontainers.image.authors="AFCM <afcm.contact@gmail.com>"
LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.source="https://github.com/AFCMS/minetest-skin-server"
ARG TARGETOS
ARG TARGETARCH
ENV GOCACHE=/root/.cache/go-build
# Install build dependencies
RUN apk add --no-cache git make build-base
WORKDIR /app
# Download Go modules
COPY go.mod go.sum ./
RUN --mount=type=cache,id=gomod,target="/go/pkg/mod" go mod download
RUN --mount=type=cache,id=gomod,target="/go/pkg/mod" go mod verify
COPY . ./
# Build with cache
# https://dev.to/jacktt/20x-faster-golang-docker-builds-289n
RUN --mount=type=cache,id=gomod,target="/go/pkg/mod" \
--mount=type=cache,id=gobuild,target="/root/.cache/go-build" \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o minetest-skin-server .
# Build Frontend
FROM --platform=$BUILDPLATFORM node:20-alpine3.19 as frontend-builder
WORKDIR /frontend
COPY ./frontend/package.json ./
COPY ./frontend/package-lock.json ./
RUN --mount=type=cache,id=npmmod,target="/root/.npm" npm ci
COPY ./frontend ./
RUN npm run build
# Production Image
FROM alpine:3.19 as production
RUN apk update && apk add --no-cache optipng
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "10001" \
"appuser"
COPY --from=builder /app/minetest-skin-server /app/
COPY --from=builder /app/index.gohtml /app/
COPY --from=frontend-builder /frontend/dist /app/frontend/dist
USER appuser:appuser
WORKDIR /app
EXPOSE 8080
CMD ["/app/minetest-skin-server"]