123 lines
4.4 KiB
YAML
123 lines
4.4 KiB
YAML
name: Renovate Image Tag Deployment
|
|
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
branches:
|
|
- main
|
|
paths:
|
|
- "**/docker-compose.yml"
|
|
|
|
env:
|
|
HC_VAULT_VERSION: "1.20.4"
|
|
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: Checkout full repository
|
|
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
|
with:
|
|
fetch-depth: 0 # required so we can access main^1
|
|
|
|
- name: Install Vault
|
|
uses: cpanato/vault-installer@main
|
|
with:
|
|
version: ${{ env.HC_VAULT_VERSION }}
|
|
|
|
- name: Save docker-compose.yml before merge (old)
|
|
run: |
|
|
git fetch origin main
|
|
if git ls-tree -r origin/main^1 --name-only | grep -q '^docker-compose.yml$'; then
|
|
git show origin/main^1:docker-compose.yml > docker-compose-old.yml
|
|
else
|
|
echo "services: {}" > docker-compose-old.yml
|
|
fi
|
|
|
|
- name: Save docker-compose.yml after merge (new)
|
|
run: |
|
|
git show origin/main:docker-compose.yml > docker-compose-new.yml
|
|
|
|
- name: Detect services with image tag/digest changes
|
|
id: detect_services
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "Flattening docker-compose files..."
|
|
yq eval '... comments=""' docker-compose-old.yml > docker-compose-old-flat.yml
|
|
yq eval '... comments=""' docker-compose-new.yml > docker-compose-new-flat.yml
|
|
|
|
echo "Getting service names..."
|
|
yq eval '.services | keys | .[]' docker-compose-old-flat.yml | sort > services_old.txt
|
|
yq eval '.services | keys | .[]' docker-compose-new-flat.yml | sort > services_new.txt
|
|
|
|
echo "Checking for image changes..."
|
|
: > service_changes.txt
|
|
|
|
comm -12 services_old.txt services_new.txt | while read service; do
|
|
old_image=$(yq eval ".services[\"$service\"].image // \"\"" docker-compose-old-flat.yml)
|
|
new_image=$(yq eval ".services[\"$service\"].image // \"\"" docker-compose-new-flat.yml)
|
|
|
|
if [ "$old_image" != "$new_image" ]; then
|
|
echo "$service" >> service_changes.txt
|
|
fi
|
|
done
|
|
|
|
echo "Detected services with changed images:"
|
|
cat service_changes.txt || true
|
|
|
|
mod_svcs=$(sort -u service_changes.txt | xargs echo -n)
|
|
echo "docker_svc_list=$mod_svcs" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Stop if no image changes
|
|
if: steps.detect_services.outputs.docker_svc_list == ''
|
|
run: |
|
|
echo "No image tag/digest changes detected. Exiting."
|
|
exit 0
|
|
|
|
- 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 (Start)
|
|
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: Docker Compose Deployment
|
|
uses: hoverkraft-tech/compose-action@b716db5b717cb9b81e391fe638e5aceaa2299e43 # v2.4.0
|
|
env:
|
|
DOCKER_HOST: tcp://dockerproxy:2375
|
|
with:
|
|
services: |
|
|
${{ steps.detect_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 (Finish)
|
|
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."
|