-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.danmaku
More file actions
98 lines (78 loc) · 3.63 KB
/
Dockerfile.danmaku
File metadata and controls
98 lines (78 loc) · 3.63 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Gobup All-in-One Container with DanmakuFactory - Frontend Embedded Build
# Stage 1: Build Frontend
FROM node:20-slim AS frontend-builder
ARG TARGETARCH
WORKDIR /app/web
COPY web/package*.json ./
RUN npm ci --include=optional
RUN if [ "$TARGETARCH" = "amd64" ]; then \
npm install --no-save @rollup/rollup-linux-x64-gnu; \
elif [ "$TARGETARCH" = "arm64" ]; then \
npm install --no-save @rollup/rollup-linux-arm64-gnu; \
fi
COPY web/ ./
RUN npm run build
# Stage 2: Build DanmakuFactory
FROM alpine:latest AS danmaku-builder
ARG TARGETARCH
# Install build dependencies for DanmakuFactory (包括 bash,xmake 安装脚本需要)
RUN apk add --no-cache git build-base curl tar bash p7zip cmake linux-headers
# Install xmake (仅在预编译版本下载失败时需要)
RUN curl -fsSL https://xmake.io/shget.text | bash && \
ln -s /root/.local/bin/xmake /usr/local/bin/xmake
# Download or build DanmakuFactory (优先使用预编译版本)
WORKDIR /build
RUN ARCH_NAME=$([ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "arm64") && \
RELEASE_URL="https://github.com/hihkm/DanmakuFactory/releases/download/dev/DanmakuFactory-linux-${ARCH_NAME}.tar.gz" && \
echo "Attempting to download prebuilt DanmakuFactory for ${ARCH_NAME}..." && \
mkdir -p /danmakufactory && \
if curl -fsSL "$RELEASE_URL" -o danmaku.tar.gz && tar -xzf danmaku.tar.gz -C /danmakufactory --strip-components=1 && test -f /danmakufactory/DanmakuFactory; then \
echo "Successfully downloaded prebuilt DanmakuFactory" && \
chmod +x /danmakufactory/DanmakuFactory && \
ls -lh /danmakufactory/; \
else \
echo "Prebuilt version not available, building from source..." && \
git clone --depth=1 https://github.com/hihkm/DanmakuFactory.git && \
cd DanmakuFactory && \
xmake build -y -v --root && \
find build -name DanmakuFactory -type f -executable -exec cp {} /danmakufactory/ \; && \
ls -lh /danmakufactory/ && \
test -f /danmakufactory/DanmakuFactory && echo "DanmakuFactory built successfully from source"; \
fi
# Stage 3: Build Backend with Embedded Frontend
FROM golang:1.24-alpine AS backend-builder
ARG TARGETARCH
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git ca-certificates build-base sqlite-dev
# Copy backend source
COPY server/ ./server/
# Copy frontend dist to embed location
COPY --from=frontend-builder /app/web/dist ./server/internal/routes/dist
# Build backend with embed tag
WORKDIR /app/server
RUN go mod download
RUN CGO_ENABLED=1 GOOS=linux GOARCH=${TARGETARCH} go build -tags embed -a -installsuffix cgo -ldflags "-w -s" -o gobup .
# Stage 4: Final Runtime Image with DanmakuFactory
FROM alpine:latest
ARG TARGETARCH
# Install runtime dependencies (DanmakuFactory 是 C 语言编译的,只需要基础运行库)
RUN apk add --no-cache ca-certificates tzdata sqlite ffmpeg libstdc++ libgcc wget fontconfig font-wqy-zenhei
# Copy compiled DanmakuFactory from builder stage
COPY --from=danmaku-builder /danmakufactory/DanmakuFactory /usr/local/bin/danmakufactory/DanmakuFactory
RUN chmod +x /usr/local/bin/danmakufactory/DanmakuFactory
ENV TZ=Asia/Shanghai
ENV DANMAKU_FACTORY_PATH=/usr/local/bin/danmakufactory/DanmakuFactory
WORKDIR /app
# Create necessary directories
RUN mkdir -p /rec /app/data
# Copy binary with embedded frontend
COPY --from=backend-builder /app/server/gobup ./gobup
# Set permissions
RUN chmod +x ./gobup
EXPOSE 12380
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:12380/api/health || exit 1
# Run the application
CMD ["./gobup"]