forked from CTFd/CTFd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
64 lines (49 loc) · 1.97 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Install tmux and virtualenv to support development
$preProvision= <<SCRIPT
sudo apt-get install tmux virtualenvwrapper mariadb-server -y
SCRIPT
# Wrap provisioning script with a virutalenv for pip packages
$provision= <<SCRIPT
source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh
mkvirtualenv ctfd
workon ctfd
cd /vagrant
./prepare.sh
pip install -r development.txt
echo "Initialising database"
commands="CREATE DATABASE ctfd;
CREATE USER 'ctfduser'@'localhost' IDENTIFIED BY 'ctfd';
GRANT USAGE ON *.* TO 'ctfduser'@'localhost' IDENTIFIED BY 'ctfd';
GRANT ALL privileges ON ctfd.* TO 'ctfduser'@'localhost';FLUSH PRIVILEGES;"
echo "${commands}" | sudo /usr/bin/mysql -u root -pctfd
SCRIPT
# Start development server in a tmux session
$startServer= <<SCRIPT
source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh
workon ctfd
export DATABASE_URL="mysql+pymysql://ctfduser:ctfd@localhost/ctfd"
cd /vagrant
python manage.py db upgrade
echo "Starting CTFd"
tmux new-session -d -n "ctfd" -c "/vagrant" -s "ctfd" "gunicorn --bind 0.0.0.0:8000 -w 4 'CTFd:create_app()'"
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
# Create a private network, which allows host-only access to the machine
config.vm.network "private_network", ip: "10.9.8.7"
# Forward the default port for the development server (4000)
# and docker or gunicorn (8000) to host machine
config.vm.network "forwarded_port", guest: 4000, host: 4000
config.vm.network "forwarded_port", guest: 8000, host: 8000
# Pre-provision
config.vm.provision "shell", inline: $preProvision
# Provisioning scripts
config.vm.provision "shell", inline: $provision, privileged: false
# Start server in tmux session (every reboot)
config.vm.provision "shell", inline: $startServer, privileged: false,
run: "always"
# Install docker (convenience)
config.vm.provision "shell", path: "scripts/install_docker_ubuntu.sh"
end