From 485e6986b88a14db5ab75ed12bab5cdc73592ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 19 Jul 2022 08:30:56 +0200 Subject: [PATCH] Implement DigitalOcean Kubernetes deployment on publishing --- .github/workflows/publish.yml | 59 ++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index da8d006e7..a2e9c84de 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -246,6 +246,63 @@ jobs: - name: Push maintenance run: docker push --all-tags ocelotsocialnetwork/maintenance + ############################################################################## + # JOB: KUBERNETES DEPLOY LATEST VERSION ###################################### + ############################################################################## + kubernetes_deploy: + # see example https://github.com/do-community/example-doctl-action + # see example https://github.com/do-community/example-doctl-action/blob/main/.github/workflows/workflow.yaml + name: Kubernetes deploy of latest version to stage.ocelot.social cluster at DigitalOcean + runs-on: ubuntu-latest + needs: [upload_to_dockerhub] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # SET ENVS ############################################################### + ########################################################################## + - name: ENV - VERSION + run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + - name: ENV - BUILD_VERSION + run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV + ########################################################################## + # Install DigitalOceans doctl and set kubeconfig ######################### + ########################################################################## + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + - name: Save DigitalOcean kubeconfig with short-lived credentials + run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 cluster-stage-ocelot-social + ########################################################################## + # Deploy new Docker images to DigitalOcean Kubernetes cluster ############ + ########################################################################## + # - name: Deploy 'latest' to DigitalOcean Kubernetes + # run: | + # kubectl set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:latest + # kubectl rollout restart deployment/ocelot-webapp + # kubectl set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:latest + # kubectl rollout restart deployment/ocelot-backend + # kubectl set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:latest + # kubectl rollout restart deployment/ocelot-backend + # kubectl set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:latest + # kubectl rollout restart deployment/ocelot-neo4j + - name: Deploy actual version '$BUILD_VERSION' to DigitalOcean Kubernetes + run: | + kubectl set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:$BUILD_VERSION + kubectl set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:$BUILD_VERSION + kubectl set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:$BUILD_VERSION + kubectl set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:$BUILD_VERSION + # - name: Verify deployment + # run: | + # kubectl rollout status deployment/ocelot-webapp + # kubectl rollout status deployment/ocelot-backend + # kubectl rollout status deployment/ocelot-backend + # kubectl rollout status deployment/ocelot-neo4j + ############################################################################## # JOB: GITHUB TAG LATEST VERSION ############################################# ############################################################################## @@ -313,4 +370,4 @@ jobs: release_name: ${{ env.VERSION }} body_path: ./CHANGELOG.md draft: false - prerelease: false \ No newline at end of file + prerelease: false