-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDB.Vagrantfile
70 lines (50 loc) · 2.6 KB
/
DB.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
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = 'digital_ocean'
config.vm.box_url = "https://github.com/devopsgroup-io/vagrant-digitalocean/raw/master/box/digital_ocean.box"
config.ssh.private_key_path = '~/.ssh/do_ssh_key'
config.vm.synced_folder "remote_files", "/minitwit-db", type: "rsync"
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.define "minitwit-db", primary: true do |server|
server.vm.provider :digital_ocean do |provider|
provider.ssh_key_name = "do_ssh_key"
provider.token = ENV["DIGITAL_OCEAN_TOKEN"]
provider.image = 'ubuntu-22-04-x64'
provider.region = 'fra1'
provider.size = 's-1vcpu-1gb'
end
server.vm.hostname = "minitwit-postgres"
server.vm.provision "shell", inline: 'echo "export DOCKER_USERNAME=' + "'" + ENV["DOCKER_USERNAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DOCKER_PASSWORD=' + "'" + ENV["DOCKER_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_USER=postgres" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_PASSWORD=password" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_DB=minitwit" >> ~/.bash_profile'
server.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
# The following address an issue in DO's Ubuntu images, which still contain a lock file
sudo killall apt apt-get
sudo rm /var/lib/dpkg/lock-frontend
# Install docker and docker compose
sudo apt-get install -y docker.io docker-compose
sudo systemctl status docker
# sudo usermod -aG docker ${USER}
echo -e "\nVerifying that docker works ...\n"
docker run --rm hello-world
docker rmi hello-world
echo -e "\nOpening port for minitwit ...\n"
ufw allow 5432 && \
ufw allow 22/tcp
echo ". $HOME/.bashrc" >> $HOME/.bash_profile
echo -e "\nConfiguring credentials as environment variables...\n"
source $HOME/.bash_profile
echo -e "\nSelecting Minitwit Folder as default folder when you ssh into the server...\n"
echo "cd /minitwit-db" >> ~/.bash_profile
# Add this just before the final SHELL
echo -e "\nStarting PostgreSQL container...\n"
cd /minitwit-db && bash deploy-db.sh
echo -e "\nVagrant setup done ..."
echo -e "PostgreSQL database will be accessible at $(hostname -I | awk '{print $1}'):5432"
SHELL
end
end