Skip to content

Instantly share code, notes, and snippets.

@robertfyffe
Forked from okovalov/fabric_virtualenv_pip.txt
Last active September 8, 2016 19:05
Show Gist options
  • Save robertfyffe/6122588fe8940001e347db80eac9e606 to your computer and use it in GitHub Desktop.
Save robertfyffe/6122588fe8940001e347db80eac9e606 to your computer and use it in GitHub Desktop.
To be able to use Fabric for deployments there are a few requirments:
- you need to be able to ssh to the deployment server
- your Python version should match a certain required one
- you must have `pip` installed
- you must have `virtualenv` installed
- you must have `fabric` installed inside your virtual environment (please read about virtual env below)
Note about SSH: Fabric uses ssh to connect to the sever, so before you even
start with Fabric please make sure your computer (user) public key is added to the
server's authorized hosts. You should be able to ssh into the server without being prompted
for a password.
Once you have SSH connection between a `deployer` computer and a `server` running, you can proceed with installing Fabric.
Notes about Fabric:
- All the Fabric related commands are called from within the virtual environment.
- The Virtual environment is created by a package that is called `virtualenv`. This package is
installed globally on your system (inside of your real environment) by `pip`.
- Fabric is another package and it also is installed by `pip`. This is not installed globally, ONLY inside of your virtual environment.
So what is `pip`?
`pip` is a package management system used to install and manage software packages written in Python.
Many packages can be found in the Python Package Index (PyPI).
Prerequisites to install Fabric are to install `pip` and to install `virtualenv`.
Installing PIP:
1) Ubuntu: sudo apt-get install -y python-pip python-dev
2) MacOS: `brew install python`
BEFORE running the command, please check your python version by doing `python --version`.
If you have version Python 2 >=2.7.9 or Python 3 >=3.4, you likely already have `pip` installed. To ensure PIP is running the latest version you can run `pip install -U pip`
A few links to read
https://pip.readthedocs.io/en/stable/installing/
https://pip.readthedocs.io/en/stable/installing/#upgrading-pip
Assuming you have your `pip` installed the next step is to install virtualenv with `pip install virtualenv`.
Assuming you have `virtualenv` installed, the next step is to choose the folder that you would like to create your virtual
environment in. That folder should be one level up from your application folder.
E.g.
App Code: ~/prj/ProjectOne/project-one-source-code
Virtual Env: ~/prj/ProjectOne/
Install Virtual environment:
1) cd ~/prj/ProjectOne/
2) `virtualenv dep-env`
Running `virtualenv dep-env` will create another folder `~/prj/ProjectOne/dep-env` and install the virtual environment there.
1) `cd ~/prj/ProjectOne/dep-env`
2) `source bin/activate`
Once you've done this you are then inside your virtual environment where you would need to install Fabric.
Install Fabric:
1) `pip install fabric`
Setup `fabfile.py`
1) Add `fabfile.py` to application root directory so that the path to the file looks something similar to `~/prj/ProjectOne/project-one-source-code/fabfile.py`
Deploy To Staging:
1) `cd ~/prj/ProjectOne/project-one-source-code/`
2) `fab set_env:stage deploy`
To exit from your virtual env and come back to a real env please run `deactivate`.
Deployment Summary:
- `cd ~/prj/ProjectOne/dep-env`
- `source bin/activate`
- `cd ~/prj/ProjectOne/project-one-source-code/`
- `fab set_env:stage deploy`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment