Skip to content

Deployment with Ansible

Filipe edited this page Jan 13, 2023 · 10 revisions

This gets a copy of openfoodnetwork from a git repo that your specify (in vars.yml), put it onto the server, and then does ruby/rake/rails tasks and configuration needed so that it can run. The main tasks accomplished are:

  • copy OFN from a git repo to the server
  • create the database if needed
  • run database migrations
  • precompile assets used by OFN
  • creates seed data
  • creates an initial admin user

This list isn't comprehensive; those are the highlights.

⚠️ For all ofn-install tasks make sure you update your local repos ofn-install and ofn-secrets.

Running the deploy playbook

Assuming you want to deploy to es-staging host, run the following command:

ansible-playbook playbooks/deploy.yml --limit es-staging

(with -vvvv for full debug output)

Replace es-staging with your own host as specified in inventory/hosts file.

There is a timestamped backup process included in deployment and a rollback version saved each time.

Note deploys don't require access to secrets files.

Setting the version to deploy

By default the deploy playbook will deploy OFN as it is in master branch.

To deploy a specific version just modifiy the git_version in inventory/group_vars/all.yml. You can supply the version on the command line as well or define a Github slug, for example:

ansible-playbook playbooks/deploy.yml --limit es-staging -e "github_key=mkllnk:4018-synchronise-checkout"
ansible-playbook playbooks/deploy.yml --limit=au-prod -e "git_version=v2.2.2"

Server groups

You can make use of the existing server groups to execute multiple deployments in parallel, so far only Europe. You can use it as follows:

ansible-playbook playbooks/deploy.yml --limit=europe -e "github_key=openfoodfoundation:v2.2.2"

To deploy to all globally managed servers, you can use the all-prod server group:

ansible-playbook playbooks/deploy.yml --limit=all-prod -e "github_key=openfoodfoundation:v2.5.0"

Rollback

If the deployment script fails after the "Create a repo backup version" task you may need to roll it back to have a functional site, by running:

ansible-playbook rollback.yml -i staging

Failures before this don't need rollback, and it will not run. Just run deployment again. This could be automated at some point.

Backup

Backups will be stored by default in ofn_deployment/backups.

To backup on the server and to the local machine run:

ansible-playbook backup.yml -i staging

Note: This doesn't clean up old backups automatically yet.