File size: 605 Bytes
893fb77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 使用适合Go应用的基础镜像
FROM golang:alpine AS builder
ARG TARGETOS
ARG TARGETARCH
RUN apk update && apk add --no-cache upx make && rm -rf /var/cache/apk/*

# 设置工作目录
WORKDIR /app

# 复制所有文件到容器中
COPY . .

# 下载依赖
RUN go mod tidy

# 构建应用程序
RUN make build-${TARGETOS}-${TARGETARCH}

FROM alpine:latest AS final
RUN apk --no-cache add ca-certificates && \
    mkdir -p /data && \
    chmod 777 /data

WORKDIR /data
COPY --from=builder /app/build/monica /data/monica
RUN chmod +x /data/monica

# 开放端口
EXPOSE 7860

# 运行
CMD ["./monica"]