Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker image release tagging on release #410

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}