name: Renovate PR Deployment on: workflow_dispatch: pull_request: types: [closed] branches: - main paths: - "**/docker-compose.yml" env: HC_VAULT_VERSION: "1.18.0" VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }} VAULT_TOKEN: ${{ secrets.VAULT_GITEA_TOKEN }} jobs: deploy: if: | github.event.pull_request.merged == true && github.event.pull_request.user.login == 'renovate-bot' runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - name: Install Vault uses: cpanato/vault-installer@main with: version: ${{ env.HC_VAULT_VERSION }} - name: Detect Renovate update type id: detect-update env: PR_BODY: ${{ github.event.pull_request.body }} run: | echo "PR body: $PR_BODY" if echo "$PR_BODY" | grep -qE 'Update Type: (patch|minor|major|digest)'; then echo "update=true" >> $GITHUB_OUTPUT else echo "update=false" >> $GITHUB_OUTPUT fi - name: Stop if update not patch/minor/major/digest if: steps.detect-update.outputs.update != 'true' run: | echo "::warning::This PR does not involve patch/minor/major/digest update. Skipping deployment." exit 0 - name: Save both versions of docker-compose.yml run: | git fetch origin main if git ls-tree -r origin/main --name-only | grep -q '^docker-compose.yml$'; then git show origin/main:docker-compose.yml > docker-compose-main.yml else echo "services: {}" > docker-compose-main.yml fi cp docker-compose.yml docker-compose-head.yml - name: Detect modified services id: detect_services shell: bash run: | set -euo pipefail echo "Getting services from main and head" yq '.services | keys | .[]' docker-compose-main.yml | sort > services_main.txt yq '.services | keys | .[]' docker-compose-head.yml | sort > services_head.txt echo "Creating list of modified services..." : > service_changes.txt comm -12 services_main.txt services_head.txt | while read service; do main_image=$(yq eval --yaml-merge ".services.\"$service\".image // \"\"" docker-compose-main.yml) head_image=$(yq eval --yaml-merge ".services.\"$service\".image // \"\"" docker-compose-head.yml) if [ "$main_image" != "$head_image" ]; then echo "$service" >> service_changes.txt fi done echo "Detected modified services:" cat service_changes.txt || true mod_svcs=$(sort -u service_changes.txt | xargs echo -n) echo "docker_svc_list=$mod_svcs" >> "$GITHUB_OUTPUT" - name: List of Services for (Re)Deployment run: | echo -e "${{ steps.services.outputs.docker_svc_list }}" - name: Generate .env file for Docker Compose run: | vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env - name: Gotify Notification uses: eikendev/gotify-action@master with: gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}" gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}" notification_title: "GITEA: [RENOVATE] Docker Compose Deployment @ Rinoa" notification_message: "Starting Docker Compose run..." - name: Login to Docker Hub uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 with: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Login to GitHub Container Registry uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 with: registry: ghcr.io username: ${{ secrets.GHCR_USER }} password: ${{ secrets.GHCR_LOGIN_TOKEN }} - name: Login to Private Gitea Registry uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 with: registry: git.trez.wtf username: ${{ secrets.BOT_GITEA_USER }} password: ${{ secrets.BOT_GITEA_PASSWORD }} - name: Docker Compose Deployment uses: hoverkraft-tech/compose-action@40041ff1b97dbf152cd2361138c2b03fa29139df # v2.3.0 env: DOCKER_HOST: tcp://dockerproxy:2375 with: services: | ${{ steps.services.outputs.docker_svc_list }} up-flags: -d --remove-orphans --pull always compose-flags: --profile rinoa-apps - name: Docker Compose Healthcheck id: health uses: jaracogmbh/docker-compose-health-check-action@973fbdccf7c8e396b652d3501984c8e530a9fa80 # v1.0.0 with: max-retries: 30 retry-interval: 10 compose-file: "docker-compose.yml" skip-exited: "true" skip-no-healthcheck: "true" - name: Gotify Notification uses: eikendev/gotify-action@master with: gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}" gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}" notification_title: "GITEA: [RENOVATE] Docker Compose Deployment @ Rinoa" notification_message: "Deployment completed successfully."