Files
compose-files/.woodpecker.yml
T
2026-06-20 22:50:42 -07:00

89 lines
3.3 KiB
YAML

when:
- event: push
branch: main
steps:
validate:
image: alpine:latest
commands:
- apk add --no-cache docker-cli docker-cli-compose
- |
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
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 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
- |
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; set +a \
&& docker stack deploy -c ${STACK}.yaml ${STACK}" \
&& echo " OK $STACK" || { echo " FAIL $STACK"; exit 1; }
done
secrets: [ ssh_key ]
verify:
image: alpine:latest
commands:
- 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
- |
YAML_FILES=$(echo "${CI_COMMIT_CHANGED_FILES}" | tr ',' '\n' | grep '\.yaml$' || true)
[ -z "$YAML_FILES" ] && exit 0
sleep 5
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}}'"
done
secrets: [ ssh_key ]
notify-success:
image: alpine:latest
commands:
- apk add --no-cache curl
- |
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:
- status: success
notify-failure:
image: alpine:latest
commands:
- apk add --no-cache curl
- |
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:
- status: failure