go-zero开发-cicd

通过使用goctl生成dockerfile或者自己改下方模板。

# build过程
FROM golang:alpine AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

WORKDIR /build/zero

ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .

RUN go build -ldflags="-s -w" -o /app/users-api api/user.go
RUN go build -ldflags="-s -w" -o /app/users-rpc rpc/user.go

# 生成镜像
# RUN echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories && \
#     echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories
# RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata
ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /app/users-api /app/users-api
COPY --from=builder /app/users-rpc /app/users-rpc

CMD ["./users-api","-f","./user-api.yaml"]
CMD ["./users-rpc","-f","./user-rpc.yaml"]

你可能感兴趣的:(go-zero开发-cicd)