diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 55fc876d..b6f83669 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -36,7 +36,7 @@ jobs: - name: Docker edge build & tag if: startsWith(github.ref, 'refs/tags/') != true && success() run: | - DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:edge-latest . + DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:edge-latest --build-arg GIT_COMMITSHA=${GITHUB_SHA::8} --build-arg GIT_VERSION="edge-latest" . docker tag ${{ secrets.IMAGE_NAME }}:edge-latest ${{ secrets.IMAGE_NAME }}:edge-${GITHUB_SHA::7} - name: Docker edge push if: startsWith(github.ref, 'refs/tags/') != true && success() @@ -46,7 +46,7 @@ jobs: - name: Docker stable build & tag if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success() run: | - DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:stable-latest . + DOCKER_BUILDKIT=1 docker build --no-cache -t ${{ secrets.IMAGE_NAME }}:stable-latest --build-arg GIT_COMMITSHA=${GITHUB_SHA::8} --build-arg GIT_VERSION=${GITHUB_REF/refs\/tags\//} . docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//} docker tag ${{ secrets.IMAGE_NAME }}:stable-latest ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7} - name: Docker stable push diff --git a/Dockerfile b/Dockerfile index b437391b..9182d87d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM golang:1.15 as builder +ARG GIT_VERSION +ARG GIT_COMMITSHA WORKDIR /build # Copy the Go Modules manifests @@ -10,7 +12,7 @@ RUN go mod download # Copy the go source COPY . . # Build -RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o meshery-meshsync main.go +RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -s -X main.version=$GIT_VERSION -X main.commitsha=$GIT_COMMITSHA" -a -o meshery-meshsync main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/main.go b/main.go index 6fcf2595..77ab5dea 100644 --- a/main.go +++ b/main.go @@ -13,14 +13,20 @@ import ( "github.com/layer5io/meshsync/internal/channels" "github.com/layer5io/meshsync/internal/config" "github.com/layer5io/meshsync/meshsync" + "github.com/spf13/viper" ) var ( serviceName = "meshsync" provider = configprovider.ViperKey + version = "Not Set" + commitsha = "Not Set" ) func main() { + viper.SetDefault("BUILD", version) + viper.SetDefault("COMMITSHA", commitsha) + // Initialize Logger instance log, err := logger.New(serviceName, logger.Options{ Format: logger.SyslogLogFormat,