Files
oss/Dockerfile

56 lines
1.3 KiB
Docker
Raw Normal View History

2026-04-01 13:04:59 +08:00
# 阶段1: 构建
2026-04-01 14:05:31 +08:00
FROM golang:1.26-alpine AS builder
2026-04-01 13:04:59 +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
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=0
ENV GOTOOLCHAIN=auto
ENV GOPRIVATE=gitea.com/red-future/common
2026-04-01 14:05:31 +08:00
2026-04-01 13:04:59 +08:00
# 配置git使用私有Gitea仓库
2026-04-01 13:49:16 +08:00
RUN git config --global url."http://116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \
2026-04-01 13:04:59 +08:00
git config --global credential.helper store
2026-04-01 13:49:16 +08:00
# 设置GIT凭据
RUN echo "http://x-token-auth:9b31146aa8c10a7cb4f2e49dcee0934a223be1076289810e1ad98b968066c2bc@116.204.74.41:3000" > ~/.git-credentials
2026-04-01 13:04:59 +08:00
WORKDIR /build
2026-04-01 14:05:31 +08:00
# 先复制go.mod下载依赖
2026-04-01 13:49:16 +08:00
COPY go.mod go.sum ./
2026-04-01 13:04:59 +08:00
RUN go mod download && go mod tidy
2026-04-01 14:05:31 +08:00
# 复制源代码
COPY . .
2026-04-01 13:04:59 +08:00
RUN go build -ldflags="-s -w" -o main ./main.go
# 阶段2: 运行
FROM alpine:3.19
RUN apk add --no-cache ca-certificates tzdata
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
COPY --from=builder /build/main .
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
USER appuser
2026-04-01 13:16:32 +08:00
EXPOSE 3008
2026-04-01 13:04:59 +08:00
CMD ["./main"]