chore: deploy script for all services
Deploy bin / deploy (push) Successful in 4s
Deploy, build and restart a service / deploy (push) Failing after 5s
Deploy agebd python package / deploy (push) Successful in 3s

This commit is contained in:
Benjamin Labrecque
2026-07-06 16:28:52 +02:00
parent d04aeff4c2
commit cb51f0f227
6 changed files with 93 additions and 61 deletions
+5 -2
View File
@@ -4,6 +4,9 @@ on:
push:
branches:
- main
tags:
- 'prod'
- 'v*'
# paths:
# - 'bin/**'
@@ -15,8 +18,8 @@ jobs:
working-directory: ./bin
env:
# TODO: prod/dev
DEST_DIR: /sls/bd/hla/dev/bin
# commit tagged ? yes->prod : no->dev
DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/bin
steps:
- name: Checkout repository
@@ -0,0 +1,80 @@
name: Deploy, build and restart a service
on:
push:
# TODO: if someone tags 'prod' to a (broken) feature branch
# this still triggers (and deploys to prod).
branches:
- main
tags:
- 'prod'
- 'v*'
jobs:
deploy:
runs-on: hla-dev
env:
# commit tagged ? yes->prod : no->dev
AGEBD_ENV: ${{ github.ref_type == 'tag' && 'prod' || 'dev' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# - name: Copy files and replace {{ agebd_env }} with dev or prod
# run: |
# mkdir -p ${SVC_CURRRENT_DIR}
# cp -r 000-master/* ${SVC_CURRRENT_DIR}
# sed -i 's/{{ agebd_env }}/${AGEBD_ENV}/g' ${SVC_CURRRENT_DIR}/systemd/AGEBD-SERVICE-MASTER.service
# - name: Create Python venv
# run: |
# cd ${SVC_CURRRENT_DIR}/app
# uv venv --allow-existing --system-site-packages .venv
# uv sync
# - name: Restart Service
# run: |
# export XDG_RUNTIME_DIR=/run/user/$(id -u)
# systemctl --user daemon-reload
# systemctl --user enable --force ${SVC_CURRRENT_DIR}/systemd/AGEBD-SERVICE-MASTER.service
# systemctl --user restart AGEBD-SERVICE-MASTER.service
- name: Detect and Deploy Changed Services
run: |
# 1. Identify which directories under 'services/' changed in this push
CHANGED_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep "^services/" | awk -F/ '{print $2}' | sort -u)
if [ -z "$CHANGED_DIRS" ]; then
echo "No service files changed. Skipping deployment."
exit 0
fi
# 2. Set up environment
export XDG_RUNTIME_DIR=/run/user/$(id -u)
# 3. Loop and deploy ONLY the changed services
for SERVICE in $CHANGED_DIRS; do
echo "Deploying detected changes for: $SERVICE"
SVC_CURRENT_DIR="/sls/bd/hla/${AGEBD_ENV}/services/${SERVICE}/current"
# Run your standard deployment blocks dynamically targeting $SERVICE
mkdir -p ${SVC_CURRENT_DIR}
cp -r services/${SERVICE}/* ${SVC_CURRENT_DIR}
# Build python venv
cd ${SVC_CURRRENT_DIR}/app
uv venv --allow-existing --system-site-packages .venv
uv sync
# Uppercase service name for systemd conversion, skip first 4 chars, then upper (000-master -> MASTER)
SVC_UPPER=$(echo "${SERVICE:4}" | tr '[:lower:]' '[:upper:]')
sed -i "s/{{ agebd_env }}/${AGEBD_ENV}/g" ${SVC_CURRENT_DIR}/systemd/AGEBD-SERVICE-${SVC_UPPER}.service
systemctl --user daemon-reload
systemctl --user enable --force ${SVC_CURRENT_DIR}/systemd/AGEBD-SERVICE-${SVC_UPPER}.service
systemctl --user restart AGEBD-SERVICE-${SVC_UPPER}.service
done
+7 -4
View File
@@ -5,8 +5,11 @@ on:
push:
branches:
- main
paths:
- 'packages/agebd/**'
tags:
- 'prod'
- 'v*'
# paths:
# - 'packages/agebd/**'
jobs:
deploy:
@@ -16,8 +19,8 @@ jobs:
working-directory: ./packages/agebd
env:
# TODO: prod/dev
DEST_DIR: /sls/bd/hla/dev/packages/agebd
# commit tagged ? yes->prod : no->dev
DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/packages/agebd
steps:
- name: Checkout repository
-48
View File
@@ -1,48 +0,0 @@
name: Deploy service MASTER
on:
push:
# TODO: if someone tags 'prod' to a (broken) feature branch
# this still triggers (and deploys to prod).
branches:
- main
tags:
- 'prod'
- 'v*'
# paths:
# - 'services/000-master/**'
jobs:
deploy:
runs-on: hla-dev
defaults:
run:
working-directory: ./services
env:
# commit tagged ? yes->prod : no->dev
AGEBD_ENV: ${{ github.ref_type == 'tag' && 'prod' || 'dev' }}
SVC_CURRRENT_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/services/000-master/current
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Copy files and replace {{ agebd_env }} with dev or prod
run: |
mkdir -p ${SVC_CURRRENT_DIR}
cp -r 000-master/* ${SVC_CURRRENT_DIR}
sed -i 's/{{ agebd_env }}/dev/g' ${SVC_CURRRENT_DIR}/systemd/AGEBD-SERVICE-MASTER.service
- name: Create Python venv
run: |
cd ${SVC_CURRRENT_DIR}/app
uv venv --allow-existing --system-site-packages .venv
uv sync
- name: Restart Service
run: |
export XDG_RUNTIME_DIR=/run/user/$(id -u)
systemctl --user daemon-reload
systemctl --user enable --force ${SVC_CURRRENT_DIR}/systemd/AGEBD-SERVICE-MASTER.service
systemctl --user restart AGEBD-SERVICE-MASTER.service
+1 -7
View File
@@ -2,10 +2,4 @@
# being installed on machine.
- name: Restart Master IOC
import_playbook: plays/restart-master-ioc.yml
- name: Phase 2 - Provision and Render New Services
import_playbook: plays/provision_services.yml
- name: Phase 3 - Restart and Verify IOCs
import_playbook: plays/restart_iocs.yml
import_playbook: plays/restart-master-ioc.yml