From d89b9e6cc3ad4991251bea8c2abdfd7878003c9c Mon Sep 17 00:00:00 2001 From: Alex Dyakonov Date: Fri, 24 Jan 2025 15:27:06 +0300 Subject: [PATCH] Updated ci/cd pipelines --- .github/workflows/cd-dev.yaml | 12 +++--- .github/workflows/cd-production.yaml | 56 +++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index a93488c..e9e892e 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -47,7 +47,7 @@ jobs: uses: containrrr/shoutrrr-action@v1 with: url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} - title: "Docker image sent: ${{ env.COMMIT_SHORT_SHA }}" + title: "[DEV] Docker image sent: ${{ env.COMMIT_SHORT_SHA }}" message: | ✅ Docker image for commit: ${{ github.sha }} has been successfully built and pushed to Docker Hub. Branches/tags: dev, ${{ env.COMMIT_SHORT_SHA }}. @@ -62,7 +62,7 @@ jobs: shell: bash run: | response=$(curl -s -o /dev/null -w "%{http_code}" \ - -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}/${{ secrets.SERVICE_HASH }}?tag=dev") + -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}/${{ secrets.SERVICE_HASH_DEV }}?tag=dev") if [ "$response" -ne 204 ]; then echo "Error: expected 204, but got $response" @@ -74,9 +74,9 @@ jobs: uses: containrrr/shoutrrr-action@v1 with: url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} - title: "Deployment of ${{ env.COMMIT_SHORT_SHA }} has been successfully started" + title: "[DEV] Deployment of ${{ env.COMMIT_SHORT_SHA }} has been successfully started" message: | - ✅ Container has been successfully updated via Portainer. + ✅ Container has been successfully updated via Portainer. Commit: ${{ github.sha }} Repository: ${{ github.repository }} @@ -87,9 +87,9 @@ jobs: uses: containrrr/shoutrrr-action@v1 with: url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} - title: "Deployment failed" + title: "[DEV] Deployment failed" message: | ❌ An error occurred during deployment for commit ${{ github.sha }}. Repository: ${{ github.repository }} - Check the pipeline logs for details. + Check the pipeline logs for details. diff --git a/.github/workflows/cd-production.yaml b/.github/workflows/cd-production.yaml index 2fbc982..c1cbad5 100644 --- a/.github/workflows/cd-production.yaml +++ b/.github/workflows/cd-production.yaml @@ -3,10 +3,8 @@ name: cd-prod on: workflow_dispatch: - inputs: - tag_name: - description: Write tag for deploy - required: true + release: + types: [released] jobs: ci-tests: @@ -43,7 +41,53 @@ jobs: ${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:latest ${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:${{ github.event.inputs.tag_name }} - - name: Trigger watchtower to update container(s) + - name: Docker hub push notification + uses: containrrr/shoutrrr-action@v1 + with: + url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} + title: "[PROD] Docker image sent: ${{ env.COMMIT_SHORT_SHA }}" + message: | + ✅ Docker image for commit: ${{ github.sha }} has been successfully built and pushed to Docker Hub. + Branches/tags: latest, ${{ env.VERSION_TAG }}. + + Repository: ${{ github.repository }} + Commit url: https://github.com/${{ github.repository }}/commit/${{ github.sha }} + + Triggering portainer webhook... + + - name: Trigger portainer webhook to update container + id: portainer_webhook shell: bash run: | - curl -H "Authorization: Bearer ${{ secrets.WATCHTOWER_HTTP_API_TOKEN }}" ${{ secrets.WATCHTOWER_UPDATE_ENDPOINT }} + response=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}/${{ secrets.SERVICE_HASH }}?tag=latest") + + if [ "$response" -ne 204 ]; then + echo "Error: expected 204, but got $response" + exit 1 + fi + + - name: Shoutrrr - success + if: ${{ success() }} + uses: containrrr/shoutrrr-action@v1 + with: + url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} + title: "[PROD] Deployment of ${{ env.COMMIT_SHORT_SHA }} has been successfully started" + message: | + ✅ Container has been successfully updated via Portainer. + Commit: ${{ github.sha }} + Repository: ${{ github.repository }} + + Link to commit: https://github.com/${{ github.repository }}/commit/${{ github.sha }} + + - name: Shoutrrr - fail + if: ${{ failure() }} + uses: containrrr/shoutrrr-action@v1 + with: + url: telegram://${{ secrets.ALERTS_TELEGRAM_HTTP_API_TOKEN }}@telegram/?channels=${{ secrets.ALERTS_CHAT_ID }} + title: "[PROD] Deployment failed" + message: | + ❌ An error occurred during deployment for commit ${{ github.sha }}. + Repository: ${{ github.repository }} + + Check the pipeline logs for details. \ No newline at end of file