-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.hybrid
More file actions
89 lines (69 loc) · 2.29 KB
/
Copy pathDockerfile.hybrid
File metadata and controls
89 lines (69 loc) · 2.29 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
# file: Dockerfile.hybrid
# Hybrid approach: Install Node.js in Go builder for go generate compatibility
# Stage 1: Node.js build stage (can be cached separately)
FROM node:25-bookworm AS node-builder
WORKDIR /src/webui
# Copy package files first for better caching
COPY webui/package*.json ./
RUN npm ci --legacy-peer-deps --production=false
# Copy source and build
COPY webui/ ./
RUN npm run build
# Stage 2: Go build stage with Node.js for go generate
FROM golang:1.26.0-bookworm AS go-builder
WORKDIR /src
# Install build dependencies including Node.js
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
sqlite3 libsqlite3-dev \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
# Copy go.mod and go.sum first for better dependency caching
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Copy the built web assets from node-builder stage
COPY --from=node-builder /src/webui/dist ./webui/dist
# Run go generate (will skip npm commands since dist exists)
RUN go generate ./webui
# Build the application
ARG TARGETOS=linux
ARG TARGETARCH=amd64
RUN CGO_ENABLED=1 \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
go build -ldflags="-s -w" -o subtitle-manager ./
# Stage 3: Final runtime image
FROM golang:1.26.0-bookworm AS final
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
ca-certificates \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Set ffmpeg path for the application
ENV SM_FFMPEG_PATH=/usr/bin/ffmpeg
# Create non-root user
RUN addgroup --system subtitle && adduser --system --ingroup subtitle subtitle
# Create directories
RUN mkdir -p /config /media && \
chown -R subtitle:subtitle /config /media
# Copy binary
COPY --from=go-builder /src/subtitle-manager /usr/local/bin/subtitle-manager
RUN chmod +x /usr/local/bin/subtitle-manager
COPY docker-init.sh /usr/local/bin/docker-init.sh
RUN chmod +x /usr/local/bin/docker-init.sh
# Switch to non-root user
USER subtitle
# Set default environment variables
ENV SM_CONFIG_FILE=/config/subtitle-manager.yaml \
SM_DB_PATH=/config/db \
SM_DB_BACKEND=pebble \
SM_SQLITE3_FILENAME=subtitle-manager.db \
SM_LOG_LEVEL=info
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/docker-init.sh"]
CMD ["web"]