Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding fabric ENVS, create sync task. #1337

Closed

Conversation

joshcartme
Copy link
Collaborator

This is a bit of a work in progress.

Update the FABRIC dictionary to be expected to look like this (the old style will still work as well):

FABRIC = {
    "DEFAULT": {
        "SSH_USER": "", # SSH username for host deploying to
        "HOSTS": ALLOWED_HOSTS[:1], # List of hosts to deploy to (eg, first host)
        "DOMAINS": ALLOWED_HOSTS, # Domains for public site
        "REPO_URL": "[email protected]/amezzproj.git", # Project's repo URL
        "VIRTUALENV_HOME":  "", # Absolute remote path for virtualenvs
        "PROJECT_NAME": "", # Unique identifier for project
        "REQUIREMENTS_PATH": "requirements.txt", # Project's pip requirements
        "LOCALE": "en_US.UTF-8", # Should end with ".UTF-8"
        "DB_PASS": "this-is-not-a-real-password", # Live database password
        "ADMIN_PASS": "this-is-not-a-real-password", # Live admin user password
        "SECRET_KEY": SECRET_KEY,
        "NEVERCACHE_KEY": NEVERCACHE_KEY,
    },
    'DEV': {
        "SSH_USER": "dev",
        "HOSTS": ['dev.example.com'],
        "VIRTUALENV_HOME": "/home/dev",
    },
    'PROD': {
        "SSH_USER": "prod",
        "HOSTS": ['www.example.com'],
        "VIRTUALENV_HOME": "/home/prod",
        "DB_PASS": "xyz---abc---zyx",
    }
}

In the above DEV and PROD are optional dictionaries that can override values in the DEFAULT dictionary. DEV and PROD are not required and any other names or number of dictionaries can be used.

To have a non default dictionary override pass --set FABENV=ENV to any fabric command where ENV is a key in the FABRIC dictionary. For example:

$ fab all --set FABENV=DEV

would call the all task and override any values in DEFAULT that are also in DEV with the values from DEV.

If no overrides are desired call fabric commands like normal, i.e.:

$ fab all

My motivation for the above changes was to create a sync command that will sync the database and static files from one environment to another (this command is also included in the pull request). The usage of it would be:

$ fab sync_to:PROD --set FABENV=DEV

Fabric hosts can technically be a list of hosts, I don't think this will support that as is so if that should be supported it will take some more work. If anyone has thoughts on the best way to do that let me know!

@stephenmcd
Copy link
Owner

Only glanced at the code, but I like the idea.

@joshcartme
Copy link
Collaborator Author

Cool, what do you think @jerivas, I think you had done the most recent work on the fabfile.

@jerivas
Copy link
Collaborator

jerivas commented Jun 23, 2015

Nice idea! A few things:

  • Are you going to update local_settings.py.template with the new format for the FABRIC dict?
  • GUNICORN_PORT and REPO_URL were dropped, so no need to define them in the settings.
  • I think you're missing a newline in line 88.

@stephenmcd
Copy link
Owner

I think with the sync_foo commands, it'd be good to add a big red warning with a prompt to confirm, something like:

You're about to overwrite the database and uploaded media in FOO with database and uploaded media from BAR. Are you sure?

(where FOO and BAR are the env names in the FABRIC dict)

We'd also need an optional arg to these, akin to --no-input elsewhere, that disables the prompt so that people can still automate the commands if they want to.

The thinking here is that judging from some of the mailing list posts, a lot of people expect there to be a way to automatically do this without actually overwriting data, and they expect a tool like this to somehow magically merge the environments, so it needs to be very clear that's not what's happening.

What do you guys think?

@joshcartme
Copy link
Collaborator Author

Thanks for the feedback guys!

@jerivas I've updated the FABRIC dict in local_settings.py.template, removed GUNICORN_PORT from the example, and added the missing newline.

@stephenmcd I think that the confirm message was a really good idea and will save a lot of headaches for us and users in the future. I've just added a confirm to the beginning of sync_to, the task that calls the other sync tasks. Do you think there should be more than one confirm? I also added a no_input argument to sync_to, I specifically tested no_input != 'True' because fabric passes all arguments as strings.

I think it would be good to get some more people to test the sync_to command before we merge this. It is working for me in a production environment, but that is using the old fabric file.

@jerivas
Copy link
Collaborator

jerivas commented Jun 25, 2015 via email

@joshcartme
Copy link
Collaborator Author

Good call @jerivas, just updated the docs. I'd appreciate it if a few people could give it a read through to make sure it makes sense.

Also, It would still be good for others to test the sync command. Thanks!

@jerivas
Copy link
Collaborator

jerivas commented Jun 26, 2015 via email

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 5.0.0-rc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants