generated from CC/VMServiceTemplate
Initial commit
This commit is contained in:
88
.gitea/workflows/deploy.yml
Normal file
88
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,88 @@
|
||||
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: frente
|
||||
env:
|
||||
PROXMOX_VE_API_TOKEN: https://api.staging.example.com
|
||||
PROXMOX_VE_ENDPOINT: true
|
||||
GITEA_BASE_URL: https://api.staging.example.com
|
||||
GITEA_TOKEN: true
|
||||
AWS_ACCESS_KEY_ID: https://api.staging.example.com
|
||||
AWS_SECRET_ACCESS_KEY: true
|
||||
AWS_REGION: garage
|
||||
TF_VAR_vm_ssh_userkey: ${{ secrets.VM_USER_SSHKEY }}
|
||||
|
||||
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
|
||||
36
.gitea/workflows/destroy_module.yml
Normal file
36
.gitea/workflows/destroy_module.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Terraform Destroy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
working_directory:
|
||||
description: "Working directory for the module"
|
||||
required: false
|
||||
default: "terraform"
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
destroy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working_directory }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v4
|
||||
|
||||
- name: Terraform Init
|
||||
run: terraform init
|
||||
|
||||
- name: Terraform Destroy Plan
|
||||
run: terraform plan -destroy -out=tfplan
|
||||
continue-on-error: false
|
||||
|
||||
- name: Terraform Destroy
|
||||
run: terraform destroy -auto-approve
|
||||
82
.gitea/workflows/test_deploy.yml
Normal file
82
.gitea/workflows/test_deploy.yml
Normal file
@@ -0,0 +1,82 @@
|
||||
name: Terraform Deploy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
instance_mode:
|
||||
description: "Instance mode"
|
||||
required: true
|
||||
default: "single"
|
||||
type: choice
|
||||
options:
|
||||
- single
|
||||
- multi
|
||||
|
||||
service_name:
|
||||
description: "Service name (e.g. n8n)"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
vm_name:
|
||||
description: "VM name (e.g. n8n-01)"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
node_name:
|
||||
description: "Proxmox node (e.g. pop)"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
app_port:
|
||||
description: "App port (e.g. 5678)"
|
||||
required: false
|
||||
default: "5678"
|
||||
|
||||
vm_tags:
|
||||
description: "VM tags, comma-separated (e.g. agentic,prod)"
|
||||
required: false
|
||||
default: "agentic"
|
||||
|
||||
jobs:
|
||||
terraform:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build tfvars
|
||||
env:
|
||||
VM_USER_SSHKEY: ${{ secrets.VM_USER_SSHKEY }}
|
||||
APP_PORT: ${{ github.event.inputs.app_port }}
|
||||
VM_TAGS: ${{ github.event.inputs.vm_tags }}
|
||||
run: |
|
||||
# Convert comma-separated tags to HCL list
|
||||
TAGS_HCL=$(echo "$VM_TAGS" | tr ',' '\n' | sed 's/^/"/;s/$/"/' | paste -sd ',' | sed 's/^/[/;s/$/]/')
|
||||
|
||||
cat > ci.tfvars <<EOF
|
||||
instance_mode = "${{ github.event.inputs.instance_mode }}"
|
||||
|
||||
instance = {
|
||||
service_name = "${{ github.event.inputs.service_name }}"
|
||||
vm_name = "${{ github.event.inputs.vm_name }}"
|
||||
node_name = "${{ github.event.inputs.node_name }}"
|
||||
app_port = ${APP_PORT}
|
||||
vm_tags = ${TAGS_HCL}
|
||||
}
|
||||
|
||||
vm_defaults = {
|
||||
vm_user_sshkey = "${VM_USER_SSHKEY}"
|
||||
}
|
||||
EOF
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v3
|
||||
|
||||
- name: Terraform Init
|
||||
run: terraform init
|
||||
|
||||
- name: Terraform Plan
|
||||
run: terraform plan -var-file="ci.tfvars"
|
||||
|
||||
- name: Terraform Apply
|
||||
run: terraform apply -var-file="ci.tfvars" -auto-approve
|
||||
Reference in New Issue
Block a user