forked from pulp/devel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile.example
154 lines (130 loc) · 6.95 KB
/
Vagrantfile.example
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
# Synced folders are declared here,
# host => guest
VAGRANT_SYNCED_FOLDERS = {
# This code
'.' => '/vagrant',
# For access to sibling repos (e.g. pulp_rpm, pulp_docker, ...)
'..' => '/home/vagrant/devel',
# You can speed up package installs in subsequent "vagrant up" operations by making the dnf
# cache a synced folder. This is essentially what the vagrant-cachier plugin would do for us
# if it supported dnf, and unfortunately that project is in need of maintainers so this might
# be the best we can do for now. Note that you'll have to manually create the '.dnf-cache'
# directory in the same directory as this Vagrantfile for this to work.
#'.dnf-cache' => '/var/cache/dnf'
}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# It is possible to use URLs to nightly images produced by the Fedora project here. You can find
# the nightly composes here: https://kojipkgs.fedoraproject.org/compose/
# Sometimes, a nightly compose is incomplete and does not contain a Vagrant image, so you may need
# to browse that repository a bit to find the latest successful Vagrant image. For example, at the
# time of this writing, I could set this setting like this for the latest F24 image:
# config.vm.box = "https://kojipkgs.fedoraproject.org/compose/rawhide/latest-Fedora-Rawhide/compose/CloudImages/x86_64/images/<imagename>.vagrant-libvirt.box"
config.vm.box = "fedora/25-cloud-base"
# Comment out if you don't want Vagrant to add and remove entries from /etc/hosts for each VM.
# requires the vagrant-hostmanager plugin to be installed
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
end
# Comment this line if you would like to disable the automatic update during provisioning
config.vm.provision "shell", inline: "sudo dnf upgrade -y"
# bootstrap and run with ansible
config.vm.provision "shell", path: "scripts/bootstrap-ansible.sh"
config.vm.provision "ansible" do |ansible|
# Uncomment this if you want debug tools like gdb, tcpdump, et al. installed
# (you don't, unless you know you do)
# ansible.extra_vars = { pulp_dev_debug: true }
ansible.playbook = "ansible/vagrant-playbook.yml"
end
# Create the "dev" box
config.vm.define "dev" do |dev|
dev.vm.host_name = "dev.example.com"
VAGRANT_SYNCED_FOLDERS.each do |host_path, guest_path|
# By default, Vagrant wants to mount with NFSv3, which will fail. Let's
# explicitly mount the code using NFSv4.
dev.vm.synced_folder host_path, guest_path, type: "nfs", nfs_version: 4, nfs_udp: false
end
dev.vm.provider :libvirt do |domain, override|
domain.cpus = 4
# In some cases, the guest gets stuck at "Waiting for domain to get an IP address..." if
# the default cpu_mode, 'host-model', is used. Using 'host-passthrough' cpu_mode prevents
# VM migration between hosts with different CPUs. However, development environments are
# expected to live on a single host for the duration of their existence. Due to this known
# issue and our use case, the default cpu_mode is overridden.
domain.cpu_mode = "host-passthrough"
domain.graphics_type = "spice"
domain.memory = 2048
domain.video_type = "qxl"
# Uncomment this to expand the disk to the given size, in GB (default is usually 40)
# You'll also need to uncomment the provisioning step below that resizes the root partition
# do not set this to a size smaller than the base box, or you will be very sad
# domain.machine_virtual_size = 80
# Uncomment the following line if you would like to enable libvirt's unsafe cache
# mode. It is called unsafe for a reason, as it causes the virtual host to ignore all
# fsync() calls from the guest. Only do this if you are comfortable with the possibility of
# your development guest becoming corrupted (in which case you should only need to do a
# vagrant destroy and vagrant up to get a new one).
#
# domain.volume_cache = "unsafe"
# Uncomment this to resize the root partition and filesystem to fill the base box disk
# This script is only guaranteed to work with the default official fedora image, and is
# only needed it you changed machine_virtual_size above.
# For other boxen, use at your own risk
# override.vm.provision "shell", path: "scripts/vagrant-resize-disk.sh"
end
dev.vm.provider :docker do |d, override|
override.vm.box = nil
# Based on fedora official image, with vagrant's needs met:
# https://github.com/rohanpm/docker-fedora-vagrant
d.image = 'rohanpm/fedora-vagrant:25'
# use ssh for the sake of ansible
d.has_ssh = true
# Necessary for systemd to work
d.privileged = true
# Expose any ports other containers may want to connect to
d.expose = [80, 443, 5672, 27017]
VAGRANT_SYNCED_FOLDERS.each do |host_path, guest_path|
# Let the synced folders use docker's native mechanism
# (bind mounts) instead of NFS
override.vm.synced_folder host_path, guest_path, type: nil
end
# Reset the UID and GID of the vagrant user in the container equal to the
# UID/GID on the host. This makes it much easier to deal with the
# permissions on shared directories.
#
# This is only needed for docker, so it's declared here in the docker
# provider.
#
# This is a shell provisioner because it's impractical to apply it using
# ansible due to peculiar requirements: you cannot 'usermod' a user if that
# user has any processes currently running - including the ssh session that
# vagrant itself uses to connect to the container.
override.vm.provision 'reset-user', :type => 'shell' do |shell|
uid = Process.euid
gid = Process.egid
reset_cmd = "/vagrant/scripts/reset-vagrant-user.sh #{uid} #{gid}"
shell.inline = <<-END_SCRIPT.gsub(/\s+/, ' ').strip
nohup sudo /bin/sh -c '
if ! #{reset_cmd}; then
wall "About to kill all vagrant processes for UID reassign!";
sleep 2;
pkill -TERM -u vagrant;
sleep 1;
pkill -KILL -u vagrant;
#{reset_cmd};
fi
' >/tmp/reset-user.log 2>&1 &
END_SCRIPT
shell.privileged = false
end
end
dev.vm.provision "shell", inline: "sudo -u vagrant bash /home/vagrant/devel/devel/scripts/vagrant-setup.sh"
dev.vm.provision "shell", run: "always" do |s|
# only gofer and httpd strictly need this, but for consistency, we'll just restart them all
s.inline = "sudo systemctl restart goferd httpd pulp_celerybeat pulp_workers pulp_resource_manager"
end
end
end