diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..caf83b3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +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 +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct +ENV CGO_ENABLED=0 +ENV GOTOOLCHAIN=auto +WORKDIR /build +COPY . . +RUN go mod download && go mod tidy +RUN go build -ldflags="-s -w" -o main ./main.go + +FROM alpine:3.19 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ + && apk add --no-cache ca-certificates tzdata ffmpeg +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +WORKDIR /app +COPY --from=builder /build/config.yml . +COPY --from=builder /build/prompt.md . +COPY --from=builder /build/default_first_frame.png . +COPY --from=builder /build/main . +RUN printf '#!/bin/sh\nif [ -d /app/short_drama.db ]; then rm -rf /app/short_drama.db; fi\ntouch /app/short_drama.db 2>/dev/null || true\nexec ./main\n' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh +EXPOSE 3006 +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docker-compose-base.yml b/docker-compose-base.yml deleted file mode 100644 index 3bd7894..0000000 --- a/docker-compose-base.yml +++ /dev/null @@ -1,23 +0,0 @@ -services: - golang-base: - build: - dockerfile_inline: | - FROM golang:alpine - 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 - ENV GO111MODULE=on - ENV GOPROXY=https://goproxy.cn,direct - ENV CGO_ENABLED=0 - ENV GOTOOLCHAIN=auto - image: golang-base:latest - - ffmpeg-base: - build: - dockerfile_inline: | - FROM alpine:3.19 - RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk add --no-cache ca-certificates tzdata ffmpeg - ENV TZ=Asia/Shanghai - RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - image: alpine-base:latest \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d8ff167..0a8d044 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,7 @@ services: video-factory: build: - dockerfile_inline: | - FROM golang-base:latest AS builder - WORKDIR /build - COPY . . - RUN go mod download && go mod tidy - RUN go build -ldflags="-s -w" -o main ./main.go - - FROM alpine-base:latest - WORKDIR /app - COPY --from=builder /build/config.yml . - COPY --from=builder /build/prompt.md . - COPY --from=builder /build/default_first_frame.png . - COPY --from=builder /build/main . - RUN printf '#!/bin/sh\nif [ -d /app/short_drama.db ]; then rm -rf /app/short_drama.db; fi\ntouch /app/short_drama.db 2>/dev/null || true\nexec ./main\n' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh - EXPOSE 3006 - ENTRYPOINT ["/app/entrypoint.sh"] + dockerfile: Dockerfile container_name: video-factory ports: - "3006:3006"