-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
164 lines (149 loc) · 4.88 KB
/
Dockerfile
File metadata and controls
164 lines (149 loc) · 4.88 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
ARG BDINFO_REPO=https://github.com/mirrorb/BDInfoCLI.git
ARG BDINFO_REF=master
ARG BDINFO_CSPROJ=BDInfo/BDInfo.csproj
ARG GO_VERSION=1.26.1
ARG APP_VERSION=dev
ARG ALPINE_VERSION=edge
ARG ALPINE_EDGE_REPO=https://dl-cdn.alpinelinux.org/alpine/edge
ARG FFMPEG_PKG=ffmpeg=8.1-r0
# 构建 WebUI
FROM --platform=$BUILDPLATFORM node:20-alpine AS webui
ARG APP_VERSION=dev
WORKDIR /app
COPY webui/package.json ./
RUN npm install --no-audit --no-fund
COPY webui .
ENV VITE_APP_VERSION=$APP_VERSION
RUN npm run build
# 构建 Go 后端
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build
ARG APP_VERSION=dev
WORKDIR /src
COPY go.mod ./
COPY *.go ./
COPY cmd ./cmd
COPY internal ./internal
COPY --from=webui /app/dist ./webui/dist
ARG TARGETOS
ARG TARGETARCH
ENV CGO_ENABLED=0
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -buildvcs=false -ldflags="-s -w -X minfo/internal/version.Version=${APP_VERSION}" -o /out/minfo ./cmd/minfo
# 构建 BDInfo (.NET)
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS bdinfo-build
ARG BDINFO_REPO
ARG BDINFO_REF
ARG BDINFO_CSPROJ
ARG TARGETARCH
RUN apk add --no-cache git ca-certificates
RUN git clone --depth 1 --branch "$BDINFO_REF" "$BDINFO_REPO" /src/bdinfo
WORKDIR /src/bdinfo
RUN set -eux; \
# 匹配 Alpine (musl) 运行环境的 RID
case "$TARGETARCH" in \
amd64) rid="linux-musl-x64" ;; \
arm64) rid="linux-musl-arm64" ;; \
*) echo "unsupported TARGETARCH=$TARGETARCH" >&2; exit 1 ;; \
esac; \
dotnet restore "$BDINFO_CSPROJ"; \
# 编译单文件版 (禁用 Trim 以防命令行反射报错)
dotnet publish "$BDINFO_CSPROJ" -c Release -r "$rid" --self-contained true \
-p:PublishSingleFile=true \
-p:EnableCompressionInSingleFile=true \
-p:DebugType=None \
-p:DebugSymbols=false \
-o /out/bdinfo; \
# 提取生成的二进制文件
exe=""; \
for f in /out/bdinfo/*; do \
[ -f "$f" ] || continue; \
[ -x "$f" ] || continue; \
case "${f##*.}" in \
dll|json|pdb) continue ;; \
esac; \
exe="$f"; \
break; \
done; \
if [ -n "$exe" ]; then \
if [ "$exe" != "/out/bdinfo/BDInfo" ]; then \
mv "$exe" /out/bdinfo/BDInfo; \
fi; \
else \
echo "BDInfo executable not found" >&2; exit 1; \
fi; \
chmod +x /out/bdinfo/BDInfo; \
find /out/bdinfo -type f \( -name '*.pdb' -o -name '*.xml' -o -name '*.dbg' \) -delete
# 构建 BD 元数据 helper
FROM alpine:${ALPINE_VERSION} AS media-helper-build
WORKDIR /src
RUN apk add --no-cache build-base
COPY tools/bdsub_probe.c ./tools/bdsub_probe.c
RUN mkdir -p /out && \
cc -O2 -Wall -Wextra -std=c11 ./tools/bdsub_probe.c -o /out/bdsub
# 最终运行环境 (Alpine)
FROM alpine:${ALPINE_VERSION} AS runtime
ARG ALPINE_EDGE_REPO
ARG FFMPEG_PKG
RUN set -eux; \
printf '%s\n%s\n' "${ALPINE_EDGE_REPO}/main" "${ALPINE_EDGE_REPO}/community" > /etc/apk/repositories; \
apk add --no-cache \
ca-certificates \
"$FFMPEG_PKG" \
mediainfo \
fontconfig \
font-noto-cjk \
kmod \
libgdiplus \
libplacebo \
vulkan-loader \
mesa-vulkan-swrast \
oxipng \
pngquant \
util-linux \
tzdata
COPY --from=build /out/minfo /usr/local/bin/minfo
COPY --from=bdinfo-build /out/bdinfo/BDInfo /usr/local/bin/bdinfo
COPY --from=media-helper-build /out/bdsub /usr/local/bin/bdsub
RUN chmod +x /usr/local/bin/minfo /usr/local/bin/bdinfo /usr/local/bin/bdsub
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PORT=28080
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
EXPOSE 28080
ENTRYPOINT ["/usr/local/bin/minfo"]
# 本地调试环境 (Go + Delve + 运行依赖)
FROM golang:${GO_VERSION}-alpine AS debug
ARG ALPINE_EDGE_REPO
ARG FFMPEG_PKG
RUN set -eux; \
printf '%s\n%s\n' "${ALPINE_EDGE_REPO}/main" "${ALPINE_EDGE_REPO}/community" > /etc/apk/repositories; \
apk add --no-cache \
ca-certificates \
"$FFMPEG_PKG" \
mediainfo \
fontconfig \
font-noto-cjk \
kmod \
libgdiplus \
libplacebo \
vulkan-loader \
mesa-vulkan-swrast \
oxipng \
pngquant \
util-linux \
tzdata
RUN GOBIN=/usr/local/bin go install github.com/go-delve/delve/cmd/dlv@latest
COPY --from=runtime /usr/local/bin/bdinfo /usr/local/bin/bdinfo
COPY --from=runtime /usr/local/bin/bdsub /usr/local/bin/bdsub
RUN chmod +x /usr/local/bin/dlv /usr/local/bin/bdinfo /usr/local/bin/bdsub
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PORT=28080
ENV GOCACHE=/tmp/go-build
ENV GOROOT=/usr/local/go
ENV PATH=/usr/local/go/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
WORKDIR /opt/minfo
EXPOSE 28080 2345
CMD ["dlv", "dap", "--listen=:2345"]
# 默认最终镜像保持为运行环境,避免 `docker build .` 误落到 debug stage。
FROM runtime AS final