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/ diff --git a/main.go b/main.go index f915944..bc7e2df 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func main() { version() return } + logger.Infof("dtm version is: %s", Version) config.MustLoadConfig(*confFile) conf := &config.Config if *isDebug {