From 3b4410b8a48eab1f17d5be265bf2e5328672e5ea Mon Sep 17 00:00:00 2001 From: jxlwqq Date: Fri, 18 Feb 2022 11:32:21 +0800 Subject: [PATCH] add docker build args --- .github/workflows/release.yml | 5 +++++ helper/Dockerfile-release | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d65f219..17c6e77 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,9 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Get Release Version + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Build and push uses: docker/build-push-action@v2 with: @@ -57,3 +60,5 @@ jobs: platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + RELEASE_VERSION=${{ env.RELEASE_VERSION }} \ No newline at end of file diff --git a/helper/Dockerfile-release b/helper/Dockerfile-release index 2cf141a..45127c2 100644 --- a/helper/Dockerfile-release +++ b/helper/Dockerfile-release @@ -2,11 +2,12 @@ FROM --platform=$TARGETPLATFORM golang:1.16-alpine as builder ARG TARGETARCH ARG TARGETOS +ARG RELEASE_VERSION WORKDIR /app/dtm # RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct EXPOSE 8080 COPY . . -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w -X main.Version=$RELEASE_VERSION" FROM --platform=$TARGETPLATFORM alpine COPY --from=builder /app/dtm/dtm /app/dtm/