-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathVagrantfile
99 lines (85 loc) · 3.83 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This Vagrantfile can be used with VirtualBox or Docker as a provider
# VirtualBox will be the default. To use Docker type:
#
# vagrant up --provider=docker
#
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# config.vm.box_version = "20200206.0.0"
config.vm.hostname = "ubuntu"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"
############################################################
# Provider for VirtualBox
############################################################
config.vm.provider :virtualbox do |vb|
vb.memory = "512"
vb.cpus = 1
# Fixes some DNS issues on some networks
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
############################################################
# Provider for Docker
############################################################
config.vm.provider :docker do |docker, override|
override.vm.box = nil
docker.image = "rofrano/vagrant-provider:ubuntu"
docker.remains_running = true
docker.has_ssh = true
docker.privileged = true
docker.volumes = ["/sys/fs/cgroup:/sys/fs/cgroup:ro"]
# Uncomment to force arm64 for testing images on Intel
# docker.create_args = ["--platform=linux/arm64"]
end
############################################################
# Copy some host files to configure VM like the host
############################################################
# Copy your .gitconfig file so that your git credentials are correct
if File.exists?(File.expand_path("~/.gitconfig"))
config.vm.provision "file", source: "~/.gitconfig", destination: "~/.gitconfig"
end
# Copy your ssh keys for github so that your git credentials work
if File.exists?(File.expand_path("~/.ssh/id_rsa"))
config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "~/.ssh/id_rsa"
end
if File.exists?(File.expand_path("~/.ssh/id_rsa.pub"))
config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub"
end
# Copy your .vimrc file so that your VI editor looks nice
if File.exists?(File.expand_path("~/.vimrc"))
config.vm.provision "file", source: "~/.vimrc", destination: "~/.vimrc"
end
############################################################
# Create a Python 3 environment for development work
############################################################
config.vm.provision "shell", inline: <<-SHELL
# Update and install
apt-get update
apt-get install -y vim git tree python3-dev python3-pip python3-venv apt-transport-https
apt-get upgrade python3
apt-get -y autoremove
# Create a Python3 Virtual Environment and Activate it in .profile
sudo -H -u vagrant sh -c 'python3 -m venv ~/venv'
sudo -H -u vagrant sh -c 'echo ". ~/venv/bin/activate" >> ~/.profile'
# Install app dependencies in virtual environment as vagrant user
sudo -H -u vagrant sh -c '. ~/venv/bin/activate && pip install -U pip && pip install wheel'
sudo -H -u vagrant sh -c '. ~/venv/bin/activate && cd /vagrant && pip install -r requirements.txt'
SHELL
######################################################################
# Add Redis database as a docker container
######################################################################
config.vm.provision "shell", inline: <<-SHELL
# Prepare Redis data share
sudo mkdir -p /var/lib/redis/data
sudo chown vagrant:vagrant /var/lib/redis/data
SHELL
# Add Redis docker container
config.vm.provision "docker" do |d|
d.pull_images "redis:alpine"
d.run "redis:alpine",
args: "--restart=always -d --name redis -h redis -p 6379:6379 -v /var/lib/redis/data:/data"
end
end