Files
deploy/Dockerfile.gobuild
T
2026-07-02 11:56:28 +08:00

59 lines
1.5 KiB
Docker

ARG SERVICE
# ========== 构建阶段 ==========
FROM golang:alpine AS builder
ARG SERVICE
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
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
WORKDIR /build
COPY $SERVICE/go.mod $SERVICE/go.sum ./
RUN go mod download
COPY $SERVICE/ .
RUN go build -ldflags="-s -w" -o main ./main.go
# 归集运行时需要的文件(各服务不同,忽略不存在的)
RUN mkdir -p /runtime && cp main /runtime/ && \
cp config.yml /runtime/ 2>/dev/null; \
cp config.yaml /runtime/ 2>/dev/null; \
cp -r manifest /runtime/ 2>/dev/null; \
cp -r resource /runtime/ 2>/dev/null; \
cp -r public /runtime/ 2>/dev/null; \
cp -r template /runtime/ 2>/dev/null; \
cp -r scripts /runtime/ 2>/dev/null; \
cp -r i18n /runtime/ 2>/dev/null; \
cp -r casbin /runtime/ 2>/dev/null; \
true
# ========== 运行阶段 ==========
FROM alpine:latest
ARG SERVICE
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache ca-certificates tzdata
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ARG PORT=8808
EXPOSE $PORT
WORKDIR /app
COPY --from=builder /runtime/ .
CMD ["./main"]