Django, Python3, Codeship, Ansible and Github for Continuous Integration / Delivery

1) Ansible deploy script: The Ansible project is a separate github repo
2) Codeship account & project setup

For testing and deploying we need access to multiple github repos (at least the project itself and the deploy-the-project repo). Codeship does not support this. However there is a decent solution available on the Github side.

Note: The doc says it’s not possible to enable read-only team members however this is now possible on Github in the add a team member settings.

The public key to be added is the one from the Codeship General settings.

Codeship testing pipeline:

# make python3 work according to codeship docs
rm -rf ${HOME}/.virtualenv
virtualenv -p $(which python3) "${HOME}/.virtualenv"
# this is where the database and media is created
mkdir -p ${HOME}/somedir
# env variables
export EP_DJANGO_DEBUG=false
# get it up and running
pip install -r requirements.txt
python migrate --noinput

Codeship delivery pipeline:

Note: In your ansible.cfg you need to disable ControlPersist since this is not compatible with the platform Codeship uses (you could also try using the python library paramiko instead of openssh). Disabling ControlPersist might have an impact on the performance of the ansible script.

ssh_args = -o ControlMaster=auto
# this is the default value: ssh_args = -o ControlMaster=auto -o ControlPersist=60s

Delivery Pipeline Script:

# switch back to python2 because ansible does not support python3
rm -rf ${HOME}/.virtualenv
virtualenv -p $(which python) "${HOME}/.virtualenv"
pip install ansible
pip install boto
git clone
# and deploy
cd ./your-project
chmod 600 project-ssh-private-key.pem
./deploy production 3-deploy.yml -vv