#cloud-config
# Ubuntu autoinstall configuration
autoinstall:
  version: 1
  locale: en_US.UTF-8
  keyboard:
    layout: us
  network:
    version: 2
    ethernets:
      ens3:
        dhcp4: true
      enp1s0:
        dhcp4: true
      eth0:
        dhcp4: true
  ssh:
    install-server: true
    authorized-keys:
      - {SSH_PUBLIC_KEY}
    allow-pw: false
  storage:
    layout:
      name: lvm
  identity:
    hostname: thrillwiki-vm
    username: ubuntu
    password: "$6$rounds=4096$salt$hash"  # disabled - ssh key only
  packages:
    - openssh-server
    - curl
    - git
    - python3
    - python3-pip
    - python3-venv
    - build-essential
    - postgresql
    - postgresql-contrib
    - nginx
    - nodejs
    - npm
    - wget
    - ca-certificates
    - openssl
    - dnsutils
    - net-tools
  early-commands:
    - systemctl stop ssh
  late-commands:
    # Enable sudo for ubuntu user
    - echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu
    # Install uv Python package manager
    - chroot /target su - ubuntu -c 'curl -LsSf https://astral.sh/uv/install.sh | sh || pip3 install uv'
    # Add uv to PATH
    - chroot /target su - ubuntu -c 'echo "export PATH=\$HOME/.cargo/bin:\$PATH" >> /home/ubuntu/.bashrc'
    # Clone ThrillWiki repository
    - chroot /target su - ubuntu -c 'cd /home/ubuntu && git clone {GITHUB_REPO} thrillwiki'
    # Setup systemd service for ThrillWiki
    - systemctl enable postgresql
    - systemctl enable nginx

  shutdown: reboot
