测试服务器IP配置变更
This commit is contained in:
61
Dockerfile
61
Dockerfile
@@ -1,55 +1,24 @@
|
||||
# 阶段1: 构建
|
||||
FROM golang:1.26-alpine AS builder
|
||||
|
||||
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
|
||||
|
||||
# 配置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
|
||||
|
||||
# 设置GIT凭据
|
||||
RUN echo "http://x-token-auth:9b31146aa8c10a7cb4f2e49dcee0934a223be1076289810e1ad98b968066c2bc@116.204.74.41:3000" > ~/.git-credentials
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
# 先复制go.mod下载依赖
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download && go mod tidy
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
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
|
||||
# 最小化Docker镜像
|
||||
FROM busybox:uclibc
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /build/main .
|
||||
COPY --from=builder /build/config.yml ./
|
||||
# 复制时区数据
|
||||
COPY timezone/localtime /etc/localtime
|
||||
COPY timezone/timezone /etc/timezone
|
||||
COPY timezone/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||
|
||||
RUN mkdir -p /app/resource/log/run \
|
||||
/app/resource/log/server \
|
||||
&& adduser -D -u 1000 appuser \
|
||||
&& chown -R appuser:appuser /app
|
||||
# 复制预构建的二进制文件和配置文件
|
||||
COPY oss_binary ./main
|
||||
COPY config.yml ./
|
||||
|
||||
USER appuser
|
||||
# 创建日志目录
|
||||
RUN mkdir -p /logs /app/resource/log/run /app/resource/log/server
|
||||
|
||||
# 添加执行权限
|
||||
RUN chmod +x /app/main
|
||||
|
||||
EXPOSE 3008
|
||||
|
||||
# 使用root用户运行
|
||||
CMD ["./main"]
|
||||
|
||||
1
go.sum
1
go.sum
@@ -2,6 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
gitea.com/red-future/common v0.0.7 h1:PbSazDCjmr+HZ4ckSSJYSCC+G/qwC5ZKbLEdsItanQ0=
|
||||
gitea.com/red-future/common v0.0.7/go.mod h1:JgBczlUF8xA8S0YbvDaMLxvvpmBGgjJA6po+EbodzZA=
|
||||
gitea.com/red-future/common v0.0.9/go.mod h1:JgBczlUF8xA8S0YbvDaMLxvvpmBGgjJA6po+EbodzZA=
|
||||
gitea.com/red-future/common v0.0.11 h1:AV7W3G0uZ8aPpHHSHd4ZHmLWe5+2STPKe/AYPoPCWVc=
|
||||
gitea.com/red-future/common v0.0.11/go.mod h1:B8syUI4XbLCDQSeRHURYxEwnWw8mEFgmqCxjC+lM+NU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
|
||||
BIN
oss_binary
Executable file
BIN
oss_binary
Executable file
Binary file not shown.
Reference in New Issue
Block a user