Feature Request: Change CD from n8n to Forgejo Actions #261

Closed
opened 2024-05-27 22:54:32 -04:00 by mafyuh · 2 comments
Owner

Summary

Change CD from n8n to Forgejo Actions

Motivation

keep everything in Forgejo, no need for n8n

Detailed Description

n8n automation works great, however it would be nice to keep everything code defined and not using 3rd party services.

Since each app is on a different SSH host, need to filter the merged PR based if the app name is in it, then match that to the SSH host

Additional Context

AI Examples:

name: SSH Deploy on PR Merge

on:
  pull_request:
    types: [closed]

jobs:
  deploy:
    if: github.event.pull_request.merged == true  # Check if the PR was merged
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Determine Host
      id: determine-host
      run: |
        if [[ "${{ github.event.pull_request.base.ref }}" == *"jellyfin"* ]]; then
          echo "::set-output name=host::jellyfin.example.com"
        elif [[ "${{ github.event.pull_request.base.ref }}" == *"adguardhome"* ]]; then
          echo "::set-output name=host::adguardhome.example.com"
        # Add more conditions for other hosts
        else
          echo "No matching host found"
          exit 1
        fi

    - name: SSH into host and execute commands
      env:
        SSH_HOST: ${{ steps.determine-host.outputs.host }}
        SSH_USER: ${{ secrets.SSH_USER }}
        SSH_KEY: ${{ secrets.SSH_KEY }}
      run: |
        echo "$SSH_KEY" > key.pem
        chmod 600 key.pem
        ssh -i key.pem -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST << 'EOF'
          # Your SSH commands go here
          echo "Connected to $SSH_HOST"
          # For example, pull the latest code
          cd /path/to/project
          git pull
          # Add more commands as needed
        EOF
### Summary Change CD from n8n to Forgejo Actions ### Motivation keep everything in Forgejo, no need for n8n ### Detailed Description n8n automation works great, however it would be nice to keep everything code defined and not using 3rd party services. Since each app is on a different SSH host, need to filter the merged PR based if the app name is in it, then match that to the SSH host ### Additional Context AI Examples: ``` name: SSH Deploy on PR Merge on: pull_request: types: [closed] jobs: deploy: if: github.event.pull_request.merged == true # Check if the PR was merged runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Determine Host id: determine-host run: | if [[ "${{ github.event.pull_request.base.ref }}" == *"jellyfin"* ]]; then echo "::set-output name=host::jellyfin.example.com" elif [[ "${{ github.event.pull_request.base.ref }}" == *"adguardhome"* ]]; then echo "::set-output name=host::adguardhome.example.com" # Add more conditions for other hosts else echo "No matching host found" exit 1 fi - name: SSH into host and execute commands env: SSH_HOST: ${{ steps.determine-host.outputs.host }} SSH_USER: ${{ secrets.SSH_USER }} SSH_KEY: ${{ secrets.SSH_KEY }} run: | echo "$SSH_KEY" > key.pem chmod 600 key.pem ssh -i key.pem -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST << 'EOF' # Your SSH commands go here echo "Connected to $SSH_HOST" # For example, pull the latest code cd /path/to/project git pull # Add more commands as needed EOF ```
mafyuh added the
enhancement
label 2024-05-27 22:54:32 -04:00
mafyuh added this to the Auto-Homelab project 2024-05-27 22:56:00 -04:00
Author
Owner

Well almost 100 commits later I have a working CI/CD platform all through Forgejo Actions.

Checkout https://git.mafyuh.dev/mafyuh/Auto-Homelab/actions/runs/125

Basically, CD.yml just filters down the name and host of the file that was affected by PR merge, sends that to AWX as extra_vars where I run this playbook on that specific host/folder, then wait 45 seconds and grab the logs and displays them right in the pipeline run.

Now all PR's have a CI Yamlint check, followed by CD all inhouse, no more n8n and no more Drone.

Still need to figure out what happens if 2 folders are affected (Adguard), guess we will see.

Well almost 100 commits later I have a working CI/CD platform all through Forgejo Actions. Checkout https://git.mafyuh.dev/mafyuh/Auto-Homelab/actions/runs/125 Basically, CD.yml just filters down the name and host of the file that was affected by PR merge, sends that to AWX as extra_vars where I run [this playbook](https://git.mafyuh.dev/mafyuh/ansible-playbooks/src/branch/main/deploy.yml) on that specific host/folder, then wait 45 seconds and grab the logs and displays them right in the pipeline run. Now all PR's have a CI Yamlint check, followed by CD all inhouse, no more n8n and no more Drone. Still need to figure out what happens if 2 folders are affected (Adguard), guess we will see.
Author
Owner

Maybe closed this a bit too prematurely, everything works as expected, however I didn't think about if 2 folders were changed with the same PR. It is really only AG-Home and Syncthing that have this happen, so need to wait for PR of one of those to start editing workflow to run on both machines.

Maybe closed this a bit too prematurely, everything works as expected, however I didn't think about if 2 folders were changed with the same PR. It is really only AG-Home and Syncthing that have this happen, so need to wait for PR of one of those to start editing workflow to run on both machines.
This repo is archived. You cannot comment on issues.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mafyuh/Auto-Homelab#261
No description provided.