Skip to content

Commit

Permalink
Upd: Release to dockerhub workflow
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed Nov 15, 2023
1 parent 869d9e3 commit d6711cd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release docker image to docker hub

on:
release:
types: [created]

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Extract tag from version
id: extract_tag
run: echo ::set-output name=TAG::$(echo ${{ steps.get_version.outputs.VERSION }} | sed 's/refs\/tags\///')

- name: Set Docker Tag
run: echo "DOCKER_HUB_TAG=${{steps.extract_tag.outputs.TAG}}" >> $GITHUB_ENV

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Build docker image, publish docker image to docker hub
- name: Build docker image, publish docker image to docker hub
run: |
make build/docker/deployable/dockerhub publish/dockerhub
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DEPLOY_VERSION = $(shell test -f $(DEPLOY_VERSION_FILE) && cat $(DEPLOY_VERSION_
GCLOUD_HOSTNAME = eu.gcr.io
GCLOUD_PROJECTID = jenkins-189019
DOCKER_IMAGE := ${GCLOUD_HOSTNAME}/${GCLOUD_PROJECTID}/$(NAME)
DOCKER_HUB_IMAGE := igrantio/bb-consent-api

# tag based on git branch, date and commit
DOCKER_TAG := $(GIT_BRANCH)-$(shell date +%Y%m%d%H%M%S)-$(GIT_COMMIT)
Expand Down Expand Up @@ -158,10 +159,19 @@ build/docker/deployable: $(DIST_FILE) ## Builds deployable docker image for prev
docker build --platform=linux/amd64 -t $(DOCKER_IMAGE):$(DOCKER_TAG) -f resources/docker/production/Dockerfile .
echo "$(DOCKER_IMAGE):$(DOCKER_TAG)" > $(DEPLOY_VERSION_FILE)

.PHONY: build/docker/deployable/dockerhub
build/docker/deployable/dockerhub: ## Builds deployable docker image for docker hub
docker build -t $(DOCKER_HUB_IMAGE):$(DOCKER_HUB_TAG) -f resources/docker/Dockerfile.dockerhub .
echo "$(DOCKER_HUB_IMAGE):$(DOCKER_HUB_TAG)" > $(DEPLOY_VERSION_FILE)

.PHONY: publish
publish: $(DEPLOY_VERSION_FILE) ## Publish latest production Docker image to docker hub
docker push $(DEPLOY_VERSION)

.PHONY: publish/dockerhub
publish/dockerhub: $(DEPLOY_VERSION_F ILE) ## Publish latest production Docker image to docker hub
docker push $(DEPLOY_VERSION)

deploy/production: $(DEPLOY_VERSION_FILE) ## Deploy to K8s cluster (e.g. make deploy/{preview,staging,production})
kubectl set image deployment/demo-consent-bb-api demo-consent-bb-api=$(DEPLOY_VERSION) -n govstack-demo

Expand Down
13 changes: 13 additions & 0 deletions resources/docker/production/Dockerfile.dockerhub
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://github.com/GoogleContainerTools/distroless/tree/master/base
# Predecessor to scratch + ca-certificates
FROM frolvlad/alpine-glibc:glibc-2.30

# copy artifacts
COPY dist/linux_amd64/bb-consent-api /app/bin/bb-consent-api
COPY resources/assets/logo.jpeg /opt/bb-consent/api/assets/
COPY resources/assets/cover.jpeg /opt/bb-consent/api/assets/
COPY resources/assets/avatar.jpeg /opt/bb-consent/api/assets/

# start API
EXPOSE 80
ENTRYPOINT ["./app/bin/bb-consent-api", "start-api", "--config", "config-production.json"]

0 comments on commit d6711cd

Please sign in to comment.