Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Vagrant.configure("2") do |config|
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Flask
config.vm.network "forwarded_port", guest: 5000, host: 5000
# Django
config.vm.network "forwarded_port", guest: 8000, host: 8000
# Display webpages served by server on VM on port 8080 on host machine
config.vm.network "forwarded_port", guest: 80, host: 8080



# Create a private network, which allows host-only access to the machine
# using a specific IP.
Expand Down Expand Up @@ -64,5 +72,15 @@ Vagrant.configure("2") do |config|
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.

#config.vm.provision "shell", name: "root privisioning", inline: <<-SHELL
#echo "Updating sudoers"
# Set up sudo
#echo vagrant ALL=NOPASSWD:ALL > /etc/sudoers.d/vagrant
#chmod 0440 /etc/sudoers.d/vagrant
# Setup sudo to allow no-password sudo for "sudo"
#usermod -a -G sudo vagrant
#SHELL

config.vm.provision "shell", path: "provision.sh"
end
13 changes: 13 additions & 0 deletions gunicorn.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=vagrant
Group=www-data
WorkingDirectory=/home/vagrant/myproject
Environment="PATH=/home/vagrant/myproject/myprojectenv/bin"
ExecStart=/home/vagrant/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/vagrant/myproject/myproject.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target
54 changes: 53 additions & 1 deletion provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,60 @@ set -e
set -x



echo "provisioning!"

# TODO your code here
# https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

sudo apt-get update -y
sudo apt-get install python3-pip python3-dev nginx -y
sudo pip3 install virtualenv

# Set-up project environment
if [ -d "/home/vagrant/myproject" ];
then
echo "myproject exist."
else
echo "Creating myproject ..."

mkdir /home/vagrant/myproject
cd /home/vagrant/myproject

virtualenv myprojectenv

source myprojectenv/bin/activate

pip install gunicorn flask

deactivate

#Create a systemd unit file
sudo cp /vagrant/gunicorn.config /etc/systemd/system/myproject.service

#Update server settings
sudo cp /vagrant/server-defaults.txt /etc/nginx/sites-available/default
sudo cp /vagrant/server-myproject.txt /etc/nginx/sites-available/myproject

sudo ufw allow 'Nginx Full'

sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled

sudo chown -R vagrant myproject
fi


# Update project file
cp /vagrant/hello.py /home/vagrant/myproject/hello.py
cp /vagrant/wsgi.py /home/vagrant/myproject/wsgi.py

# Enable wsgi settings
sudo systemctl start myproject
sudo systemctl enable myproject

# Enable nginx server settings
sudo systemctl restart nginx


echo "provisioning complete!"
# Install virtualenv
echo "***** provisioning complete! ***** "
9 changes: 9 additions & 0 deletions server-defaults.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;


location / {
include proxy_params;
proxy_pass http://unix:/home/vagrant/myproject/myproject.sock;
}
}
9 changes: 9 additions & 0 deletions server-myproject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name 0.0.0.0;

location / {
include proxy_params;
proxy_pass http://unix:/home/vagrant/myproject/myproject.sock;
}
}
4 changes: 4 additions & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from hello import app

if __name__ == "__main__":
app.run()