Files
override-web/Dockerfile
2024-09-19 16:01:18 +08:00

42 lines
1.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 构建阶段
FROM golang:alpine AS builder
WORKDIR /build
# 复制整个项目
COPY . ./override-web
# 设置 Go 环境
ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct
# 构建配置管理服务器
WORKDIR /build/override-web/config
RUN go mod download
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o config-server .
# 构建原始 override 应用
WORKDIR /build/override-web/override
RUN go mod download
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o override .
# 最终镜像
FROM alpine:latest
RUN apk --no-cache add ca-certificates
# 从构建阶段复制编译好的二进制文件
COPY --from=builder /build/override-web/config/config-server /usr/local/bin/
COPY --from=builder /build/override-web/override/override /usr/local/bin/
WORKDIR /app
VOLUME /app
# 复制配置文件和静态文件
COPY ./config/web /app/web
COPY ./override/config.json.example /app/config.json
# 暴露原始应用和配置管理服务器的端口
EXPOSE 8181 9090
# 使用 shell 形式的 CMD这样可以使用环境变量并同时运行两个应用
CMD ["/bin/sh", "-c", "/usr/local/bin/config-server -app /usr/local/bin/override -config /app/config.json & /usr/local/bin/override"]