Version: 1.2 Date: 15/9/2018 Author: David Glance
- Install and configure Fabric
- Deploy a server with nginx installed and configured by Fabric
- Deploy Django code using Fabric
Ubuntu AWS Python Fabric
The aim of this lab is to write a program that will:
[1] Background and basics to Fabric [2] How to automatically deploy a server using Fabric
Use your existing code to create an EC2 instance that you will test your Fabric-based installation on.
NOTE do this on your VirtualBox VM
The easiest way to install fabric is to:
pip install fabric
You will need to create a config file in ~/.ssh with the contents:
Host <ec2instance>
Hostname <EC2 instance public DNS>
User ubuntu
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile <path to your private key>
You can test fabric from the command line:
Remember to rplace with your EC2 name you used in the configuration - use your student number to identify resources.
python
>>> from fabric import Connection
>>> c = Connection(‘<ec2instance>’)
>>> result = c.run(‘uname -s’)
Linux
>>>
Write a python script using fabric to set up and configure nginx as you did for the Django app last week
This will consiste of doing the same commands you would do manually to configure nginx but using the commands:
sudo("commands go here separated by ;")
and/or
run("Commands go here separated by ;")
You will copy the files from your local directory to the new EC2 instance. You may find this easier if you create a tar/zip file first of the code and then untar/unzip on the EC2 machine.
Add the necessary commands to configure the virtual environment and clone your Django app from your local directory - this is basically taking the instructions you used in that lab and converting them to Fabric commands.
The final command should be the command to run the server - if you add an '&' at the end it will run the process in the background. Note - you would normally use Gunicorn to do this not manage.py runserver but we are keeping it simple.
The documentation for Fabric is here: http://docs.fabfile.org/en/2.0/
Lab Assessment:
This semester all labs will be assessed as "Lab notes". You should follow all steps in each lab and include your own comments. In addition, include screenshots showing the output for every commandline instruction that you execute in the terminal and any other relevant screenshots that demonstrate you followed the steps from the corresponding lab. Please also include any linux or python script that you create and the corresponding output you get when executed. Please submit a single PDF file. The formatting is up to you but a well organised structure of your notes is appreciated.