This commit is contained in:
30
.gitea/workflows/deploy-containers.yml
Normal file
30
.gitea/workflows/deploy-containers.yml
Normal file
@ -0,0 +1,30 @@
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Prepare Build
|
||||
runs-on: homelab-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Deploy containers
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_KNOWN_HOSTS }}" >> ~/.ssh/known_hosts
|
||||
chmod 644 ~/.ssh/known_hosts
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add <(echo "${{ secrets.SSH_PRIVATE_KEY }}")
|
||||
echo "HOST *" > ~/.ssh/config
|
||||
echo "StrictHostKeyChecking no" >> ~/.ssh/config
|
||||
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > ~/.vault_password.txt
|
||||
echo "nameserver 10.10.10.1" > /etc/resolv.conf
|
||||
ansible-galaxy install oefenweb.fail2ban
|
||||
./.gitea/workflows/deploy.sh "${{ github.event.before }}" "${{ github.sha }}"
|
13
.gitea/workflows/deploy.sh
Executable file
13
.gitea/workflows/deploy.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
changed_tasks=($(git diff --name-only $1 $2 | grep '\.yml$'))
|
||||
if [ ! -z "$changed_tasks" ]; then
|
||||
for task in "${changed_tasks[@]}"; do
|
||||
tag=$(echo "$task" | awk -F/ '{print $2}')
|
||||
if [[ "$tag" != "deploy-homelab.yml" && "$tag" != "main.yml" && "$tag" != "all.yml" && "$tag" != "all.example.yml" && "$tag" != "ISSUE_TEMPLATE" && "$tag" != "workflows" ]] ; then
|
||||
tag=${tag%.*}_install
|
||||
ansible-playbook main.yml --tags "$tag" --vault-password-file ~/.vault_password.txt
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No changes detected in task files. Skipping Ansible playbook execution."
|
||||
fi
|
Reference in New Issue
Block a user