Advertisement
umuro

VSCode KDE Vagrantfile

Mar 19th, 2025
136
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.19 KB | Fixit | 0 0
  1. Vagrant.configure("2") do |config|
  2.     config.vm.box = "bento/ubuntu-22.04"
  3.  
  4.     config.vm.provision "shell", inline: <<-SHELL
  5.       # Update system and install Kubuntu desktop
  6.       sudo apt-get update
  7.       sudo apt-get install -y kubuntu-desktop sddm
  8.  
  9.       # Set GUI as default boot mode
  10.       sudo systemctl set-default graphical.target
  11.       sudo systemctl enable --now sddm
  12.  
  13.       # Install VirtualBox Guest Additions
  14.       sudo apt-get install -y build-essential dkms linux-headers-$(uname -r)
  15.       sudo apt-get install -y virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
  16.  
  17.       # Enable VirtualBox services
  18.       sudo systemctl enable vboxadd.service
  19.       sudo systemctl start vboxadd.service
  20.  
  21.       # Install VS Code
  22.       wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
  23.       sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/
  24.       echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
  25.       sudo apt update
  26.       sudo apt install -y code
  27.  
  28.       # Enable automatic login to KDE
  29.       echo -e "[Autologin]\nUser=vagrant\nSession=plasma.desktop" | sudo tee /etc/sddm.conf.d/autologin.conf
  30.  
  31.       # Install Docker CLI inside the VM
  32.       sudo apt-get install -y docker.io
  33.       sudo usermod -aG docker vagrant
  34.  
  35.       # Ensure the docker socket is correctly owned
  36.       if [ -S /var/run/docker.sock ]; then
  37.         sudo chown root:docker /var/run/docker.sock
  38.         sudo chmod 666 /var/run/docker.sock
  39.       fi
  40.  
  41.       # Create a systemd service to manually bind the host Docker socket
  42.       cat <<EOF | sudo tee /etc/systemd/system/mount-docker-socket.service
  43.       [Unit]
  44.       Description=Bind-mount host Docker socket into VM
  45.       After=network.target
  46.       Requires=network-online.target
  47.       Wants=network-online.target
  48.       Before=docker.service
  49.  
  50.       [Service]
  51.       Type=oneshot
  52.       ExecStart=/bin/mount --bind /mnt/docker.sock /var/run/docker.sock
  53.       RemainAfterExit=true
  54.       ExecStop=/bin/umount /var/run/docker.sock
  55.  
  56.       [Install]
  57.       WantedBy=multi-user.target
  58.       EOF
  59.  
  60.       # Enable the Docker socket mount service
  61.       sudo systemctl daemon-reload
  62.       sudo systemctl enable --now mount-docker-socket
  63.     SHELL
  64.  
  65.     # Configure VM resources
  66.     config.vm.provider "virtualbox" do |vb|
  67.       vb.gui = true
  68.       vb.memory = "4096"
  69.       vb.cpus = 2
  70.       vb.customize ["modifyvm", :id, "--vram", "128"]
  71.       vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
  72.     end
  73.  
  74.     # Shared folder for file exchange between host and VM
  75.     config.vm.synced_folder "/home/umur", "/home/vagrant/host_share",
  76.       owner: "vagrant",
  77.       group: "vagrant",
  78.       mount_options: ["dmode=775,fmode=664"]
  79.  
  80.     # Conditionally mount the Docker socket if it exists
  81.     if File.exist?("/var/run/docker.sock")
  82.       config.vm.synced_folder "/var/run/docker.sock", "/mnt/docker.sock", type: "virtualbox"
  83.     else
  84.       puts "WARNING: Docker socket not found on host. Skipping mount."
  85.     end
  86.   end
  87.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement