From 03f2906e35e92f61750516059fbcd59c0f402efa Mon Sep 17 00:00:00 2001 From: Balint Morasz Date: Thu, 26 Oct 2023 12:54:05 +0200 Subject: [PATCH] ci: push docker image to DO container registry --- .github/workflows/ci.yml | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcbe82c..0818306 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,12 +28,41 @@ jobs: docker-build: runs-on: ubuntu-latest + needs: + - ci-fe steps: - uses: actions/checkout@v3 - - name: docker build run: | cd ./frontend - docker build . - + docker build . -t kemkas:${GITHUB_SHA::8} + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DO_ACCESS_TOKEN }} + - name: Log in to DigitalOcean Container Registry with short-lived credentials + run: doctl registry login --expiry-seconds 1200 + - name: Tag container image + run: | + docker tag kemkas:${GITHUB_SHA::8} registry.digitalocean.com/kemkas/kemkas:${GITHUB_SHA::8} + - name: Tag container image with latest tag + if: ${{ github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged ) }} + run: | + docker tag kemkas:${GITHUB_SHA::8} registry.digitalocean.com/kemkas/kemkas:latest + - name: Push image to Container Registry + run: | + docker push --all-tags registry.digitalocean.com/kemkas/kemkas + - name: Get container image ID of the images just pushed + if: ${{ github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged ) }} + run: | + docker images registry.digitalocean.com/kemkas/kemkas:${GITHUB_SHA::8} --format "{{.ID}}" + export DOCKER_IMAGE_ID=$(docker images registry.digitalocean.com/kemkas/kemkas:${GITHUB_SHA::8} --format "{{.ID}}") + export DOCKER_IMAGE_ID=DO-$DOCKER_IMAGE_ID + echo "DOCKER_IMAGE_ID=$DOCKER_IMAGE_ID" >> $GITHUB_ENV + - name: Tag commit + if: ${{ github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged ) }} + uses: tvdias/github-tagger@v0.0.1 + with: + repo-token: "${{ github.token }}" + tag: "${{ env.DOCKER_IMAGE_ID }}"