#!/bin/bash # Setup LXC containers for CI/CD infrastructure set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' # No Color echo -e "${GREEN}🚀 Setting up CI/CD Infrastructure on Proxmox${NC}" # Configuration TEMPLATE_ID=9000 # Ubuntu 22.04 template ID STORAGE="local-lvm" BRIDGE="vmbr1" GATEWAY="10.10.0.1" DNS="8.8.8.8" # Container specifications declare -A CONTAINERS=( ["git-server"]="100:10.10.0.10:2048:20" ["cicd-registry"]="101:10.10.0.20:4096:50" ["production"]="102:10.10.0.30:2048:20" ) create_container() { local name=$1 local config=$2 IFS=':' read -r id ip memory disk <<< "$config" echo -e "${YELLOW}Creating container: $name (ID: $id)${NC}" # Create container pct create $id $TEMPLATE_ID \ --hostname $name \ --cores 2 \ --memory $memory \ --swap 512 \ --storage $STORAGE \ --rootfs $STORAGE:$disk \ --net0 name=eth0,bridge=$BRIDGE,firewall=1,gw=$GATEWAY,ip=$ip/24,type=veth \ --nameserver $DNS \ --features nesting=1,keyctl=1 \ --unprivileged 1 \ --start 1 echo -e "${GREEN}✅ Container $name created and started${NC}" # Wait for container to boot sleep 10 # Install Docker echo -e "${YELLOW}Installing Docker on $name...${NC}" pct exec $id -- bash -c " apt update && apt upgrade -y apt install -y ca-certificates curl gnupg lsb-release curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo 'deb [arch=\$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable' | tee /etc/apt/sources.list.d/docker.list > /dev/null apt update apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin systemctl enable docker systemctl start docker usermod -aG docker root " # Install Docker Compose pct exec $id -- bash -c " curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose " echo -e "${GREEN}✅ Docker installed on $name${NC}" } # Create containers for container in "${!CONTAINERS[@]}"; do create_container "$container" "${CONTAINERS[$container]}" done echo -e "${GREEN}🎉 All containers created successfully!${NC}" echo -e "${YELLOW}Next steps:${NC}" echo "1. Configure DNS: git.home.lab → 10.10.0.10" echo "2. Deploy services using docker-compose files" echo "3. Configure webhooks and CI/CD" echo -e "${GREEN}Container Access:${NC}" echo "Git Server: ssh root@10.10.0.10 or pct enter 100" echo "CI/CD: ssh root@10.10.0.20 or pct enter 101" echo "Production: ssh root@10.10.0.30 or pct enter 102"