diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b8710a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/Dockerfile.gobuild b/Dockerfile.gobuild new file mode 100644 index 0000000..e6c4d7d --- /dev/null +++ b/Dockerfile.gobuild @@ -0,0 +1,58 @@ +ARG SERVICE + +# ========== 构建阶段 ========== +FROM golang:alpine AS builder + +ARG SERVICE + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ + apk add --no-cache git ca-certificates tzdata + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct +ENV CGO_ENABLED=0 +ENV GOTOOLCHAIN=auto +WORKDIR /build + +COPY $SERVICE/go.mod $SERVICE/go.sum ./ +RUN go mod download + +COPY $SERVICE/ . + +RUN go build -ldflags="-s -w" -o main ./main.go + +# 归集运行时需要的文件(各服务不同,忽略不存在的) +RUN mkdir -p /runtime && cp main /runtime/ && \ + cp config.yml /runtime/ 2>/dev/null; \ + cp config.yaml /runtime/ 2>/dev/null; \ + cp -r manifest /runtime/ 2>/dev/null; \ + cp -r resource /runtime/ 2>/dev/null; \ + cp -r public /runtime/ 2>/dev/null; \ + cp -r template /runtime/ 2>/dev/null; \ + cp -r scripts /runtime/ 2>/dev/null; \ + cp -r i18n /runtime/ 2>/dev/null; \ + cp -r casbin /runtime/ 2>/dev/null; \ + true + + +# ========== 运行阶段 ========== +FROM alpine:latest + +ARG SERVICE + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ + apk add --no-cache ca-certificates tzdata + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +ARG PORT=8808 +EXPOSE $PORT + +WORKDIR /app +COPY --from=builder /runtime/ . + +CMD ["./main"] diff --git a/Dockerfile.media b/Dockerfile.media new file mode 100644 index 0000000..34a0f52 --- /dev/null +++ b/Dockerfile.media @@ -0,0 +1,64 @@ +# ========== 构建 Go 二进制 ========== +FROM golang:alpine AS builder + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ + apk add --no-cache git ca-certificates tzdata + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct +ENV CGO_ENABLED=0 +ENV GOTOOLCHAIN=auto +WORKDIR /build + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN go build -ldflags="-s -w" -o main ./main.go + + +# ========== 运行时(FFmpeg + Python3 + PySceneDetect + Node.js + HyperFrames)========== +FROM alpine:3.21 + +# 阿里云镜像 + community 仓库 +RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories \ + && echo "https://mirrors.aliyun.com/alpine/v3.21/community" >> /etc/apk/repositories \ + && apk add --no-cache ca-certificates tzdata ffmpeg python3 py3-pip nodejs npm \ + gcc musl-dev python3-dev linux-headers + +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# opencv +RUN apk add --no-cache py3-opencv + +# PySceneDetect(虚拟环境隔离) +RUN python3 -m venv --system-site-packages /opt/venv \ + && /opt/venv/bin/pip install --no-deps -i https://mirrors.aliyun.com/pypi/simple/ \ + --trusted-host mirrors.aliyun.com scenedetect \ + && /opt/venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ \ + --trusted-host mirrors.aliyun.com click platformdirs tqdm +ENV PATH=/opt/venv/bin:$PATH + +RUN python3 -c "import scenedetect; print(f'scenedetect {scenedetect.__version__} installed')" + +# HyperFrames +RUN npm install -g hyperframes --ignore-scripts + +# Chromium + 中文字体 +RUN apk add --no-cache chromium font-noto-cjk fontconfig \ + && fc-cache -f +RUN npx hyperframes browser ensure + +WORKDIR /app + +COPY --from=builder /build/main . +COPY config.yml . +COPY scripts/ ./scripts/ + +EXPOSE 3010 + +CMD ["./main"] diff --git a/Dockerfile.ui b/Dockerfile.ui new file mode 100644 index 0000000..b7b8a4c --- /dev/null +++ b/Dockerfile.ui @@ -0,0 +1,35 @@ +# ========== 构建前端 ========== +FROM docker.m.daocloud.io/node:18-alpine AS builder + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories + +WORKDIR /app + +COPY package*.json ./ +RUN npm install --registry=https://registry.npmmirror.com + +COPY . . +RUN npm run build + + +# ========== 部署到 Nginx ========== +FROM docker.m.daocloud.io/nginx:alpine + +COPY --from=builder /app/dist/ /usr/share/nginx/html/ +COPY ngnix.conf /etc/nginx/conf.d/default.conf +COPY ssl/ /etc/nginx/ssl/ + +RUN printf '%s\n' \ + '#!/bin/sh' \ + 'set -e' \ + 'if [ -n "$API_HOST" ]; then' \ + ' HOST_IP="$API_HOST"' \ + 'else' \ + ' HOST_IP=$(route -n 2>/dev/null | grep "^0.0.0.0" | tr -s " " | cut -d " " -f2)' \ + 'fi' \ + 'sed -i "s/__API_HOST__/$HOST_IP/g" /etc/nginx/conf.d/default.conf' \ + > /docker-entrypoint.d/01-set-api-host.sh && chmod +x /docker-entrypoint.d/01-set-api-host.sh + +EXPOSE 80 443 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose-app.yml b/docker-compose-app.yml index 30031f4..d2a1004 100644 --- a/docker-compose-app.yml +++ b/docker-compose-app.yml @@ -18,6 +18,8 @@ networks: services: + # -------- Go 微服务(各服务目录自带 Dockerfile)-------- + gateway: build: context: ../gateway @@ -60,17 +62,6 @@ services: networks: - redfuture-net - media: - build: - context: ../media - dockerfile: Dockerfile - container_name: media - restart: unless-stopped - ports: - - "3010:3010" - networks: - - redfuture-net - model-gateway: build: context: ../model-gateway @@ -93,6 +84,32 @@ services: networks: - redfuture-net + prompts-core: + build: + context: ../prompts-core + dockerfile: Dockerfile + container_name: prompts-core + restart: unless-stopped + ports: + - "3009:3009" + networks: + - redfuture-net + + # -------- media(特殊依赖:FFmpeg + Python + HyperFrames)-------- + + media: + build: + context: ../media + dockerfile: Dockerfile + container_name: media + restart: unless-stopped + ports: + - "3010:3010" + networks: + - redfuture-net + + # -------- 前端(Node 构建 + Nginx)-------- + admin-ui: build: context: ../admin-ui @@ -104,14 +121,3 @@ services: - "443:443" networks: - redfuture-net - - prompts-core: - build: - context: ../prompts-core - dockerfile: Dockerfile - container_name: prompts-core - restart: unless-stopped - ports: - - "3009:3009" - networks: - - redfuture-net