cd-prod #14
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: cd-prod | |
on: | |
workflow_dispatch: | |
release: | |
types: [released] | |
jobs: | |
ci-tests: | |
uses: ./.github/workflows/ci-tests.yaml | |
push_to_registry: | |
name: Push Docker image to Docker Hub | |
needs: [ci-tests] | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
attestations: write | |
id-token: write | |
steps: | |
- name: Fail if not on main branch or release tag | |
if: github.ref != 'refs/heads/main' && github.event.release.tag_name == '' | |
run: | | |
echo "This workflow should only run on the 'main' branch or for a release with a tag name." | |
exit 1 | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV | |
- name: Determine Version tag | |
id: tag | |
run: | | |
if [ "${{ github.event_name }}" == "release" ]; then | |
echo "VERSION_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
else | |
echo "VERSION_TAG=${{ env.COMMIT_SHORT_SHA }}" >> $GITHUB_ENV | |
fi | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
id: push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:latest | |
${{ secrets.DOCKER_USERNAME }}/dishdash-dashboard:${{ env.VERSION_TAG }} | |
- 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: | | |
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. |