Skip to content

Commit

Permalink
Add Docker image release tagging on release
Browse files Browse the repository at this point in the history
Add tagging of the Docker image with the release number when creating a
Git tag.

Resolves #398
  • Loading branch information
HorizonNet committed Nov 28, 2020
1 parent 9b32df3 commit a086a65
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# push image to Docker Hub
push:
runs-on: ubuntu-latest

steps:
- name: Checkout Terrascan
uses: actions/checkout@v1

- name: Build Terrascan docker image
run: make docker-build

- name: Login to docker hub
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u accurics --password-stdin

- name: Push Terrascan latest tag docker image
run: make docker-push-latest-tag
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ help:
@echo "docker-build\n\tbuild terrascan docker image"
@echo "docker-push\n\tpush terrascan docker image"
@echo "docker-push-latest\n\tpush terrascan docker image with latest tag"
@echo "docker-push-latest-tag\n\tpush terrascan docker image with latest release tag"
@echo "gofmt\n\tvalidate gofmt"
@echo "golint\n\tvalidate golint"
@echo "gomodverify\n\tverify go modules"
Expand All @@ -35,7 +36,7 @@ build: clean
@echo "binary created at ${BUILD_DIR}/${BINARY_NAME}"


# clean build
# clean build
clean:
@rm -rf $(BUILD_DIR)

Expand Down Expand Up @@ -95,3 +96,7 @@ docker-push:
# push latest terrascan docker image
docker-push-latest:
./scripts/docker-push-latest.sh

# push release tag terrascan docker image
docker-push-latest-tag:
./scripts/docker-push-latest-tag.sh
15 changes: 15 additions & 0 deletions scripts/docker-push-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null)
DOCKER_REPO="accurics/terrascan"
DOCKERFILE="./build/Dockerfile"
LATEST_TAG=$(git describe --abbrev=0 --tags)
LATEST_TAG_SHORT=$(echo "${LATEST_TAG//v}")

# PS: It is a prerequisite to execute 'docker login' before running this script
docker tag ${DOCKER_REPO}:${GIT_COMMIT} ${DOCKER_REPO}:${LATEST_TAG_SHORT}
docker push ${DOCKER_REPO}:${LATEST_TAG_SHORT}

0 comments on commit a086a65

Please sign in to comment.