-
Notifications
You must be signed in to change notification settings - Fork 45
/
Vagrantfile
137 lines (125 loc) · 4.31 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.box_check_update = false
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
config.vm.provider "virtualbox" do |vb|
# Hardware settings
vb.gui = true
vb.cpus = "4"
vb.memory = "8192"
# Video Settings with remote desktop disabled and other settings
vb.customize [ "modifyvm", :id,
"--vram", "256",
"--accelerate3d", "on",
"--vrde", "off",
"--graphicscontroller", "vboxsvga",
"--nested-hw-virt", "on",
"--clipboard-mode", "bidirectional"]
end
config.vm.provision "shell", inline: <<-SHELL
set -exo pipefail
whoami
echo $SHELL
export DEBIAN_FRONTEND=noninteractive
# sleep anywhere between 1 and 9 seconds
function random_sleep() {
local interval="$(tr -dc '1-9' < /dev/urandom | head -c1)"
sleep "$interval"
}
maxretries=300
count=0
function retry() {
until ( "$@" ); do
count=$((count + 1))
if [ "$count" -gt "$maxretries" ]; then
return 1
fi
random_sleep
done
}
retry apt-get update
retry apt-get install -y ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
retry /bin/bash -exo pipefail -c 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg'
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
> /etc/apt/sources.list.d/docker.list
chmod a+r /etc/apt/keyrings/docker.gpg
retry apt-get update
retry apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
retry snap install --classic code
retry apt-get install -y --no-install-recommends ubuntu-desktop gnome-startup-applications
retry apt-get install -y --no-install-recommends virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
# other applications
retry apt-get install -y firefox git
su - vagrant -c 'git config --global user.name "Your Name"'
su - vagrant -c 'git config --global user.email "you@example.com"'
mkdir -p ~vagrant/git
retry git clone https://github.com/samrocketman/jervis.git ~vagrant/git/jervis
usermod -a -G sudo vagrant
usermod -a -G docker vagrant
systemctl enable docker.service
systemctl start docker.service
retry curl -sSfLo /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64
chmod 755 /usr/local/bin/docker-compose
# wait for docker startup to complete
until curl -sSfLo /dev/null --unix-socket /var/run/docker.sock http://localhost/info; do
sleep 1
done
# startup automation
retry su - vagrant -c 'code --install-extension ms-vscode-remote.remote-containers'
retry su - vagrant -c 'code --install-extension ms-azuretools.vscode-docker'
mkdir -p ~vagrant/.config/autostart
cat > ~vagrant/.config/autostart/code.desktop <<'EOF'
[Desktop Entry]
Type=Application
Exec=code git/jervis
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[C]=Open VSCode with Jervis
Name=Open VSCode with Jervis
Comment[C]=
Comment=
EOF
mkdir -p ~vagrant/.config/Code/User/
cat > ~vagrant/.config/Code/User/settings.json <<'EOF'
{
"workbench.startupEditor": "none",
"telemetry.telemetryLevel": "off",
"dev.containers.dockerComposePath": "/usr/local/bin/docker-compose"
}
EOF
#auto login for vagrant
mkdir -p /etc/gdm3/
cat > /etc/gdm3/custom.conf <<'EOF'
[daemon]
AutomaticLoginEnable=True
AutomaticLogin=vagrant
[security]
[xdmcp]
[chooser]
[debug]
EOF
# Disable Package upgrade notifications
mkdir -p etc/update-manager/
cat > /etc/update-manager/release-upgrades <<'EOF'
[DEFAULT]
Prompt=never
EOF
cat > /etc/apt/apt.conf.d/10periodic <<'EOF'
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
EOF
cp -f /etc/apt/apt.conf.d/10periodic /etc/apt/apt.conf.d/20auto-upgrades
# Finalize and reboot to show VSCode automatically
chown -R vagrant: ~vagrant
retry apt-get upgrade -y
retry snap refresh
sudo reboot
SHELL
end