migrate add new service
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
name: Add new service
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'feature/add-service-*'
|
||||
|
||||
# TODO: when to deploy to prod? Manual (i.e. cli command)?
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: hla-dev
|
||||
|
||||
env:
|
||||
ANSIBLE_CONFIG: "${{ github.workspace }}/ansible/ansible.cfg"
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install and setup uv
|
||||
uses: actions/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
|
||||
with:
|
||||
version: "latest"
|
||||
enable-cache: true # Speeds up runs by caching python dependencies # TODO: does this work?
|
||||
|
||||
- name: Install Python 3.10
|
||||
run: uv python install 3.10
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
cd cli && uv run pytest
|
||||
|
||||
- name: Parse Service Directory Name
|
||||
id: parse_branch
|
||||
# Uses bash shell parameter elimination to strip 'feature/add-service-' from the front
|
||||
run: |
|
||||
BRANCH="${{ github.ref_name }}"
|
||||
SERVICE_NAME="${BRANCH#feature/add-service-}"
|
||||
echo "service_name_lower=$SERVICE_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
# TODO: look into venv caching (will do later in case we move from uv to pixi)
|
||||
# - name: Cache Python Virtual Environment
|
||||
# uses: actions/cache@v4
|
||||
# with:
|
||||
# path: .venv
|
||||
# # Changes uv.lock will automatically invalidate the cache and rebuild
|
||||
# key: ${{ runner.os }}-uv-cli-venv-${{ hashFiles('cli/uv.lock') }}
|
||||
# restore-keys: |
|
||||
# ${{ runner.os }}-uv-cli-venv-
|
||||
|
||||
# # Only create the venv if the cache didn't restore an existing one
|
||||
# if [ ! -d ".venv" ]; then
|
||||
# echo "Building new .venv"
|
||||
# uv venv .venv
|
||||
# fi
|
||||
- name: Initialize Virtual Environment from cli/uv.lock
|
||||
run: |
|
||||
uv venv .venv
|
||||
uv sync --directory cli
|
||||
|
||||
- name: Install Ansible Galaxy Collections
|
||||
run: |
|
||||
uv run ansible-galaxy collection install -r ansible/collections/requirements.yml -p ./ansible/installed-collections
|
||||
|
||||
# TODO: dev/prod
|
||||
- name: Run New Service Playbook
|
||||
working-directory: ansible
|
||||
run: |
|
||||
uv run ansible-playbook playbooks/add-new-service.yml \
|
||||
-i "inventories/dev/hosts.yml" \
|
||||
--extra-vars="repo_root=${{ github.workspace }}" \
|
||||
--extra-vars="service_name_lower=${{ steps.parse_branch.outputs.service_name_lower }}" \
|
||||
-v
|
||||
@@ -34,3 +34,20 @@ jobs:
|
||||
BRANCH="${{ github.ref_name }}"
|
||||
SERVICE_NAME="${BRANCH#feature/add-service-}"
|
||||
echo "service_name_lower=$SERVICE_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
# - name: Install Master IOC
|
||||
|
||||
# - name: Restart Master IOC
|
||||
|
||||
- name: Deploy and Restart Master Service
|
||||
run: |
|
||||
./.gitea/scripts/deploy-and-restart-service.sh "master" "dev"
|
||||
|
||||
# - name: Install New IOC
|
||||
|
||||
# - name: Start New IOC
|
||||
|
||||
- name: Deploy and Restart New Service
|
||||
run: |
|
||||
SERVICE_NAME=${{ steps.parse_branch.outputs.service_name_lower }}
|
||||
./.gitea/scripts/deploy-and-restart-service.sh "${SERVICE_NAME}" "dev"
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# name: Deploy agebd python package to gitea/pypi
|
||||
#
|
||||
# # TODO: services depend on this workflow
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# paths:
|
||||
# - 'packages/agebd/**'
|
||||
#
|
||||
# jobs:
|
||||
# deploy:
|
||||
# runs-on: hla-dev
|
||||
@@ -1,63 +0,0 @@
|
||||
name: Service Deployer
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
service_name:
|
||||
required: true
|
||||
type: string
|
||||
description: "Target service name lower (e.g. master)"
|
||||
environment:
|
||||
required: true
|
||||
type: string
|
||||
# default: "dev"
|
||||
description: "Target deployment environment: 'dev' or 'prod'"
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Resolve service name parameters
|
||||
id: vars
|
||||
run: |
|
||||
SERVICE_NAME="${{ inputs.service_name }}"
|
||||
SERVICE_NAME_LOWER=$(echo "$SERVICE_NAME" | tr '[:upper:]' '[:lower:]')
|
||||
SERVICE_NAME_UPPER=$(echo "$SERVICE_NAME" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
echo "service_name_lower=$SERVICE_NAME_LOWER" >> $GITHUB_OUTPUT
|
||||
echo "service_name_upper=$SERVICE_NAME_UPPER" >> $GITHUB_OUTPUT
|
||||
echo "systemd_unit_name=AGEBD-SERVICE-${SERVICE_NAME_UPPER}.service" >> $GITHUB_OUTPUT
|
||||
echo "service_dir=/sls/bd/hla/${{ inputs.environment }}/services/${SERVICE_NAME_LOWER}/current" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Ensure service directory exists
|
||||
run: |
|
||||
mkdir -p ${{ steps.vars.outputs.service_dir }}
|
||||
|
||||
- name: Sync service deployment files
|
||||
run: |
|
||||
rsync -avz --delete --exclude='.venv' \
|
||||
./services/${{ steps.vars.outputs.service_name_lower }}/current/ \
|
||||
${{ steps.vars.outputs.service_dir }}/
|
||||
|
||||
- name: Substitute environment variables & setup systemd service
|
||||
run: |
|
||||
SERVICE_DIR="${{ steps.vars.outputs.service_dir }}"
|
||||
SYSTEMD_UNIT_NAME="${{ steps.vars.outputs.systemd_unit_name }}"
|
||||
AGEBD_ENV="${{ inputs.environment }}"
|
||||
|
||||
SYSTEMD_UNIT_FILE_PATH="${SERVICE_DIR}/systemd/${SYSTEMD_UNIT_NAME}"
|
||||
if [ -f "\$SYSTEMD_UNIT_FILE_PATH" ]; then
|
||||
sed -i "s/{{ *agebd_env *}}/${AGEBD_ENV}/g" "\$SYSTEMD_UNIT_FILE_PATH"
|
||||
fi
|
||||
|
||||
mkdir -p ~/.config/systemd/user
|
||||
ln -sf "\$SYSTEMD_UNIT_FILE_PATH" "~/.config/systemd/user/${SYSTEMD_UNIT_NAME}"
|
||||
|
||||
export XDG_RUNTIME_DIR="/run/user/\$(id -u)"
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable "${SYSTEMD_UNIT_NAME}"
|
||||
systemctl --user restart "${SYSTEMD_UNIT_NAME}"
|
||||
@@ -107,9 +107,5 @@ jobs:
|
||||
|
||||
# 3. Loop through changed services and invoke deployment script
|
||||
echo "$CHANGED_SERVICES" | while read -r SERVICE; do
|
||||
echo "=========================================="
|
||||
echo "Deploying service: ${SERVICE} (${AGEBD_ENV})"
|
||||
echo "=========================================="
|
||||
|
||||
./.gitea/scripts/deploy-service.sh "${SERVICE}" "${AGEBD_ENV}"
|
||||
./.gitea/scripts/deploy-and-restart-service.sh "${SERVICE}" "${AGEBD_ENV}"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user