-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
44 lines (40 loc) · 1.88 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
Vagrant.configure("2") do |config|
# Dynamically set the machine name to the name of the current directory
current_dir_name = File.basename(Dir.getwd)
config.vm.define current_dir_name do |docker_vm|
docker_vm.vm.hostname = "ubuntu"
docker_vm.vm.provider :docker do |docker, override|
override.vm.box = nil
docker.git_repo = "git@github.com:calef/vagrant-docker-provider-ubuntu-latest.git"
docker.remains_running = true
docker.has_ssh = true
docker.privileged = true
docker.volumes = ["/sys/fs/cgroup:/sys/fs/cgroup:rw"]
docker.create_args = ["--cgroupns=host"]
end
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provision "file", source: "~/.ssh", destination: "/home/vagrant/.ssh_temp"
docker_vm.vm.provision "shell", inline: <<-SHELL
# Add a provisioner to change to a specific subdirectory of /vagrant upon login
# The subdirectory matches the name of the current directory on the host machine
echo 'cd /vagrant/#{current_dir_name}' >> /home/vagrant/.bashrc
# update the packages
sudo apt-get update
sudo apt-get install -y git
# copy the keys
mkdir -p /home/vagrant/.ssh
# Copy all files from .ssh_temp to .ssh directory
cp -r /home/vagrant/.ssh_temp/* /home/vagrant/.ssh/
# Remove temporary directory
rm -rf /home/vagrant/.ssh_temp
# Set the correct permissions for the .ssh directory and its contents
chmod 700 /home/vagrant/.ssh
chmod 600 /home/vagrant/.ssh/*
# Ensure the authorized_keys file also has correct permissions in case it exists
chmod 644 /home/vagrant/.ssh/authorized_keys
# Change ownership of all the files in .ssh to vagrant user
chown -R vagrant:vagrant /home/vagrant/.ssh
# cd /vagrant/#{current_dir_name} && [ -x script/bootstrap ] && ./script/bootstrap
SHELL
end
end