Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add PROJECT_DISK_SIZE_GB to add Projects disk #69

Merged
merged 10 commits into from
Apr 5, 2024
17 changes: 13 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.env.enable # plugin vagrant-env

# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = ENV['VM_BOX'] || "bento/debian-10.10"
config.vm.box_version = "202107.08.0"

config.env.enable # plugin vagrant-env
config.vm.box = ENV['VM_BOX'] || "bento/debian-12"
config.vm.box_version = ENV['_VER_VM_BOX'] || "202309.08.0"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
Expand All @@ -32,6 +32,8 @@ Vagrant.configure("2") do |config|
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
ssh_port = ENV['SSH_PORT'] || "3222"
config.vm.network "forwarded_port", guest: 22, host: ssh_port, host_ip: "0.0.0.0", id: 'ssh'
forwarded_ports = (ENV['FORWARDED_PORTS'] || "443").split(',')
forwarded_ports.each { |forwarded_port|
port = forwarded_port.to_i
Expand Down Expand Up @@ -94,6 +96,13 @@ Vagrant.configure("2") do |config|
vb.customize ['createhd', '--filename', disk_filename, '--variant', 'Fixed', '--size', docker_disk_size.to_i * 1024]
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--type', 'hdd', '--medium', disk_filename]
end
project_disk_size = ENV['PROJECT_DISK_SIZE_GB']
disk_filename = (ENV['VMDISK_LOCATION'] || "") + "#{machine_name}.projects.#{project_disk_size}.vdi"
if project_disk_size && !File.exist?(disk_filename)
vb.customize ['createhd', '--filename', disk_filename, '--variant', 'Fixed', '--size', project_disk_size.to_i * 1024]
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--type', 'hdd', '--medium', disk_filename]
end

end

# Enable provisioning with a shell script. Additional provisioners such as
Expand Down
36 changes: 26 additions & 10 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ fi

vm_hosts_vars=$(set | grep "__VMHOSTS__[^=]\+=" | cut -c 12-)
$ssh << EOSSH
echo --------------------- Removing vagrant password
passwd vagrant --delete > /dev/null
echo ---------------------
echo Adding $username to Sudoer
usermod -aG sudo $username
Expand Down Expand Up @@ -225,32 +227,41 @@ ssh $machine_name "touch ~/.hushlogin"
#### user $username
ssh $machine_name << EOSSH

echo "==============================\nHello from $machine_name, \$(whoami)"
echo "==============================
Hello from $machine_name, \$(whoami)"
sudo apt remove vim -y
sudo apt update && sudo apt install \
git \
zsh \
vim-gtk \
vim \
python3-pip \
tmux \
dnsutils \
pass gnupg2 \
-y

if [ "\$?" -eq 0 ]; then
if [ -f ~/.oh-my-zsh/oh-my-zsh.sh ]; then
echo "-----\noh my zsh is aleady installed"
echo "-----
oh my zsh is aleady installed"
else
echo "-----\nInstalling oh my zsh...."
echo "-----
Installing oh my zsh...."
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh --unattended
rm -f install.sh*
sh install.sh --unattended && \
rm -f install.sh* && \
sudo chsh -s /bin/zsh $username
fi
fi

if [ "\$?" -eq 0 ]; then
if [ -f "/usr/local/bin/docker-compose" ]; then
echo "-----\ndocker-compose aleady exists"
echo "-----
docker-compose aleady exists"
docker-compose --version
else
echo "-----\nInstalling docker-compose...."
echo "-----
Installing docker-compose...."
sudo pip3 install requests --upgrade
dc_version=\${COMPOSE_VERSION:-1.29.2}
dc_version_url=/docker/compose/releases/download/\${dc_version}/docker-compose-\$(uname -s)-\$(uname -m)
Expand All @@ -264,12 +275,16 @@ else
docker-compose --version
fi
fi
fi

if [ "\$?" -eq 0 ]; then
mkdir -p ~/Projects
if [ -d ~/samba ]; then
echo "-----\nSamba config is found. skipping to create"
echo "-----
Samba config is found. skipping to create"
else
echo "-----\nConfiguring samba"
echo "-----
Configuring samba"
mkdir -p samba
cp /vagrant/config/samba/* samba/
cd samba
Expand All @@ -279,6 +294,7 @@ else
chmod +x adduser
./adduser \$USER
fi
fi

if [ -f "/dummy" ]; then
filesize=\$(stat -c%s "/dummy")
Expand Down
2 changes: 1 addition & 1 deletion config/env_var.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export VERSION=20.10.8
export VERSION=
16 changes: 9 additions & 7 deletions config/vm.docker.disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ add_docker_disk_to_fstab () {
echo "$partition /mnt/$partition_name ext4 defaults,nofail 0 2 # by linuxdev startup script" >> /etc/fstab
echo Added $partition to /etc/fstab
mount -a
mkdir -p /mnt/$partition_name/var/lib/docker
echo "/mnt/$partition_name/var/lib/docker /var/lib/docker ext4 bind,defaults,nofail 0 0 # by linuxdev startup script" >> /etc/fstab
echo Added docker lib directory to /etc/fstab
service docker stop
mount -a
service docker start
echo Restarted docker daemon
if [ -z "$(grep /var/lib/docker /etc/fstab)"]; then
mkdir -p /mnt/$partition_name/var/lib/docker
echo "/mnt/$partition_name/var/lib/docker /var/lib/docker ext4 bind,defaults,nofail 0 0 # by linuxdev startup script" >> /etc/fstab
echo Added docker lib directory to /etc/fstab
service docker stop
mount -a
service docker start
echo Restarted docker daemon
fi
else
echo $partition found on /etc/fstab. skipping to add
fi
Expand Down
7 changes: 5 additions & 2 deletions destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ vagrant destroy

machine_name=${NAME:-linuxdev}

vagrant status $machine_name
vagrant status

if [[ $? != 0 ]];then
exitCode=$?

if [[ $exitCode != 0 ]];then
echo the VM is not exists any more, removing configs
mkdir -p backup
mv ssh.config* backup/
rm -rf ~/.docker/certs.$machine_name
exit $exitCode
fi
Loading