Compare commits
23 Commits
f87f2af4fa
...
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 | |||
| faaa9ce511 | |||
| 7c1b9a5e40 |
@@ -7,26 +7,23 @@ on:
|
||||
|
||||
jobs:
|
||||
production:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: production
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: SSH Key einrichten
|
||||
- name: Configure Git Token
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
echo "${{ secrets.PROD_HOST_KEY }}" >> ~/.ssh/known_hosts
|
||||
git config --global url."https://sebastian.serfling:${{ secrets.GIT_TOKEN }}@gitlab.stines.de/".insteadOf "https://gitlab.stines.de/"
|
||||
|
||||
- name: Hugo Build
|
||||
run: hugo --minify --source ./hugo
|
||||
|
||||
- name: Deploy auf Production
|
||||
- name: Hugo Build & Deploy
|
||||
run: |
|
||||
rsync -az --delete \
|
||||
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no" \
|
||||
./hugo/public/ \
|
||||
root@${{ secrets.PROD_IP }}:/var/www/html/
|
||||
set -e
|
||||
|
||||
# Hugo Build direkt in /var/www/html
|
||||
hugo --minify --source ./hugo -d /var/www/html
|
||||
|
||||
echo "✅ Production Hugo Build erfolgreich!"
|
||||
echo "🚀 Live unter https://stines.de"
|
||||
|
||||
@@ -4,17 +4,23 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- "dev*"
|
||||
|
||||
jobs:
|
||||
staging:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: proxmox
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Terraform Init & Apply (Staging LXC)
|
||||
- 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: |
|
||||
terraform init
|
||||
@@ -23,25 +29,32 @@ jobs:
|
||||
-var="proxmox_token_id=${{ secrets.PROXMOX_TOKEN_ID }}" \
|
||||
-var="proxmox_token_secret=${{ secrets.PROXMOX_TOKEN_SECRET }}" \
|
||||
-var="proxmox_node=${{ secrets.PROXMOX_NODE }}" \
|
||||
-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="root_password=${{ secrets.ROOT_PASSWORD }}"
|
||||
env:
|
||||
TF_IN_AUTOMATION: "true"
|
||||
|
||||
- name: SSH Key einrichten
|
||||
- name: Hugo Clone & Build auf Staging-LXC
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
echo "${{ secrets.STAGING_HOST_KEY }}" >> ~/.ssh/known_hosts
|
||||
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no root@${{ secrets.STAGING_IP }} bash << 'EOF'
|
||||
set -e
|
||||
cd /tmp
|
||||
|
||||
- name: Hugo Build
|
||||
run: hugo --minify --source ./hugo
|
||||
# Repository clonen mit Token (oder updaten falls existiert)
|
||||
GIT_URL="https://sebastian.serfling:${{ secrets.GIT_TOKEN }}@gitlab.stines.de/sebastian.serfling/Webseite_Stines.git"
|
||||
|
||||
- name: Deploy auf Staging
|
||||
run: |
|
||||
rsync -az --delete \
|
||||
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no" \
|
||||
./hugo/public/ \
|
||||
root@${{ secrets.STAGING_IP_PLAIN }}:/var/www/html/
|
||||
if [ -d "webseite" ]; then
|
||||
cd webseite
|
||||
git pull origin main
|
||||
else
|
||||
git clone "$GIT_URL" webseite
|
||||
cd webseite
|
||||
fi
|
||||
|
||||
# Hugo Build direkt in /var/www/html
|
||||
hugo --minify --source ./hugo -d /var/www/html
|
||||
|
||||
echo "✅ Staging Hugo Build erfolgreich!"
|
||||
EOF
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Test Deploy
|
||||
+33
-26
@@ -14,49 +14,56 @@ provider "proxmox" {
|
||||
pm_tls_insecure = true
|
||||
}
|
||||
|
||||
resource "proxmox_lxc" "staging" {
|
||||
target_node = var.proxmox_node
|
||||
hostname = "hugo-staging"
|
||||
ostemplate = var.lxc_ostemplate
|
||||
unprivileged = true
|
||||
start = true
|
||||
onboot = false
|
||||
|
||||
cores = 1
|
||||
memory = 512
|
||||
swap = 512
|
||||
|
||||
rootfs {
|
||||
storage = var.lxc_storage
|
||||
size = "8G"
|
||||
# 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 = "vmbr2"
|
||||
ip = var.staging_ip
|
||||
gw = var.staging_gw != "" ? var.staging_gw : null
|
||||
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 nginx",
|
||||
"apt-get install -y hugo nginx git rsync curl",
|
||||
"systemctl enable --now nginx",
|
||||
"useradd -m -s /bin/bash deploy 2>/dev/null || true",
|
||||
"mkdir -p /var/www/html",
|
||||
"chown -R www-data:www-data /var/www/html"
|
||||
"chown -R deploy:deploy /var/www/html",
|
||||
"echo '✅ Staging VM Setup complete!'"
|
||||
]
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "root"
|
||||
private_key = file("~/.ssh/deploy_key")
|
||||
host = self.network[0].ip
|
||||
private_key = file(pathexpand("~/.ssh/deploy_key"))
|
||||
host = var.staging_ip
|
||||
timeout = "5m"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
+38
-6
@@ -17,13 +17,17 @@ variable "proxmox_token_secret" {
|
||||
variable "proxmox_node" {
|
||||
description = "Ziel-Proxmox-Node"
|
||||
type = string
|
||||
default = "pve"
|
||||
}
|
||||
|
||||
variable "lxc_bridge" {
|
||||
description = "Netzwerk-Bridge (z.B. vmbr2)"
|
||||
type = string
|
||||
}
|
||||
|
||||
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" {
|
||||
@@ -33,18 +37,46 @@ variable "lxc_storage" {
|
||||
}
|
||||
|
||||
variable "staging_ip" {
|
||||
description = "Statische IP fuer Staging-LXC (CIDR)"
|
||||
description = "Statische IP fuer Staging-LXC (ohne CIDR)"
|
||||
type = string
|
||||
default = "dhcp"
|
||||
default = "172.17.1.100"
|
||||
}
|
||||
|
||||
variable "staging_gw" {
|
||||
description = "Gateway fuer Staging-LXC"
|
||||
type = string
|
||||
default = ""
|
||||
default = "172.17.1.1"
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
description = "SSH Public Key fuer den deploy-User im LXC"
|
||||
description = "SSH Public Key fuer deploy-User im LXC"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_private_key" {
|
||||
description = "SSH Private Key (für Provisioning)"
|
||||
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