From 919a5e6e6dca716464398b97671647ada15e4c8b Mon Sep 17 00:00:00 2001 From: Roee Gadot Date: Thu, 15 Jul 2021 13:28:56 +0300 Subject: [PATCH] no message --- .github/workflows/publish-cli.yml | 46 ------------------ .github/workflows/publish-docker.yml | 39 --------------- .github/workflows/publish.yml | 73 ++++++++++++++++++++++++++++ Dockerfile | 6 ++- api/main.go | 3 ++ api/pkg/version/consts.go | 8 +++ 6 files changed, 89 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/publish-cli.yml delete mode 100644 .github/workflows/publish-docker.yml create mode 100644 .github/workflows/publish.yml create mode 100644 api/pkg/version/consts.go diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml deleted file mode 100644 index b9e814931..000000000 --- a/.github/workflows/publish-cli.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: public-cli -on: - push: - branches: - - develop - - main -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@master - with: - service_account_key: ${{ secrets.GCR_JSON_KEY }} - export_default_credentials: true - - uses: haya14busa/action-cond@v1 - id: condval - with: - cond: ${{ github.ref == 'refs/heads/main' }} - if_true: "minor" - if_false: "patch" - - name: Auto Increment Semver Action - uses: MCKanpolat/auto-semver-action@1.0.5 - id: versioning - with: - releaseType: ${{ steps.condval.outputs.value }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Get base image name - shell: bash - run: | - echo "##[set-output name=build_timestamp;]$(echo $(date +%s))" - echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: version_parameters - - name: Build and Push CLI - run: make push-cli SEM_VER='${{ steps.versioning.outputs.version }}' BUILD_TIMESTAMP='${{ steps.version_parameters.outputs.build_timestamp }}' - - name: publish - uses: ncipollo/release-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - artifacts: "cli/bin/*" - commit: ${{ steps.version_parameters.outputs.branch }} - tag: ${{ steps.versioning.outputs.version }} - prerelease: ${{ github.ref != 'refs/heads/main' }} - bodyFile: 'cli/bin/README.md' diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml deleted file mode 100644 index bd8bfa03a..000000000 --- a/.github/workflows/publish-docker.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: publish-docker -on: - push: - branches: - - 'develop' - - 'main' -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Get base image name - shell: bash - run: echo "##[set-output name=image;]$(echo gcr.io/up9-docker-hub/mizu/${GITHUB_REF#refs/heads/})" - id: base_image_step - - name: Docker meta - id: meta - uses: crazy-max/ghaction-docker-meta@v2 - with: - images: ${{ steps.base_image_step.outputs.image }} - tags: | - type=sha - type=raw,${{ github.sha }} - type=raw,latest - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - registry: gcr.io - username: _json_key - password: ${{ secrets.GCR_JSON_KEY }} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..166c0bafa --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,73 @@ +name: publish +on: + push: + branches: + - 'develop' + - 'main' + - 'feature/versioning' +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@master + with: + service_account_key: ${{ secrets.GCR_JSON_KEY }} + export_default_credentials: true + - uses: haya14busa/action-cond@v1 + id: condval + with: + cond: ${{ github.ref == 'refs/heads/main' }} + if_true: "minor" + if_false: "patch" + - name: Auto Increment Semver Action + uses: MCKanpolat/auto-semver-action@1.0.5 + id: versioning + with: + releaseType: ${{ steps.condval.outputs.value }} + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Get version parameters + shell: bash + run: | + echo "##[set-output name=build_timestamp;]$(echo $(date +%s))" + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: version_parameters + - name: Get base image name + shell: bash + run: echo "##[set-output name=image;]$(echo gcr.io/up9-docker-hub/mizu/${GITHUB_REF#refs/heads/})" + id: base_image_step + - name: Docker meta + id: meta + uses: crazy-max/ghaction-docker-meta@v2 + with: + images: ${{ steps.base_image_step.outputs.image }} + tags: | + type=sha + type=raw,${{ github.sha }} + type=raw,${{ steps.versioning.outputs.version }} + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + registry: gcr.io + username: _json_key + password: ${{ secrets.GCR_JSON_KEY }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} +# - name: Build and Push CLI +# run: make push-cli SEM_VER='${{ steps.versioning.outputs.version }}' BUILD_TIMESTAMP='${{ steps.version_parameters.outputs.build_timestamp }}' +# - name: publish +# uses: ncipollo/release-action@v1 +# with: +# token: ${{ secrets.GITHUB_TOKEN }} +# artifacts: "cli/bin/*" +# commit: ${{ steps.version_parameters.outputs.branch }} +# tag: ${{ steps.versioning.outputs.version }} +# prerelease: ${{ github.ref != 'refs/heads/main' }} +# bodyFile: 'cli/bin/README.md' diff --git a/Dockerfile b/Dockerfile index 157588ec9..dad77821e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,11 @@ RUN go list -f '{{.Path}}@{{.Version}}' -m all | sed 1d | grep -e 'go-cache' -e COPY shared ../shared COPY tap ../tap COPY api . -RUN go build -ldflags="-s -w" -o mizuagent . +RUN go build -ldflags="-s -w \ + -X 'mizuserver/version.GitCommitHash=$(COMMIT_HASH)' \ + -X 'mizuserver/version.Branch=$(GIT_BRANCH)' \ + -X 'mizuserver/version.BuildTimestamp=$(BUILD_TIMESTAMP)' \ + -X 'mizuserver/version.SemVer=$(SEM_VER)'" -o mizuagent . FROM alpine:3.13.5 diff --git a/api/main.go b/api/main.go index ba012fca7..ef9daa6d4 100644 --- a/api/main.go +++ b/api/main.go @@ -16,6 +16,7 @@ import ( "mizuserver/pkg/routes" "mizuserver/pkg/sensitiveDataFiltering" "mizuserver/pkg/utils" + "mizuserver/pkg/version" "os" "os/signal" "strings" @@ -27,6 +28,8 @@ var standalone = flag.Bool("standalone", false, "Run in standalone tapper and AP var aggregatorAddress = flag.String("aggregator-address", "", "Address of mizu collector for tapping") func main() { + rlog.Infof("Version parameters are: %s %s %s %s", version.Branch, version.SemVer, version.BuildTimestamp, version.BuildTimestamp) + flag.Parse() hostMode := os.Getenv(shared.HostModeEnvVar) == "1" tapOpts := &tap.TapOpts{HostMode: hostMode} diff --git a/api/pkg/version/consts.go b/api/pkg/version/consts.go new file mode 100644 index 000000000..79742f5ce --- /dev/null +++ b/api/pkg/version/consts.go @@ -0,0 +1,8 @@ +package version + +var ( + SemVer = "0.0.1" + Branch = "develop" + GitCommitHash = "" // this var is overridden using ldflags in makefile when building + BuildTimestamp = "" // this var is overridden using ldflags in makefile when building +)