forked from bs10081/youtube-music-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (73 loc) · 2.26 KB
/
Copy pathDockerfile
File metadata and controls
83 lines (73 loc) · 2.26 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
# 多階段構建
# Stage 1: 構建前端
ARG APP_VERSION=0.2.0
ARG APP_GIT_SHA=dev
ARG YTDLP_VERSION=2026.03.17
FROM node:20-slim AS frontend-builder
ARG APP_VERSION
ARG APP_GIT_SHA
ENV APP_VERSION=${APP_VERSION}
ENV APP_GIT_SHA=${APP_GIT_SHA}
WORKDIR /app
COPY package.json ./package.json
COPY frontend/package*.json ./frontend/
COPY src/utils/app-metadata.ts ./src/utils/app-metadata.ts
WORKDIR /app/frontend
RUN npm ci
WORKDIR /app
COPY frontend/ ./frontend/
ENV NODE_ENV=production
RUN cd frontend && npm run build
# Stage 2: 構建後端
FROM oven/bun:1 AS backend-builder
ARG APP_VERSION
ARG APP_GIT_SHA
WORKDIR /app
ENV NODE_ENV=production
ENV APP_VERSION=${APP_VERSION}
ENV APP_GIT_SHA=${APP_GIT_SHA}
COPY package.json bun.lock* ./
RUN bun install --frozen-lockfile
COPY src/ ./src/
COPY tsconfig.json ./
RUN bun build src/index.ts --outdir dist --target bun
# Stage 3: 最終映像
FROM oven/bun:1-slim
ARG APP_VERSION
ARG APP_GIT_SHA
ARG YTDLP_VERSION
WORKDIR /app
# 安裝 mpv,並使用可控版本的 yt-dlp binary
RUN apt-get update && apt-get install -y --no-install-recommends \
mpv \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN set -eux; \
arch="$(uname -m)"; \
case "$arch" in \
x86_64|amd64) ytdlp_asset="yt-dlp_linux" ;; \
aarch64|arm64) ytdlp_asset="yt-dlp_linux_aarch64" ;; \
armv7l|armhf) ytdlp_asset="yt-dlp_linux_armv7l" ;; \
*) echo "Unsupported architecture for yt-dlp binary: $arch" >&2; exit 1 ;; \
esac; \
curl -L "https://github.com/yt-dlp/yt-dlp/releases/download/${YTDLP_VERSION}/${ytdlp_asset}" -o /usr/local/bin/yt-dlp; \
chmod +x /usr/local/bin/yt-dlp; \
yt-dlp --version
# 複製構建產物
COPY --from=backend-builder /app/dist ./dist
COPY --from=backend-builder /app/node_modules ./node_modules
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
COPY package.json ./
# 複製舊版 HTML5 前端(保留作為後備)
COPY public/ ./public/
# 環境變數
ENV NODE_ENV=production
ENV LOG_LEVEL=INFO
ENV APP_VERSION=${APP_VERSION}
ENV APP_GIT_SHA=${APP_GIT_SHA}
ENV SYNC_STATE_DB_PATH=/data/sync-state.sqlite
LABEL org.opencontainers.image.version="${APP_VERSION}"
LABEL org.opencontainers.image.revision="${APP_GIT_SHA}"
EXPOSE 3000
CMD ["bun", "run", "dist/index.js"]