feat: Improve Docker build (#3682)
This commit is contained in:
8
tools/goctl/.dockerignore
Normal file
8
tools/goctl/.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
||||
test/
|
||||
.dockerignore
|
||||
.go-version
|
||||
Dockerfile
|
||||
goctl
|
||||
Makefile
|
||||
readme.md
|
||||
readme-cn.md
|
||||
@@ -8,13 +8,12 @@ ENV GOPROXY https://goproxy.cn,direct
|
||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||
RUN addgroup -g 1000 -S app && adduser -u 1000 -S app -G app
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go mod download
|
||||
RUN go build -ldflags="-s -w" -o /app/goctl ./goctl.go
|
||||
|
||||
|
||||
@@ -22,13 +21,20 @@ FROM golang:alpine
|
||||
|
||||
RUN apk update --no-cache && apk add --no-cache protoc
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||
COPY --from=builder /go/bin/protoc-gen-go /usr/bin/protoc-gen-go
|
||||
COPY --from=builder /go/bin/protoc-gen-go-grpc /usr/bin/protoc-gen-go-grpc
|
||||
COPY --from=builder /etc/passwd /etc/group /etc/
|
||||
COPY --from=builder /usr/share/zoneinfo/ /usr/share/zoneinfo/
|
||||
COPY --from=builder --chown=1000:1000 /go/bin/protoc-gen-go* /app/goctl /usr/local/bin/
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/goctl /usr/bin/goctl
|
||||
USER app
|
||||
|
||||
CMD ["goctl"]
|
||||
LABEL org.opencontainers.image.authors="Kevin Wan"
|
||||
LABEL org.opencontainers.image.base.name="docker.io/library/golang:alpine"
|
||||
LABEL org.opencontainers.image.description="A cloud-native Go microservices framework with cli tool for productivity."
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.source="https://github.com/zeromicro/go-zero"
|
||||
LABEL org.opencontainers.image.title="goctl (cli)"
|
||||
LABEL org.opencontainers.image.version="v1.6.0"
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/goctl"]
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
FROM golang:1.19
|
||||
FROM golang:1.21-alpine
|
||||
|
||||
ENV TZ Asia/Shanghai
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
WORKDIR /app
|
||||
ADD goctl /usr/bin/goctl
|
||||
ADD cmd.sh .
|
||||
COPY goctl /usr/bin/
|
||||
COPY cmd.sh .
|
||||
|
||||
RUN chmod +x /usr/bin/goctl
|
||||
RUN chmod +x cmd.sh
|
||||
RUN chmod +x /usr/bin/goctl cmd.sh
|
||||
CMD ["/bin/bash", "cmd.sh"]
|
||||
|
||||
@@ -25,7 +25,7 @@ fi
|
||||
|
||||
# run docker image
|
||||
console_step "docker running"
|
||||
docker run $image
|
||||
docker run --rm $image
|
||||
if [ $? -ne 0 ]; then
|
||||
rm -f $buildFile
|
||||
console_red "docker run failed"
|
||||
|
||||
Reference in New Issue
Block a user