From 57761aa96f2171caf5e5ad938fef60557ef02fc4 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 20 Jun 2026 22:50:35 -0700 Subject: [PATCH] Fix pipeline: use CI_COMMIT_CHANGED_FILES, --no-interpolate validation, deploy only changed stacks --- .woodpecker.yml | 52 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 22197f0..8bd84a1 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -6,31 +6,39 @@ steps: validate: image: alpine:latest commands: - - apk add --no-cache docker-cli docker-cli-compose git + - apk add --no-cache docker-cli docker-cli-compose - | - CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '\.yaml$' || ls *.yaml) - for f in $CHANGED; do + echo "Changed files: ${CI_COMMIT_CHANGED_FILES}" + YAML_FILES=$(echo "${CI_COMMIT_CHANGED_FILES}" | tr ',' '\n' | grep '\.yaml$' || true) + [ -z "$YAML_FILES" ] && echo "No yaml files changed, skipping" && exit 0 + for f in $YAML_FILES; do [ -f "$f" ] || continue - docker compose -f "$f" config > /dev/null && echo " OK $f" || { echo " FAIL $f"; exit 1; } + echo "Validating $f..." + docker compose -f "$f" --no-interpolate config -q \ + && echo " OK $f" \ + || { echo " FAIL $f"; exit 1; } done deploy: image: alpine:latest commands: - - apk add --no-cache openssh-client git + - apk add --no-cache openssh-client rsync - mkdir -p ~/.ssh - echo "$SSH_KEY" | base64 -d > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H 192.168.4.32 >> ~/.ssh/known_hosts 2>/dev/null - - rsync -av -e "ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa" *.yaml root@192.168.4.32:/volume1/docker/compose-files/ - | - CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '\.yaml$' | sed 's/\.yaml//' || echo "") - [ -z "$CHANGED" ] && echo "No stacks changed" && exit 0 - for STACK in $CHANGED; do + YAML_FILES=$(echo "${CI_COMMIT_CHANGED_FILES}" | tr ',' '\n' | grep '\.yaml$' || true) + [ -z "$YAML_FILES" ] && echo "No yaml files changed" && exit 0 + for f in $YAML_FILES; do + [ -f "$f" ] || continue + STACK=$(basename "$f" .yaml) + rsync -av -e "ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa" \ + "$f" root@192.168.4.32:/volume1/docker/compose-files/ ssh -o StrictHostKeyChecking=no root@192.168.4.32 \ - "cd /volume1/docker/compose-files && \ - set -a && [ -f ${STACK}.env ] && . ./${STACK}.env || true && set +a && \ - docker stack deploy -c ${STACK}.yaml ${STACK}" \ + "cd /volume1/docker/compose-files \ + && set -a && [ -f ${STACK}.env ] && . ./${STACK}.env; set +a \ + && docker stack deploy -c ${STACK}.yaml ${STACK}" \ && echo " OK $STACK" || { echo " FAIL $STACK"; exit 1; } done secrets: [ ssh_key ] @@ -38,29 +46,31 @@ steps: verify: image: alpine:latest commands: - - apk add --no-cache openssh-client git + - apk add --no-cache openssh-client - mkdir -p ~/.ssh - echo "$SSH_KEY" | base64 -d > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H 192.168.4.32 >> ~/.ssh/known_hosts 2>/dev/null - | - CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '\.yaml$' | sed 's/\.yaml//' || echo "") - [ -z "$CHANGED" ] && exit 0 + YAML_FILES=$(echo "${CI_COMMIT_CHANGED_FILES}" | tr ',' '\n' | grep '\.yaml$' || true) + [ -z "$YAML_FILES" ] && exit 0 sleep 5 - for STACK in $CHANGED; do + for f in $YAML_FILES; do + STACK=$(basename "$f" .yaml) echo "--- $STACK ---" ssh -o StrictHostKeyChecking=no root@192.168.4.32 \ - "docker stack ps $STACK --filter desired-state=running --format ' {{.Name}} {{.CurrentState}}'" + "docker stack ps $STACK --filter desired-state=running \ + --format ' {{.Name}} {{.CurrentState}}'" done secrets: [ ssh_key ] notify-success: image: alpine:latest commands: - - apk add --no-cache curl git + - apk add --no-cache curl - | - CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '\.yaml$' | tr '\n' ' ' || echo "unknown") - PAYLOAD=$(printf '{"title":"Swarm Deploy OK","text":"%s","themeColor":"00aa00"}' "$CHANGED") + CHANGED=$(echo "${CI_COMMIT_CHANGED_FILES}" | tr ',' ' ') + PAYLOAD=$(printf '{"title":"Swarm Deploy OK","text":"Stacks: %s Commit: %s","themeColor":"00aa00"}' "$CHANGED" "$CI_COMMIT_MESSAGE") curl -sf -X POST -H 'Content-Type: application/json' -d "$PAYLOAD" "$TEAMS_WEBHOOK" || true secrets: [ teams_webhook ] when: @@ -71,7 +81,7 @@ steps: commands: - apk add --no-cache curl - | - PAYLOAD=$(printf '{"title":"Swarm Deploy FAILED","text":"%s","themeColor":"ff0000"}' "$CI_COMMIT_MESSAGE") + PAYLOAD=$(printf '{"title":"Swarm Deploy FAILED","text":"Commit: %s See: https://woodpecker.bryanmail.net","themeColor":"ff0000"}' "$CI_COMMIT_MESSAGE") curl -sf -X POST -H 'Content-Type: application/json' -d "$PAYLOAD" "$TEAMS_WEBHOOK" || true secrets: [ teams_webhook ] when: