From 887bf616c9e9f246f5ea24636f4b137fa1827954 Mon Sep 17 00:00:00 2001 From: CC Date: Fri, 22 May 2026 22:00:55 +0100 Subject: [PATCH] tested template --- .gitea/workflows/deploy.yml | 75 +++++++++++------- .../workflows}/destroy_module.yml | 0 compose/n8n/.env | 17 ---- compose/n8n/docker-compose.yml | 22 ------ workflows/deploy.yml | 78 ------------------- 5 files changed, 48 insertions(+), 144 deletions(-) rename {workflows => .gitea/workflows}/destroy_module.yml (100%) delete mode 100644 compose/n8n/.env delete mode 100644 compose/n8n/docker-compose.yml delete mode 100644 workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 74c32db..69f81e5 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,6 +1,8 @@ name: Deploy VM and App on: + push: + workflow_dispatch: inputs: tfvars_file: @@ -13,45 +15,64 @@ on: - multi.tfvars.example jobs: - terraform: + terraform-ansible-deploy: runs-on: ubuntu-latest - defaults: - run: - working-directory: terraform steps: - uses: actions/checkout@v4 - - uses: hashicorp/setup-terraform@v3 + - name: Check files & Select tfvars + shell: bash + run: | + #rm ansible/inventory/inventory.yml + mkdir -p ansible/inventory + cd terraform + #rm vm_data.yml + cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars - - name: Select tfvars - run: cp "${{ inputs.tfvars_file }}" terraform.tfvars + - uses: hashicorp/setup-terraform@v4 + + - name: Check path + run: pwd - name: Terraform init run: terraform init + working-directory: "terraform" - name: Terraform apply run: terraform apply -auto-approve - - - name: Write inventory - run: | - mkdir -p ../ansible/inventory - terraform output -json vm_ipv4_addresses | jq -r ' - to_entries[] | "[app]\n\(.value) ansible_user=cloud" - ' > ../ansible/inventory/hosts.ini - - - name: Write tags - run: terraform output -json vm_tags > ../ansible/vm_tags.json - - deploy: - needs: terraform - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 + working-directory: "terraform" - name: Install Ansible + shell: bash run: | - python3 -m pip install --upgrade pip - pip install ansible community.docker + sudo apt-get update + sudo apt-get install -y ansible rsync - - name: Deploy app - run: ansible-playbook -i ansible/inventory/hosts.ini ansible/playbooks/deploy.yml + - name: Set up SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa + chmod 600 ~/.ssh/vlans_rsa + cat > ~/.ssh/config <<'EOF' + Host * + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null + EOF + + - name: Run playbook + run: | + ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa + + - name: Configure Git + run: | + git config user.name "git-bot" + git config user.email "got-bot@text.com" + + - name: Commit and push to Gitea + run: | + git remote set-url origin https://$GITEA_USERNAME:${{ secrets.GIT_BOT_TOKEN }}@tea.charcarservices.uk/CC/N8N.git + git add terraform/vm_data.yml ansible/inventory/inventory.yml + git diff --cached --quiet || git commit -m "chore: update terraform outputs" + git push origin HEAD:main + env: + GITEA_USERNAME: git-bot # or your bot account diff --git a/workflows/destroy_module.yml b/.gitea/workflows/destroy_module.yml similarity index 100% rename from workflows/destroy_module.yml rename to .gitea/workflows/destroy_module.yml diff --git a/compose/n8n/.env b/compose/n8n/.env deleted file mode 100644 index d9c1928..0000000 --- a/compose/n8n/.env +++ /dev/null @@ -1,17 +0,0 @@ -APP_NAME=n8n -APP_PORT=5678 -# DOMAIN_NAME and SUBDOMAIN together determine where n8n will be reachable from -# The top level domain to serve from -DOMAIN_NAME=charcarservices.uk - -# The subdomain to serve from -SUBDOMAIN=nein - -# The above example serve n8n at: https://n8n.example.com - -# Optional timezone to set which gets used by Cron and other scheduling nodes -# New York is the default value if not set -GENERIC_TIMEZONE=Europe/London - -# The email address to use for the TLS/SSL certificate creation -SSL_EMAIL=user@example.com \ No newline at end of file diff --git a/compose/n8n/docker-compose.yml b/compose/n8n/docker-compose.yml deleted file mode 100644 index 52a72c1..0000000 --- a/compose/n8n/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - n8n: - image: docker.n8n.io/n8nio/n8n - restart: always - ports: - - "5678:5678" - environment: - - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true - - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME} - - N8N_PORT=5678 - - N8N_PROTOCOL=https - - NODE_ENV=production - - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/ - - GENERIC_TIMEZONE=${GENERIC_TIMEZONE} - - TZ=${GENERIC_TIMEZONE} - volumes: - - ./n8n_data:/home/node/.n8n - - ./local-files:/files - -volumes: - n8n_data: - traefik_data: diff --git a/workflows/deploy.yml b/workflows/deploy.yml deleted file mode 100644 index 69f81e5..0000000 --- a/workflows/deploy.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Deploy VM and App - -on: - push: - - workflow_dispatch: - inputs: - tfvars_file: - description: "Which tfvars file to use" - required: true - default: "single.tfvars.example" - type: choice - options: - - single.tfvars.example - - multi.tfvars.example - -jobs: - terraform-ansible-deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Check files & Select tfvars - shell: bash - run: | - #rm ansible/inventory/inventory.yml - mkdir -p ansible/inventory - cd terraform - #rm vm_data.yml - cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars - - - uses: hashicorp/setup-terraform@v4 - - - name: Check path - run: pwd - - - name: Terraform init - run: terraform init - working-directory: "terraform" - - - name: Terraform apply - run: terraform apply -auto-approve - working-directory: "terraform" - - - name: Install Ansible - shell: bash - run: | - sudo apt-get update - sudo apt-get install -y ansible rsync - - - name: Set up SSH - run: | - mkdir -p ~/.ssh - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa - chmod 600 ~/.ssh/vlans_rsa - cat > ~/.ssh/config <<'EOF' - Host * - StrictHostKeyChecking no - UserKnownHostsFile=/dev/null - EOF - - - name: Run playbook - run: | - ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa - - - name: Configure Git - run: | - git config user.name "git-bot" - git config user.email "got-bot@text.com" - - - name: Commit and push to Gitea - run: | - git remote set-url origin https://$GITEA_USERNAME:${{ secrets.GIT_BOT_TOKEN }}@tea.charcarservices.uk/CC/N8N.git - git add terraform/vm_data.yml ansible/inventory/inventory.yml - git diff --cached --quiet || git commit -m "chore: update terraform outputs" - git push origin HEAD:main - env: - GITEA_USERNAME: git-bot # or your bot account