FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive ENV HOSTNAME=Nobita # ----------------------------- # Install Required Packages # ----------------------------- RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ wget \ git \ sudo \ qemu-system-x86 \ cloud-image-utils \ openssh-client \ htop \ neovim \ && rm -rf /var/lib/apt/lists/* # ----------------------------- # Install code-server # ----------------------------- RUN curl -fsSL https://code-server.dev/install.sh | sh # ----------------------------- # Create VM Directory # ----------------------------- WORKDIR /workspace RUN mkdir -p /vm/ubuntu22 # ----------------------------- # Download Ubuntu 22.04 Cloud Image (.img is actually qcow2) # ----------------------------- RUN wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img \ -O /vm/ubuntu22/ubuntu22.qcow2 # ----------------------------- # Cloud-Init Config (User: ubuntu) # ----------------------------- RUN cat < /vm/ubuntu22/user-data #cloud-config ssh_pwauth: true disable_root: false chpasswd: list: | root:root expire: false # Ini wajib supaya SSH root tidak diblokir oleh sistem runcmd: - sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config - systemctl restart ssh EOF RUN cat < /vm/ubuntu22/meta-data instance-id: ubuntu22 local-hostname: ubuntu22 EOF RUN cloud-localds /vm/ubuntu22/seed.iso \ /vm/ubuntu22/user-data \ /vm/ubuntu22/meta-data # ----------------------------- # Expose Ports # ----------------------------- EXPOSE 7860 2222 # ----------------------------- # Startup Script # ----------------------------- CMD bash -c "\ DISK_FREE_MB=\$(df -m /home | awk 'NR==2 {print \$4}'); \ VM_DISK=\$((DISK_FREE_MB * 80 / 100)); \ qemu-img resize /vm/ubuntu22/ubuntu22.qcow2 \${VM_DISK}M; \ TOTAL_RAM=\$(awk '/MemTotal/ {print int(\$2/1024)}' /proc/meminfo); \ VM_RAM=\$((TOTAL_RAM*70/100)); \ CPU_CORES=\$(nproc); \ echo \"Detected RAM: \$TOTAL_RAM MB\"; \ echo \"Allocating VM RAM: \$VM_RAM\"; \ echo \"Allocating VM DISK: \$VM_DISK MB\"; \ echo \"Detected CPU Cores: \$CPU_CORES\"; \ qemu-system-x86_64 \ -m \$VM_RAM \ -smp \$CPU_CORES \ -cpu EPYC \ -drive file=/vm/ubuntu22/ubuntu22.qcow2,format=qcow2,if=virtio \ -drive file=/vm/ubuntu22/seed.iso,format=raw,if=virtio \ -net nic \ -net user,hostfwd=tcp::2222-:22 \ -nographic & \ code-server --bind-addr 0.0.0.0:7860 --auth none"