From 99e87b9d6b0817ca8c7819f5a4937cd1193b1004 Mon Sep 17 00:00:00 2001 From: atompi Date: Wed, 8 Mar 2023 16:46:01 +0800 Subject: [PATCH] chore: better docker build experience Build binaries via docker in one step. --- Dockerfile | 31 +++++++++++++++++++++++-------- README.md | 14 +------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a3e5af..3543c07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,33 @@ ## Build # This dockerfile uses the linux image -# VERSION 1 +# VERSION 1.2.0 # Author: greatsql # Command format: Instruction [arguments / command] … -FROM golang:latest +FROM golang:latest AS builder + LABEL gt-checksum="greatsql" MAINTAINER greatsql -ENV GO111MODULE=on GOOS=linux GOPROXY=https://goproxy.io -RUN go env -w GOPRIVATE=github.com/marvinhosea/* + +ENV GO111MODULE=on \ + GOOS=linux \ + GOPROXY="https://goproxy.io" \ + GOPRIVATE="github.com/marvinhosea/*" + WORKDIR /go/release -COPY go.mod ./ -COPY go.sum ./ + COPY . . -RUN go mod download + +ARG VERSION + +RUN go mod tidy RUN go build -o gt-checksum greatdbCheck.go -RUN mkdir -p ./gt-checksum-v1.2.0 && cp -rf docs gc.conf gc.conf-simple gt-checksum Oracle/instantclient_11_2 README.md relnotes gt-checksum-v1.2.0 +RUN mkdir -p ./gt-checksum-${VERSION} && cp -rf docs gc.conf gc.conf-simple gt-checksum Oracle/instantclient_11_2 README.md relnotes gt-checksum-${VERSION} + +FROM scratch AS exporter + +ARG VERSION + +COPY --from=builder /go/release/gt-checksum-${VERSION} ./gt-checksum-${VERSION} + +# DOCKER_BUILDKIT=1 docker build --build-arg VERSION=v1.2.0 -f Dockerfile -o ./ . diff --git a/README.md b/README.md index 7bf0f3c..23b2be1 100644 --- a/README.md +++ b/README.md @@ -151,19 +151,7 @@ shell> mv gt-checksum /usr/local/bin ```shell shell> git clone https://gitee.com/GreatSQL/gt-checksum.git shell> cd gt-checksum - -#构建Docker编译环境 -shell> docker build -t gt-checksum . - -#查看Docker镜像列表 -shell> docker images | grep gt-checksum -gt-checksum latest a716d9d018b3 27 minutes ago 1.38GB - -#创建一个新容器,编译gt-checksum -shell> docker run -itd --name=gt-checksum gt-checksum - -#将编译好的二进制文件copy到宿主机 -shell> docker cp gt-checksum:/go/release/gt-checksum-v1.2.0 . +shell> DOCKER_BUILDKIT=1 docker build --build-arg VERSION=v1.2.0 -f Dockerfile -o ./ . shell> cd gt-checksum-v1.2.0 shell> ./gt-checksum -v gt-checksum version 1.2.0 -- Gitee