deploy
This commit is contained in:
parent
f0a319d470
commit
036abbff30
1 changed files with 38 additions and 12 deletions
|
|
@ -11,19 +11,26 @@ jobs:
|
||||||
swarm_files: ${{ steps.changes.outputs.swarm_files }}
|
swarm_files: ${{ steps.changes.outputs.swarm_files }}
|
||||||
compose_matrix: ${{ steps.changes.outputs.compose_matrix }}
|
compose_matrix: ${{ steps.changes.outputs.compose_matrix }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository (no node)
|
- name: Checkout repository (git clone, no node)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
git config --global --add safe.directory "$PWD"
|
rm -rf repo
|
||||||
git fetch origin
|
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
||||||
git checkout -B "$GITHUB_REF_NAME" "origin/$GITHUB_REF_NAME"
|
cd repo
|
||||||
|
# Ensure exact commit for this run
|
||||||
|
git fetch --depth 50 origin "${{ github.sha }}"
|
||||||
|
git checkout -q "${{ github.sha }}"
|
||||||
|
|
||||||
- name: Detect changed YAML files
|
- name: Detect changed YAML files
|
||||||
id: changes
|
id: changes
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
cd repo
|
||||||
|
|
||||||
BASE="${{ github.event.before }}"
|
BASE="${{ github.event.before }}"
|
||||||
HEAD="${{ github.sha }}"
|
HEAD="${{ github.sha }}"
|
||||||
|
|
@ -62,25 +69,33 @@ jobs:
|
||||||
JSON+=']}'
|
JSON+=']}'
|
||||||
|
|
||||||
echo "compose_matrix=$JSON" >> "$GITHUB_OUTPUT"
|
echo "compose_matrix=$JSON" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "compose_matrix=$JSON"
|
||||||
|
|
||||||
deploy_swarm:
|
deploy_swarm:
|
||||||
needs: detect
|
needs: detect
|
||||||
if: ${{ needs.detect.outputs.swarm_files != '' }}
|
if: ${{ needs.detect.outputs.swarm_files != '' }}
|
||||||
runs-on: docker2
|
runs-on: docker2
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository (no node)
|
- name: Checkout repository (git clone, no node)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
git config --global --add safe.directory "$PWD"
|
rm -rf repo
|
||||||
git fetch origin
|
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
||||||
git checkout -B "$GITHUB_REF_NAME" "origin/$GITHUB_REF_NAME"
|
cd repo
|
||||||
|
git fetch --depth 50 origin "${{ github.sha }}"
|
||||||
|
git checkout -q "${{ github.sha }}"
|
||||||
|
|
||||||
- name: Validate swarm stacks
|
- name: Validate swarm stacks
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
cd repo
|
||||||
for f in ${{ needs.detect.outputs.swarm_files }}; do
|
for f in ${{ needs.detect.outputs.swarm_files }}; do
|
||||||
|
echo "Validating swarm stack file: $f"
|
||||||
docker stack config -c "$f" >/dev/null
|
docker stack config -c "$f" >/dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -88,8 +103,10 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
cd repo
|
||||||
for f in ${{ needs.detect.outputs.swarm_files }}; do
|
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"
|
||||||
docker stack deploy -c "$f" "$STACK"
|
docker stack deploy -c "$f" "$STACK"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -101,23 +118,32 @@ jobs:
|
||||||
matrix: ${{ fromJSON(needs.detect.outputs.compose_matrix) }}
|
matrix: ${{ fromJSON(needs.detect.outputs.compose_matrix) }}
|
||||||
runs-on: ${{ matrix.host }}
|
runs-on: ${{ matrix.host }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository (no node)
|
- name: Checkout repository (git clone, no node)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
CLONE_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
git config --global --add safe.directory "$PWD"
|
rm -rf repo
|
||||||
git fetch origin
|
git clone --branch "$BRANCH" --depth 50 "$CLONE_URL" repo
|
||||||
git checkout -B "$GITHUB_REF_NAME" "origin/$GITHUB_REF_NAME"
|
cd repo
|
||||||
|
git fetch --depth 50 origin "${{ github.sha }}"
|
||||||
|
git checkout -q "${{ github.sha }}"
|
||||||
|
|
||||||
- name: Validate compose file
|
- name: Validate compose file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
cd repo
|
||||||
|
echo "Validating compose file: ${{ matrix.file }}"
|
||||||
docker compose -f "${{ matrix.file }}" config -q
|
docker compose -f "${{ matrix.file }}" config -q
|
||||||
|
|
||||||
- name: Deploy compose file
|
- name: Deploy compose file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
cd repo
|
||||||
|
echo "Deploying compose file: ${{ matrix.file }}"
|
||||||
docker compose -f "${{ matrix.file }}" pull
|
docker compose -f "${{ matrix.file }}" pull
|
||||||
docker compose -f "${{ matrix.file }}" up -d --remove-orphans
|
docker compose -f "${{ matrix.file }}" up -d --remove-orphans
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue