diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml new file mode 100644 index 0000000..ceb046e --- /dev/null +++ b/.github/workflows/dockerhub.yml @@ -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 diff --git a/Makefile b/Makefile index ccb987f..38bc9d8 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 diff --git a/resources/docker/production/Dockerfile.dockerhub b/resources/docker/production/Dockerfile.dockerhub new file mode 100644 index 0000000..34a9061 --- /dev/null +++ b/resources/docker/production/Dockerfile.dockerhub @@ -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"]