claude attempt
This commit is contained in:
parent
2bce69f114
commit
3a7400b7c8
1 changed files with 109 additions and 109 deletions
|
|
@ -5,145 +5,145 @@ on:
|
||||||
branches: ["master"]
|
branches: ["master"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
detect:
|
deploy_swarm:
|
||||||
runs-on: docker2
|
runs-on: docker2
|
||||||
outputs:
|
container:
|
||||||
swarm_files: ${{ steps.changes.outputs.swarm_files }}
|
image: docker:27-cli
|
||||||
compose_matrix: ${{ steps.changes.outputs.compose_matrix }}
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository (git clone, no node)
|
- name: Checkout repository
|
||||||
shell: bash
|
shell: sh
|
||||||
env:
|
env:
|
||||||
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
BRANCH: ${{ github.ref_name }}
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -e
|
||||||
rm -rf repo
|
git clone --branch "$BRANCH" --depth 1 "$CLONE_URL" repo
|
||||||
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
|
||||||
cd repo
|
cd repo
|
||||||
# Ensure exact commit for this run
|
|
||||||
git fetch --depth 50 origin "${{ github.sha }}"
|
|
||||||
git checkout -q "${{ github.sha }}"
|
git checkout -q "${{ github.sha }}"
|
||||||
|
|
||||||
- name: Detect changed YAML files
|
- name: Detect and deploy swarm stacks
|
||||||
id: changes
|
shell: sh
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -e
|
||||||
cd repo
|
cd repo
|
||||||
|
|
||||||
BASE="${{ github.event.before }}"
|
BASE="${{ github.event.before }}"
|
||||||
HEAD="${{ github.sha }}"
|
HEAD="${{ github.sha }}"
|
||||||
|
|
||||||
|
# Handle first commit or missing base
|
||||||
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
|
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
|
||||||
BASE="$(git rev-parse "${HEAD}~1" || true)"
|
git fetch --depth 2 origin "$HEAD"
|
||||||
|
BASE="$(git rev-parse "${HEAD}~1" 2>/dev/null || echo "")"
|
||||||
|
else
|
||||||
|
git fetch --depth 1 origin "$BASE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$BASE" ]; then
|
if [ -z "$BASE" ]; then
|
||||||
echo "No base commit found; deploying nothing."
|
echo "No base commit found; skipping swarm deployment."
|
||||||
echo "swarm_files=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo 'compose_matrix={"include":[]}' >> "$GITHUB_OUTPUT"
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHANGED="$(git diff --name-only "$BASE" "$HEAD" || true)"
|
# Find changed swarm files
|
||||||
echo "Changed files:"
|
SWARM_FILES="$(git diff --name-only "$BASE" "$HEAD" | grep -E '^swarm/.*\.ya?ml$' || true)"
|
||||||
echo "$CHANGED"
|
|
||||||
|
if [ -z "$SWARM_FILES" ]; then
|
||||||
# Swarm stack YAMLs
|
echo "No swarm stack changes detected."
|
||||||
SWARM_FILES="$(echo "$CHANGED" | grep -E '^swarm/.*\.ya?ml$' || true)"
|
exit 0
|
||||||
echo "swarm_files=$(echo "$SWARM_FILES" | xargs)" >> "$GITHUB_OUTPUT"
|
fi
|
||||||
|
|
||||||
# Compose YAMLs: services/compose/<host>/<service>/<file>.yml
|
echo "Changed swarm files: $SWARM_FILES"
|
||||||
COMPOSE_FILES="$(echo "$CHANGED" | grep -E '^services/compose/[^/]+/[^/]+/.*\.ya?ml$' || true)"
|
|
||||||
|
# Validate and deploy each stack
|
||||||
JSON='{"include":['
|
for f in $SWARM_FILES; do
|
||||||
FIRST=1
|
if [ ! -f "$f" ]; then
|
||||||
while read -r FILE; do
|
echo "Warning: $f not found, skipping"
|
||||||
[ -z "$FILE" ] && continue
|
continue
|
||||||
HOST="$(echo "$FILE" | awk -F/ '{print $3}')"
|
fi
|
||||||
if [ $FIRST -eq 0 ]; then JSON+=','; fi
|
|
||||||
FIRST=0
|
|
||||||
JSON+="{\"host\":\"$HOST\",\"file\":\"$FILE\"}"
|
|
||||||
done <<< "$COMPOSE_FILES"
|
|
||||||
JSON+=']}'
|
|
||||||
|
|
||||||
echo "compose_matrix=$JSON" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "compose_matrix=$JSON"
|
|
||||||
|
|
||||||
deploy_swarm:
|
|
||||||
needs: detect
|
|
||||||
if: ${{ needs.detect.outputs.swarm_files != '' }}
|
|
||||||
runs-on: docker2
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository (git clone, no node)
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
|
||||||
BRANCH: ${{ github.ref_name }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
rm -rf repo
|
|
||||||
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
|
||||||
cd repo
|
|
||||||
git fetch --depth 50 origin "${{ github.sha }}"
|
|
||||||
git checkout -q "${{ github.sha }}"
|
|
||||||
|
|
||||||
- name: Validate swarm stacks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
cd repo
|
|
||||||
for f in ${{ needs.detect.outputs.swarm_files }}; do
|
|
||||||
echo "Validating swarm stack file: $f"
|
|
||||||
docker stack config -c "$f" >/dev/null
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Deploy swarm stacks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
cd repo
|
|
||||||
for f in ${{ needs.detect.outputs.swarm_files }}; do
|
|
||||||
STACK="$(basename "$f" | sed 's/\.ya\?ml$//')"
|
STACK="$(basename "$f" | sed 's/\.ya\?ml$//')"
|
||||||
echo "Deploying swarm stack: $STACK from $f"
|
echo "Validating stack: $STACK"
|
||||||
|
docker stack config -c "$f" >/dev/null
|
||||||
|
|
||||||
|
echo "Deploying stack: $STACK"
|
||||||
docker stack deploy -c "$f" "$STACK"
|
docker stack deploy -c "$f" "$STACK"
|
||||||
done
|
done
|
||||||
|
|
||||||
deploy_compose:
|
deploy_compose:
|
||||||
needs: detect
|
runs-on: docker2
|
||||||
if: ${{ needs.detect.outputs.compose_matrix != '' }}
|
container:
|
||||||
strategy:
|
image: docker:27-cli
|
||||||
fail-fast: false
|
volumes:
|
||||||
matrix: ${{ fromJSON(needs.detect.outputs.compose_matrix) }}
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
runs-on: ${{ matrix.host }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository (git clone, no node)
|
- name: Install docker compose
|
||||||
shell: bash
|
shell: sh
|
||||||
|
run: apk add --no-cache docker-cli-compose
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
shell: sh
|
||||||
env:
|
env:
|
||||||
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
BRANCH: ${{ github.ref_name }}
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -e
|
||||||
rm -rf repo
|
git clone --branch "$BRANCH" --depth 1 "$CLONE_URL" repo
|
||||||
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
|
||||||
cd repo
|
cd repo
|
||||||
git fetch --depth 50 origin "${{ github.sha }}"
|
|
||||||
git checkout -q "${{ github.sha }}"
|
git checkout -q "${{ github.sha }}"
|
||||||
|
|
||||||
- name: Validate compose file
|
- name: Detect and deploy compose files
|
||||||
shell: bash
|
shell: sh
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -e
|
||||||
cd repo
|
cd repo
|
||||||
echo "Validating compose file: ${{ matrix.file }}"
|
|
||||||
docker compose -f "${{ matrix.file }}" config -q
|
BASE="${{ github.event.before }}"
|
||||||
|
HEAD="${{ github.sha }}"
|
||||||
- name: Deploy compose file
|
|
||||||
shell: bash
|
# Handle first commit or missing base
|
||||||
run: |
|
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
|
||||||
set -euo pipefail
|
git fetch --depth 2 origin "$HEAD"
|
||||||
cd repo
|
BASE="$(git rev-parse "${HEAD}~1" 2>/dev/null || echo "")"
|
||||||
echo "Deploying compose file: ${{ matrix.file }}"
|
else
|
||||||
docker compose -f "${{ matrix.file }}" pull
|
git fetch --depth 1 origin "$BASE"
|
||||||
docker compose -f "${{ matrix.file }}" up -d --remove-orphans
|
fi
|
||||||
|
|
||||||
|
if [ -z "$BASE" ]; then
|
||||||
|
echo "No base commit found; skipping compose deployment."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find changed compose files
|
||||||
|
COMPOSE_FILES="$(git diff --name-only "$BASE" "$HEAD" | grep -E '^services/compose/[^/]+/[^/]+/.*\.ya?ml$' || true)"
|
||||||
|
|
||||||
|
if [ -z "$COMPOSE_FILES" ]; then
|
||||||
|
echo "No compose file changes detected."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Changed compose files: $COMPOSE_FILES"
|
||||||
|
|
||||||
|
# Group files by host and deploy
|
||||||
|
echo "$COMPOSE_FILES" | while read -r FILE; do
|
||||||
|
[ -z "$FILE" ] && continue
|
||||||
|
|
||||||
|
if [ ! -f "$FILE" ]; then
|
||||||
|
echo "Warning: $FILE not found, skipping"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
HOST="$(echo "$FILE" | awk -F/ '{print $3}')"
|
||||||
|
|
||||||
|
# Only deploy if we're on the correct host
|
||||||
|
if [ "$HOST" = "docker2" ] || [ "$HOST" = "$(hostname)" ]; then
|
||||||
|
echo "Validating: $FILE"
|
||||||
|
docker compose -f "$FILE" config -q
|
||||||
|
|
||||||
|
echo "Deploying: $FILE"
|
||||||
|
docker compose -f "$FILE" pull
|
||||||
|
docker compose -f "$FILE" up -d --remove-orphans
|
||||||
|
else
|
||||||
|
echo "Skipping $FILE (requires host: $HOST)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
Loading…
Add table
Add a link
Reference in a new issue