FROM golang:1.22 AS builder

ENV GO111MODULE=on GOPROXY=https://goproxy.cn,direct CGO_ENABLED=0 GOOS=linux GOARCH=amd64

WORKDIR /build

COPY ./ /build/

RUN go build main.go

FROM alpine:latest

WORKDIR /app
ENV TZ Asia/Shanghai

#设置国内镜像源，时区
RUN echo "https://mirrors.aliyun.com/alpine/v3.18/main/" > /etc/apk/repositories && \
    echo "https://mirrors.aliyun.com/alpine/v3.18/community/" >> /etc/apk/repositories \
    && apk update && apk upgrade && apk add --no-cache tzdata && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

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/

# 启动服务
CMD ["./main"]

EXPOSE 12306