Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric import *
- from fabric import transfer
- #connecting to the instance
- c = Connection('i-0a1fc1786ff0ca089')
- #installing the packages - nginx,unzip, pip, virtualenv
- c.sudo('apt-get update')
- c.sudo('apt-get install nginx -y')
- c.sudo('apt-get install unzip -y')
- c.sudo('apt install python-pip -y')
- c.sudo('apt-get install python3-venv -y')
- #creating a virtualenv for our django project
- c.sudo('mkdir -p /opt/wwc/mysites')
- c.sudo('python3 -m venv /opt/wwc/mysites/virtualenv')
- #setting permission to ubuntu user to run everything smoothly
- c.sudo('chown -R ubuntu:ubuntu /opt/wwc/*')
- #installing django project dependencies
- c.run('/opt/wwc/mysites/virtualenv/bin/pip install "django==2.1"')
- c.run('/opt/wwc/mysites/virtualenv/bin/pip install boto3')
- #importing the project from local server to the instance
- c.put('lab.zip', remote='/opt/wwc/mysites/', preserve_mode=True)
- #copying the nginx config file from local to instance
- c.put('default.txt', remote='/opt/wwc/mysites/', preserve_mode=True)
- c.sudo('rm /etc/nginx/sites-available/default')
- c.sudo('mv /opt/wwc/mysites/default.txt /etc/nginx/sites-available/default')
- #restarting nginx to impliment changes to config file
- c.sudo('service nginx restart')
- #extracting the project
- c.sudo('unzip /opt/wwc/mysites/lab.zip -d /opt/wwc/mysites/')
- #running the server
- c.sudo('/opt/wwc/mysites/virtualenv/bin/python /opt/wwc/mysites/lab/manage.py runserver 8000')
Add Comment
Please, Sign In to add comment