Files
kami_boss/deploy/Dockerfile
danial db68283b3b chore(docker): 优化构建环境变量设置
- 移除旧的 GOPROXY 环境变量设置
- 添加 CGO_ENABLED=0 配置以禁用 CGO
- 设置目标操作系统为 linux
- 设置目标架构为 amd64
2025-11-25 21:41:51 +08:00

51 lines
1.5 KiB
Docker

FROM golang:1.24 AS builder
# 定义参数
ARG USE_PROXY
WORKDIR /build
COPY .. /build/
# 根据USE_PROXY参数设置环境变量
RUN export GO111MODULE=on \
&& export CGO_ENABLED=0 \
&& export GOOS=linux \
&& export GOARCH=amd64 \
&& go mod tidy && go build -ldflags="-s -w" main.go
FROM alpine:latest
WORKDIR /app
ENV TZ=Asia/Shanghai
ENV serverName=""
ENV gatewayAddr=""
ENV portalAddr=""
# 定义参数
ARG USE_PROXY
#设置国内镜像源,时区
RUN if [ "$USE_PROXY" = "1" ]; then \
echo "https://mirrors.aliyun.com/alpine/v3.18/main/" > /etc/apk/repositories && \
echo "https://mirrors.aliyun.com/alpine/v3.18/community/" >> /etc/apk/repositories; \
fi && \
apk update && \
apk upgrade && \
apk add --no-cache tzdata curl && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
RUN wget "https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/ca-certificates-20241121-r1.apk" && apk add ./ca-certificates-20241121-r1.apk
RUN curl -fsSL -o /usr/local/share/ca-certificates/aaa-certificate-services.crt https://www.tbs-x509.com/Comodo_AAA_Certificate_Services.crt
RUN update-ca-certificates
COPY --from=builder /build/main /app/
COPY --from=builder /build/conf/ /app/conf/
COPY --from=builder /build/views/ /app/views/
COPY --from=builder /build/static/ /app/static/
COPY --from=builder /build/deploy/wait-for-it.sh /app/
# 启动服务
CMD ["sh", "wait-for-it.sh", "mysql:3306" , "./main"]
EXPOSE 12306