Compare commits
21 Commits
faaa9ce511
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a5b529fc8 | |||
| 184d8ca313 | |||
| a429605f32 | |||
| 0a4568fc83 | |||
| 1f5abb9bc5 | |||
| 666ae202fb | |||
| 4d155c907e | |||
| 46cd198b41 | |||
| 91a96e6cd3 | |||
| 63145188f8 | |||
| bda56f8563 | |||
| 0a4f1ba1e9 | |||
| e53a6016cd | |||
| cc4ae05638 | |||
| 9d2f12a8ef | |||
| f58b75980b | |||
| 04e38a03c6 | |||
| 81d4126e0f | |||
| 64b17872a8 | |||
| 3a5b252dca | |||
| 623d03e559 |
@@ -4,6 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
- "dev*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
staging:
|
staging:
|
||||||
@@ -14,6 +15,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
- name: Delete alte Staging VM (CT 200)
|
||||||
|
run: |
|
||||||
|
pct destroy 200 --force || true
|
||||||
|
sleep 3
|
||||||
|
|
||||||
- name: Terraform Init & Apply (Staging LXC erstellen)
|
- name: Terraform Init & Apply (Staging LXC erstellen)
|
||||||
working-directory: terraform
|
working-directory: terraform
|
||||||
run: |
|
run: |
|
||||||
@@ -26,24 +32,13 @@ jobs:
|
|||||||
-var="lxc_bridge=vmbr2" \
|
-var="lxc_bridge=vmbr2" \
|
||||||
-var="staging_ip=${{ secrets.STAGING_IP }}" \
|
-var="staging_ip=${{ secrets.STAGING_IP }}" \
|
||||||
-var="staging_gw=${{ secrets.STAGING_GW }}" \
|
-var="staging_gw=${{ secrets.STAGING_GW }}" \
|
||||||
-var="ssh_public_key=${{ secrets.DEPLOY_SSH_PUBKEY }}" \
|
-var="root_password=${{ secrets.ROOT_PASSWORD }}"
|
||||||
-var="ssh_private_key=${{ secrets.DEPLOY_SSH_KEY }}"
|
|
||||||
env:
|
env:
|
||||||
TF_IN_AUTOMATION: "true"
|
TF_IN_AUTOMATION: "true"
|
||||||
|
|
||||||
- name: Warte auf LXC Boot
|
|
||||||
run: sleep 30
|
|
||||||
|
|
||||||
- name: SSH Key Setup
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.DEPLOY_SSH_KEY }}" | base64 -d > ~/.ssh/staging_key
|
|
||||||
chmod 600 ~/.ssh/staging_key
|
|
||||||
ssh-keyscan -H ${{ secrets.STAGING_IP }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
||||||
|
|
||||||
- name: Hugo Clone & Build auf Staging-LXC
|
- name: Hugo Clone & Build auf Staging-LXC
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/staging_key -o StrictHostKeyChecking=no deploy@${{ secrets.STAGING_IP }} bash << 'EOF'
|
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no root@${{ secrets.STAGING_IP }} bash << 'EOF'
|
||||||
set -e
|
set -e
|
||||||
cd /tmp
|
cd /tmp
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Test Deploy
|
||||||
+32
-34
@@ -14,58 +14,56 @@ provider "proxmox" {
|
|||||||
pm_tls_insecure = true
|
pm_tls_insecure = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "proxmox_lxc" "staging" {
|
# Create staging LXC mit pct-Befehl
|
||||||
target_node = var.proxmox_node
|
resource "null_resource" "staging_lxc" {
|
||||||
hostname = "hugo-staging"
|
# SSH Public Key in Datei schreiben
|
||||||
vmid = 200
|
provisioner "local-exec" {
|
||||||
ostemplate = var.lxc_ostemplate
|
command = "mkdir -p /tmp/terraform && echo '${var.ssh_public_key}' > /tmp/terraform/staging_key.pub"
|
||||||
unprivileged = true
|
|
||||||
start = true
|
|
||||||
onboot = false
|
|
||||||
|
|
||||||
cores = 2
|
|
||||||
memory = 1024
|
|
||||||
swap = 512
|
|
||||||
|
|
||||||
rootfs {
|
|
||||||
storage = var.lxc_storage
|
|
||||||
size = "10G"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network {
|
provisioner "local-exec" {
|
||||||
name = "eth0"
|
command = <<-EOT
|
||||||
bridge = var.lxc_bridge
|
pct create 200 \
|
||||||
ip = "${var.staging_ip}/24"
|
${var.lxc_ostemplate} \
|
||||||
gw = var.staging_gw
|
--hostname hugo-staging \
|
||||||
|
--cores ${var.lxc_cores} \
|
||||||
|
--memory ${var.lxc_memory} \
|
||||||
|
--swap ${var.lxc_swap} \
|
||||||
|
--rootfs ${var.lxc_rootfs} \
|
||||||
|
--net0 name=eth0,bridge=${var.lxc_bridge},ip=${var.staging_ip}/24,gw=${var.staging_gw} \
|
||||||
|
--unprivileged 1 \
|
||||||
|
--start 1 \
|
||||||
|
--password "${var.root_password}" \
|
||||||
|
--ssh-public-keys /tmp/terraform/staging_key.pub
|
||||||
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_public_keys = var.ssh_public_key
|
provisioner "local-exec" {
|
||||||
|
command = "sleep 30"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setup via SSH (nutzt ~/.ssh/deploy vom Proxmox Host)
|
||||||
provisioner "remote-exec" {
|
provisioner "remote-exec" {
|
||||||
inline = [
|
inline = [
|
||||||
"apt-get update -qq",
|
"apt-get update -qq",
|
||||||
"apt-get install -y hugo nginx git rsync curl",
|
"apt-get install -y hugo nginx git rsync curl",
|
||||||
"systemctl enable --now nginx",
|
"systemctl enable --now nginx",
|
||||||
"useradd -m -s /bin/bash deploy || true",
|
"useradd -m -s /bin/bash deploy 2>/dev/null || true",
|
||||||
"mkdir -p /home/deploy/.ssh",
|
|
||||||
"chmod 700 /home/deploy/.ssh",
|
|
||||||
"echo '${var.ssh_public_key}' >> /home/deploy/.ssh/authorized_keys",
|
|
||||||
"chmod 600 /home/deploy/.ssh/authorized_keys",
|
|
||||||
"chown -R deploy:deploy /home/deploy/.ssh",
|
|
||||||
"mkdir -p /var/www/html",
|
"mkdir -p /var/www/html",
|
||||||
"chown -R deploy:deploy /var/www/html"
|
"chown -R deploy:deploy /var/www/html",
|
||||||
|
"echo '✅ Staging VM Setup complete!'"
|
||||||
]
|
]
|
||||||
|
|
||||||
connection {
|
connection {
|
||||||
type = "ssh"
|
type = "ssh"
|
||||||
user = "root"
|
user = "root"
|
||||||
private_key = var.ssh_private_key
|
private_key = file(pathexpand("~/.ssh/deploy_key"))
|
||||||
host = self.network[0].ip
|
host = var.staging_ip
|
||||||
|
timeout = "5m"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
depends_on = []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output "staging_ip" {
|
output "staging_ip" {
|
||||||
value = proxmox_lxc.staging.network[0].ip
|
value = "${var.staging_ip}/24"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ proxmox_host = "https://192.168.1.10:8006/api2/json"
|
|||||||
proxmox_token_id = "terraform@pve!deploy"
|
proxmox_token_id = "terraform@pve!deploy"
|
||||||
proxmox_token_secret = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
proxmox_token_secret = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
proxmox_node = "pve"
|
proxmox_node = "pve"
|
||||||
lxc_ostemplate = "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
lxc_ostemplate = "local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst"
|
||||||
lxc_storage = "local-lvm"
|
lxc_storage = "local-lvm"
|
||||||
staging_ip = "192.168.1.50/24"
|
staging_ip = "192.168.1.50/24"
|
||||||
staging_gw = "192.168.1.1"
|
staging_gw = "192.168.1.1"
|
||||||
|
|||||||
+23
-1
@@ -27,7 +27,7 @@ variable "lxc_bridge" {
|
|||||||
variable "lxc_ostemplate" {
|
variable "lxc_ostemplate" {
|
||||||
description = "Pfad zum LXC-Template"
|
description = "Pfad zum LXC-Template"
|
||||||
type = string
|
type = string
|
||||||
default = "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
default = "local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "lxc_storage" {
|
variable "lxc_storage" {
|
||||||
@@ -58,3 +58,25 @@ variable "ssh_private_key" {
|
|||||||
type = string
|
type = string
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "root_password" {
|
||||||
|
description = "Root Password für Staging VM"
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "lxc_cores" {
|
||||||
|
default = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "lxc_memory" {
|
||||||
|
default = 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "lxc_swap" {
|
||||||
|
default = 512
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "lxc_rootfs" {
|
||||||
|
default = "SSD:10"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user