From e5142c080cf8c0ec69668dffd4814188d7437c26 Mon Sep 17 00:00:00 2001 From: Alex Dyakonov Date: Wed, 22 Jan 2025 19:43:40 +0300 Subject: [PATCH] fixed ci/cd for dev --- .github/workflows/cd-dev.yaml | 54 +++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index 4db613d..dfc301c 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,9 +1,6 @@ name: cd-dev -on: - push: - branches: - - dev +on: [workflow_dispatch] jobs: ci-tests: @@ -46,8 +43,53 @@ jobs: ${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:dev ${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:dev-${{ env.COMMIT_SHORT_SHA }} - - name: Trigger Watchtower to update dev container + - 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: "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 }}. + + 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_DEV }} + response=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}/${{ secrets.SERVICE_HASH }}?tag=dev") + + 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: "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: "Deployment failed" + message: | + ❌ An error occurred during deployment for commit ${{ github.sha }}. + Repository: ${{ github.repository }} + + Check the pipeline logs for details.