Files
gateway/Dockerfile

55 lines
1.3 KiB
Docker
Raw Normal View History

2026-03-16 11:02:37 +08:00
# 阶段1: 构建
FROM golang:1.25-alpine AS builder
2026-01-31 18:37:54 +08:00
2026-03-16 11:02:37 +08:00
RUN 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
2026-01-31 18:37:54 +08:00
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=0
2026-03-16 11:02:37 +08:00
ENV GOTOOLCHAIN=auto
2026-03-16 17:04:22 +08:00
ENV GOPRIVATE=gitea.com/red-future/common
2026-01-31 18:37:54 +08:00
2026-03-16 17:04:22 +08:00
# 配置git使用私有Gitea仓库
RUN git config --global url."http://116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \
git config --global credential.helper store
2026-01-31 18:37:54 +08:00
2026-03-16 17:04:22 +08:00
# 设置GIT凭据
RUN echo "http://x-token-auth:297685158fb953a1bad6c45e16f72472ca6e9866@116.204.74.41:3000" > ~/.git-credentials
2026-01-31 18:37:54 +08:00
2026-03-16 17:04:22 +08:00
WORKDIR /build
2026-01-31 18:37:54 +08:00
2026-03-16 17:04:22 +08:00
COPY go.mod go.sum ./
2026-03-16 11:02:37 +08:00
COPY main.go ./
COPY config.yml ./
2026-01-31 18:37:54 +08:00
2026-03-16 17:04:22 +08:00
RUN go mod download && go mod tidy
2026-01-31 18:37:54 +08:00
RUN go build -ldflags="-s -w" -o main ./main.go
2026-03-16 11:02:37 +08:00
# 阶段2: 运行
FROM alpine:3.19
2026-01-31 18:37:54 +08:00
2026-03-16 11:02:37 +08:00
RUN apk add --no-cache ca-certificates tzdata
2026-01-31 18:37:54 +08:00
ENV TZ=Asia/Shanghai
2026-03-16 11:02:37 +08:00
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2026-01-31 18:37:54 +08:00
WORKDIR /app
COPY --from=builder /build/main .
2026-03-16 11:02:37 +08:00
COPY --from=builder /build/config.yml ./
RUN mkdir -p /app/resource/log/run \
/app/resource/log/server \
&& adduser -D -u 1000 appuser \
&& chown -R appuser:appuser /app
2026-01-31 18:37:54 +08:00
USER appuser
EXPOSE 8000
2026-03-16 11:02:37 +08:00
CMD ["./main"]