Compare commits
22 Commits
faaa9ce511
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 78fd15de69 | |||
| 6a5b529fc8 | |||
| 184d8ca313 | |||
| a429605f32 | |||
| 0a4568fc83 | |||
| 1f5abb9bc5 | |||
| 666ae202fb | |||
| 4d155c907e | |||
| 46cd198b41 | |||
| 91a96e6cd3 | |||
| 63145188f8 | |||
| bda56f8563 | |||
| 0a4f1ba1e9 | |||
| e53a6016cd | |||
| cc4ae05638 | |||
| 9d2f12a8ef | |||
| f58b75980b | |||
| 04e38a03c6 | |||
| 81d4126e0f | |||
| 64b17872a8 | |||
| 3a5b252dca | |||
| 623d03e559 |
@@ -3,7 +3,7 @@ name: Deploy Staging
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- "dev*"
|
||||
|
||||
jobs:
|
||||
staging:
|
||||
@@ -14,6 +14,11 @@ jobs:
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Delete alte Staging VM (CT 200)
|
||||
run: |
|
||||
pct destroy 200 --force || true
|
||||
sleep 3
|
||||
|
||||
- name: Terraform Init & Apply (Staging LXC erstellen)
|
||||
working-directory: terraform
|
||||
run: |
|
||||
@@ -26,24 +31,13 @@ jobs:
|
||||
-var="lxc_bridge=vmbr2" \
|
||||
-var="staging_ip=${{ secrets.STAGING_IP }}" \
|
||||
-var="staging_gw=${{ secrets.STAGING_GW }}" \
|
||||
-var="ssh_public_key=${{ secrets.DEPLOY_SSH_PUBKEY }}" \
|
||||
-var="ssh_private_key=${{ secrets.DEPLOY_SSH_KEY }}"
|
||||
-var="root_password=${{ secrets.ROOT_PASSWORD }}"
|
||||
env:
|
||||
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
|
||||
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
|
||||
cd /tmp
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Test Deploy
|
||||
+32
-34
@@ -14,58 +14,56 @@ provider "proxmox" {
|
||||
pm_tls_insecure = true
|
||||
}
|
||||
|
||||
resource "proxmox_lxc" "staging" {
|
||||
target_node = var.proxmox_node
|
||||
hostname = "hugo-staging"
|
||||
vmid = 200
|
||||
ostemplate = var.lxc_ostemplate
|
||||
unprivileged = true
|
||||
start = true
|
||||
onboot = false
|
||||
|
||||
cores = 2
|
||||
memory = 1024
|
||||
swap = 512
|
||||
|
||||
rootfs {
|
||||
storage = var.lxc_storage
|
||||
size = "10G"
|
||||
# Create staging LXC mit pct-Befehl
|
||||
resource "null_resource" "staging_lxc" {
|
||||
# SSH Public Key in Datei schreiben
|
||||
provisioner "local-exec" {
|
||||
command = "mkdir -p /tmp/terraform && echo '${var.ssh_public_key}' > /tmp/terraform/staging_key.pub"
|
||||
}
|
||||
|
||||
network {
|
||||
name = "eth0"
|
||||
bridge = var.lxc_bridge
|
||||
ip = "${var.staging_ip}/24"
|
||||
gw = var.staging_gw
|
||||
provisioner "local-exec" {
|
||||
command = <<-EOT
|
||||
pct create 200 \
|
||||
${var.lxc_ostemplate} \
|
||||
--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" {
|
||||
inline = [
|
||||
"apt-get update -qq",
|
||||
"apt-get install -y hugo nginx git rsync curl",
|
||||
"systemctl enable --now nginx",
|
||||
"useradd -m -s /bin/bash deploy || 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",
|
||||
"useradd -m -s /bin/bash deploy 2>/dev/null || true",
|
||||
"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 {
|
||||
type = "ssh"
|
||||
user = "root"
|
||||
private_key = var.ssh_private_key
|
||||
host = self.network[0].ip
|
||||
private_key = file(pathexpand("~/.ssh/deploy_key"))
|
||||
host = var.staging_ip
|
||||
timeout = "5m"
|
||||
}
|
||||
}
|
||||
|
||||
depends_on = []
|
||||
}
|
||||
|
||||
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_secret = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
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"
|
||||
staging_ip = "192.168.1.50/24"
|
||||
staging_gw = "192.168.1.1"
|
||||
|
||||
+23
-1
@@ -27,7 +27,7 @@ variable "lxc_bridge" {
|
||||
variable "lxc_ostemplate" {
|
||||
description = "Pfad zum LXC-Template"
|
||||
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" {
|
||||
@@ -58,3 +58,25 @@ variable "ssh_private_key" {
|
||||
type = string
|
||||
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