A tool to assist deployments for Eryx infraestructure
pip install eryxdeploy==0.4.7
Object-oriented devops. Period.
BETA status.
Add eryxdeploy
to your dev.txt / local.txt requirements and update them. (Create a new file and a virtualenv
if your project is not a python project.)
Create a python package in your project root called devops
with 2 empty files: secrets.json
and stacks.py
.
Add devops/secrets.json
to .gitignore
. This file will be used to store info that is insecure to share in your repo.
Create an empty fabfile.py
file on your project's root dir, importing this lib and the stacks
package:
from eryx_deploy import *
from devops import stacks
Configure your app stack(s) in devops/stacks.py
.
Example:
import json
from fabric.state import env
from eryx_deploy import DjangoBasicStack, UbuntuMachine, AmazonRDSMachine, SassCompileWithGrunt, NPM
secrets = json.load(open('devops/secrets.json'))
env.local_stack = DjangoBasicStack(host=UbuntuMachine.new_local(project_path=secrets['local_project_path']),
project_name='project_xxx',
db_name='project_xxx_dev',
db_user=secrets['local_db_user'],
db_password=secrets['local_db_password'],
remote_url='git@gitlab.com:eryx/project_xxx.git',
requirements_file_path='requirements/local.txt',
virtual_env_path=secrets['local_virtual_env_path'],
web_assets_pipeline=SassCompileWithGrunt,
frontend_package_manager=NPM)
env.stacks['staging'] = DjangoBasicStack(host=UbuntuMachine.new_remote(hostname='project_xxx.eryx.co',
ssh_connection='project-xxx',
project_path=secrets['staging_project_path']),
project_name='project_xxx',
db_name='project_xxx_staging',
db_user=secrets['staging_db_user'],
db_password=secrets['staging_db_password'],
db_port=secrets['staging_db_port'],
db_server=AmazonRDSMachine(
hostname=secrets['staging_db_server']),
remote_url='git@gitlab.com:eryx/project_xxx.git',
requirements_file_path='requirements/master.txt',
virtual_env_path='%s/bootstrap' % secrets['staging_project_path'],
web_assets_pipeline=SassCompileWithGrunt,
frontend_package_manager=NPM)
The only required thing here is to set the env.stacks
dictionary with an app stack tied to an environment
configuration. In the example above, we're setting the staging
environment with a DjangoBasicStack
instance.
Configuring a local_stack
with your workstation configuration is also recommended as some devops tasks depends
on it.
Please check eryx_deploy/app_stacks
directory for configuring this and other app stacks.
Add your secrets in JSON format on devops/secrets.json
.
You are now ready to run tasks on your app stacks! Before finishing, please take a moment to document deployment instructions on your README.md to help you and other developers in the future.
To perform an initial deploy of your remote stack on a specific environment, just run from the command line:
$ fab --set env=ENV first_deploy
Replace ENV
for staging
, production
or other environments.
To upgrade your remote stack from your local machine, just run:
$ fab --set env=ENV deploy
Replace ENV
for staging
, production
or other environments.
To sync your local db with the db from a remote environment, just run:
$ fab --set env=YOUR_ENV sync_local_db
Replace YOUR_ENV
for staging
, production
or other environments.
You can configure additional global settings on your fabfile.py
.
env.confirm_before_run
: Ask for confirmation before running EVERY command.
Disable after you are confident with the tool. Default: True.env.allow_skipping_cmd
: Allows skipping commands: Saying NO when asking for confirmation to run a command,
will ask again if you want to abort or continue. Useful for debugging. Default: False.Check default_config.py
for all options.
App stacks are configured using many different technology assets. Please check assets
dir for all the available
classes, segmented by technology type.
Rename your secrets.py
to secrets.json
and format the values as a JSON. Change .gitignore
accordingly.
Change stacks.py
to use secrets from the new file. Check example above to see how to import the JSON file.
Django project with PostgreSQL 9.5, Nginx with Gunicorn, NPM, SASS with grunt, on:
Django project with PostgreSQL 9.5, Nginx with Gunicorn, on:
Ruby on Rails project with PostgreSQL 9.5, Nginx with Gunicorn, on:
Please add your scenario to this list after testing!
Clone this repo on your machine.
Make sure to install dev_requirements.txt on a new virtual environment.
On the project you are using the tool, uninstall the stable version with pip uninstall eryxdeploy
and install a local copy with:
$ pip install -e /path/to/eryxdeploy
Any changes you make on the cloned repo will be available instantly from your project.
To debug from a Jetbrain IDE, add a python runner with a full path to fab
binary installed on your project's
virtualenv (NOT from erxydeploy's project, but from the project
were eryxdeploy is installed!). Open eryxdeploy source directly from your project and add a breakpoint there.
Assets are divided by technology. Any new asset of an existing technology type, like a new frontend package manager should subclass from the corresponding abstract class. Any new type of technology should define a new package dir and an abstract class. Asset constructors should provide default collaborators when possible. The criteria here is to use the most COMMON/DEFAULT implementation.
Machines are an important/special kind of asset. Those assets are responsible for performing the actions ultimately. Most other assets collaborate with machines.
When creating a new app stack, try to define all configuration parameters directly from the constructor. Add most RECOMMENDED default assets (considering nowadays standards) if the stack can use multiple variants.
As this is a library, make sure not to break backwards-compatibility unless is really necessary. Some guidelines:
__init__
signature of any asset will probably break compatibility. If you add a new parameter, set a
default value.__init__
signature.__init__.py
files so the user of the lib can always import doing eryx_deploy.AssetClass
, no
matter internal package organization.__init__
on subclasses unless you are sure what you are doing.$ python test.py
No tests for now!
You must have an account on https://pypi.python.org to upload a new version.
Be sure to move version number up first.
Create package and upload with:
$ python setup.py bdist_wheel
$ twine upload dist/*
0.4.7 (01/08/2019)
0.4.6 (08/10/2018)
0.4.5 (01/10/2018)
0.4.4 (20/03/2018)
0.4.3 (05/03/2018)
0.4.2 (16/01/2018)
0.4.1 (20/12/2017)
0.4.0 (19/12/2017)
0.3.0 (02/11/2017)
0.2.0 (27/10/2017)