Initial commit: stack
This commit is contained in:
commit
fe16a07dd7
11 changed files with 2058 additions and 0 deletions
66
infrastructure/lxc-templates/provision.sh
Normal file
66
infrastructure/lxc-templates/provision.sh
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
# Provision an app LXC on the internal network (10.10.10.0/24)
|
||||
# Usage: ./provision.sh <lxc-id> <last-octet> <app-name> <git-repo-url>
|
||||
# Example: ./provision.sh 110 110 kitchen https://forgejo.yourserver.com/hnf/hnf-kitchen.git
|
||||
set -e
|
||||
|
||||
LXC_ID=$1
|
||||
OCTET=$2
|
||||
APP=$3
|
||||
REPO=$4
|
||||
IP="10.10.10.${OCTET}"
|
||||
|
||||
if [ -z "$LXC_ID" ] || [ -z "$OCTET" ] || [ -z "$APP" ]; then
|
||||
echo "Usage: $0 <lxc-id> <ip-octet> <app-name> [git-repo-url]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> Creating LXC $LXC_ID: $APP at $IP"
|
||||
|
||||
# Create LXC (Ubuntu 22.04, no public template — adjust storage pool as needed)
|
||||
pct create "$LXC_ID" local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
|
||||
--hostname "hnf-$APP" \
|
||||
--memory 512 \
|
||||
--cores 1 \
|
||||
--rootfs local-lvm:8 \
|
||||
--net0 name=eth0,bridge=vmbr1,ip="${IP}/24",gw=10.10.10.1 \
|
||||
--features nesting=1 \
|
||||
--unprivileged 0 \
|
||||
--start 1
|
||||
|
||||
sleep 5
|
||||
echo "==> LXC started, installing Docker..."
|
||||
|
||||
pct exec "$LXC_ID" -- bash -c "
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq ca-certificates curl gnupg git openssh-server
|
||||
install -m 0755 -d /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable' \
|
||||
> /etc/apt/sources.list.d/docker.list
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||
systemctl enable docker
|
||||
mkdir -p /opt/$APP
|
||||
"
|
||||
|
||||
# Copy management container's SSH public key for update webhooks
|
||||
if [ -f /root/.ssh/management_deploy.pub ]; then
|
||||
pct exec "$LXC_ID" -- bash -c "
|
||||
mkdir -p /root/.ssh
|
||||
echo '$(cat /root/.ssh/management_deploy.pub)' >> /root/.ssh/authorized_keys
|
||||
chmod 600 /root/.ssh/authorized_keys
|
||||
"
|
||||
echo "==> SSH key installed"
|
||||
fi
|
||||
|
||||
# Clone app repo if provided
|
||||
if [ -n "$REPO" ]; then
|
||||
pct exec "$LXC_ID" -- bash -c "git clone '$REPO' /opt/$APP"
|
||||
echo "==> Repo cloned to /opt/$APP"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "==> LXC $LXC_ID ($APP) ready at $IP"
|
||||
echo " SSH: pct enter $LXC_ID"
|
||||
echo " Next: copy .env, then: cd /opt/$APP && docker compose up -d"
|
||||
Loading…
Add table
Add a link
Reference in a new issue