This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
Auto-Homelab/scripts/README.md

72 lines
2.7 KiB
Markdown
Raw Normal View History

2024-05-19 23:26:07 -04:00
# n8n Continuous Deployment
2024-05-20 01:26:01 -04:00
Previously used this script for CD, it worked, but I wanted an instant deployment and not just ran on a schedule. So I created an n8n automation. Here's the visual breakdown:
```mermaid
graph LR
A((Webhook Received)) --> B{PR Merged?}
B -- No --> C(End)
B -- Yes --> D{Extract App Name}
D --> E{SSH to Host Machine}
E --> F{Git Pull & Docker Compose Up}
F --> G{Error?}
G -- Yes --> H[Send Gotify Notification]
G -- No --> I[Extract PR Number]
I --> J[Add PR Number to Forgejo API URL]
J --> K[Send Review with Logs]
K --> L(End)
H --> L
```
2024-05-19 23:26:07 -04:00
## Outline
- Webhook is sent whenever a PR is merged
- Filters out any new, edited or re-opened PR's
- Checks the PR title for app name, which is filtered so each SSH session matches based on the IF conditions.
- SSH in to the machine that hosts that docker compose stack running git pull and docker compose up -d
- Optional, If there is any error message we sent Gotify a link to the PR and error message
- Set number from JSON to number in n8n
2024-05-19 23:38:45 -04:00
- Add that number to URL of API request to Forgejo which we add a review with the logs if no errors. https://git.mafyuh.dev/mafyuh/Auto-Homelab/pulls/222#issuecomment-1799
2024-05-19 23:26:07 -04:00
The only exception is n8n itself. Which for now I will manually update.
## dccd instructions (no longer used besides ag-backup)
2024-05-10 23:20:17 -04:00
Modified version of https://github.com/loganmarchione/dccd, with Gotify notification on error and allowing to choose which directory is cd'd into before running script. I run this on each docker host through crontab every 30 minutes, just adding the -f flag with the folder which that host represents. So each directory represents a host
2024-04-15 02:18:42 -04:00
2024-04-15 19:22:34 -04:00
Clone this repo:
```
git clone https://git.mafyuh.dev/mafyuh/Auto-Homelab.git
```
2024-04-15 02:18:42 -04:00
2024-04-11 18:51:16 -04:00
Make executable:
```
2024-04-15 19:22:34 -04:00
sudo chmod +x /home/mafyuh/Auto-Homelab/scripts/dccd.sh
2024-04-11 18:51:16 -04:00
```
Example:
```
./dccd.sh -b main -d /home/mafyuh/Auto-Homelab -p -f 'arrs'
```
2024-04-15 02:18:42 -04:00
Crontab every 30 mins:
2024-04-11 18:51:16 -04:00
```
2024-04-11 19:06:55 -04:00
*/30 * * * * /home/mafyuh/Auto-Homelab/scripts/dccd.sh -b main -d /home/mafyuh/Auto-Homelab -l /tmp/dccd.txt -p -f 'arrs'
2024-04-11 18:51:16 -04:00
```
View Logs:
```
cat /tmp/dccd.txt
```
2024-04-11 20:23:09 -04:00
Export Variables:
```
export GOTIFY_BASE_URL="https:go.example.com"
export GOTIFY_TOKEN="token"
```
2024-04-15 02:18:42 -04:00
Full Usage:
```
Options:
-b <name> Specify the remote branch to track (default: main)
-d <path> Specify the base directory of the git repository (required)
-h Show this help message
-l <path> Specify the path to the log file (default: /tmp/dccd.log)
-p Specify if you want to prune docker images (default: don't prune)
-x <path> Exclude directories matching the specified pattern (relative to the base directory)
-f <pattern> Specify the pattern for folder names to match
```