-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (46 loc) · 1.95 KB
/
Dockerfile
File metadata and controls
69 lines (46 loc) · 1.95 KB
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
69
FROM node:22-alpine AS frontend-builder
WORKDIR /app/clientapp
# Install git for getting commit hash
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.23/main' > /etc/apk/repositories && \
echo 'http://mirrors.ustc.edu.cn/alpine/v3.23/community' >> /etc/apk/repositories && \
apk update && apk add --no-cache git
COPY clientapp/package*.json ./
RUN npm ci --only=production
COPY clientapp/ ./
# Remove git dependency
# COPY .git/ .git/
# Generate version.ts with static info
RUN echo "export const A1CTF_VERSION = \"local-dev\"" > version.ts && \
echo "export const A1CTF_NAME = \"HnuCTF\"" >> version.ts && \
echo "export const BUILD_TIME = \"$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")\"" >> version.ts
RUN npm install
RUN npm run build
FROM golang:1.25.3-alpine AS backend-builder
WORKDIR /app
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.22/main' > /etc/apk/repositories && \
echo 'http://mirrors.ustc.edu.cn/alpine/v3.22/community' >> /etc/apk/repositories && \
apk update && apk add --no-cache git libwebp-dev build-base
COPY go.mod go.sum ./
ENV GOPROXY=https://goproxy.cn,direct
RUN go mod download
COPY src/ ./src/
RUN CGO_ENABLED=1 GOMAXPROCS=0 GOOS=linux go build -ldflags="-s -w" -o app src/main.go
FROM alpine:latest
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.23/main' > /etc/apk/repositories && \
echo 'http://mirrors.ustc.edu.cn/alpine/v3.23/community' >> /etc/apk/repositories && \
apk update && apk --no-cache add ca-certificates tzdata libwebp-dev
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
WORKDIR /app
RUN mkdir -p /app/data && \
mkdir -p /app/clientapp/build/client && \
chown -R appuser:appgroup /app
COPY --from=frontend-builder /app/clientapp/build/client ./clientapp/build/client
COPY --from=backend-builder /app/app ./
COPY migrations/ ./migrations/
COPY i18n/ ./i18n/
RUN chown -R appuser:appgroup /app && \
chmod +x /app/app
USER appuser
EXPOSE 7777
CMD ["./app"]