Giter Site home page Giter Site logo

deployotron's Introduction

Deployotron

Deployotron is a Drush command to simplify deploying new code to a Drupal site.

There's already a lot of ways to deploy ones Drupal site, from FTPing up the files to having Capistrano deploy the site when the build passes in Jenkins. Deployotron aims to be simple to use, but also usable as a part of a bigger setup.

Build Status Code Coverage Scrutinizer Quality Score

Overview

In order to keep things simple, we're working with a few assumptions:

That the code is in GIT, and that the root of the site is checked in.

That you can run Drush commands and GIT on the live webserver and the root of the site on the webserver is a git checkout, and

That you've set up Drush aliases to reach the live webserver.

For everyone's sanity, we suggest having a Drush alias file in sites/all/drush/<short-site-alias>.aliases.drushrc.php that defines relevant environments (production, dev, etc.), so that everybody is using the same settings.

And we suggest that deployotron is installed by copying it into the sites/all/drush folder and committed to the site repository. This ensures that everyone is running the exact same version of deployotron when deploying.

Setup

Clone Deployotron into sites/all/drush.

Create a <sitename>.aliases.drushrc.php file in the same directory, with the definition of the different environments.

Deployotron is configured for each alias by adding an array of options in the 'deployotron' key of the alias array (see the example later, if that didn't make any sense). All the double-dash options the deploy command takes can be specified this way, and it's recommended to at least define the 'branch' option to select a default branch to deploy.

Initialize the environments by doing an initial git clone of the codebase in the destination directories.

Usage

Deploying

To run the deployment, use a command like:

/var/www/site$ drush deploy @alias

To get a listing of all supported command line options, do a drush help deploy.

Example configuration:

$aliases['staging'] = array(
  'remote-host' => 'example.com',
  'remote-user' => 'deploy_user',
  'uri' => 'default',
  'root' => '/path',
  'deployotron' => array(
    'branch' => 'develop',
    'dump-dir' => '/backups', // Defaults to /tmp.
    'num-dumps' => 3, // Defaults to 5. 0 for unlimited.
    'post-deploy' => array(
      'sudo apache2 graceful',
      'drush -y fra',
    ),
  ),
);

As demonstrated, you can add external commands to be run before (pre-) or after (post-) the individual actions. All the possible options is listed in drush help deploy and drush deployotron-actions.

In addition to command line options you can add messages to be displayed to the deploying user by using the following keys:

  • message: Shown at confirmation and after deployment.
  • confirm_message: Shown at confirmation.
  • done_message: Shown after deployment.
  • confirm_message_<command>: Shown at confirmation for the <command>.
  • done_message_<command>: Shown after deployment for the <command>.

These can be useful to remind the user of extra manual steps, or other things they should be aware.

Recovering

In case everything goes to hell after a deployment, you can do another deployment using a known good revision, or use:

/var/www/site$ drush omg @alias

This will try to find recent database dumps, ask which to use and attempt to import the database and revert the codebase to the previous revision. It will not attempt to clear caches or restarting any services.

Help

Running drush deployotron-actions will give a full list of which commands uses which actions, and the options of all actions.

Sudo setup

To run sudo commands in pre/post hooks, you need to configure sudo to allow the command without a password.

Run:

sudo visudo -f /etc/sudoers.d/deployotron

And add something like following to the file (replacing deploy_user with the remote-user of the alias used for deployment):

deploy_user          ALL=(root) NOPASSWD: /usr/sbin/service apache2 graceful,/usr/sbin/service varnish restart

This allows deployotron to run "sudo service apache2 graceful" and "sudo service varnish restart".

deployotron's People

Contributors

arnested avatar kasperg avatar naxoc avatar xendk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deployotron's Issues

Dump file safety check.

For extra safety, we should check that the dump file ends with the "dump completed" line that mysqldump adds.

Refactor action strings

There seem to be a lot of nearly duplicated stings for an action:

  • Description
  • Shortname
  • Run message
  • Killswitch
  • Error message

See for example Apache2 restart.

I think it would be nice it these could be simplified but generating default from a single text-string and then allowing individual actions to override them if necessary.

Add Drush 7-dev to build matrix

As I've been running master branch of Drush on and off for some time, I'd say it works, but would be nice if we could get Travis word for it too.

D8 compatibility

Some things have changed:

  • Setting site offline is now the config system instead of variables.
  • cache-clear all in now cache-rebuild
  • Don't know if updb changed.

We should probably keep core compatibility on separate branches, as it doesn't make much sense to support multiple versions as long as deployotron is installed inside the site.

Compression of dumps

SQL dumps tends to be large without compression. We should compress them per default.

Dump file purging

In order to not fill up disks we should limit the number of dump files by deleting the oldest.

The hardest part is deciding on how many to keep

Additional actions for OMG

When doing a rollback it would be nice if Deployotron could perform additional tasks such as:

  1. Set the existing site offline before the rollback is initiated
  2. Keep the restored site offline (if it is in fact online)
  3. Clear caches after the site has been restored. This is especially usefull when using non-database cache backeds
  4. Update VERSION.txt
  5. Restart Apache and Varnish
  6. Set the site online again

VERSION.txt action

It would be create to have an action which could create/update a version.txt file when deploying.

I think this file should include:

  • The SHA which was deployed - preferably including tag and branch name
  • The time of deployment
  • The username of the user executing the deployment. I guess this would have to be taken from the local machine where the deployment was carried out.

Confusing error if the alias root is not set (or wrong)

I had an error in an alias file, but the error message I got seemed to be from git.

Here is the error message. Note the cd &&. It has nowhere to cd.

Sanity checking [7.29 sec, 8.99 MB]                                                                                 [status]   
Undefined index: root deployotron.actions.inc:290 [7.29 sec, 8.99 MB]                                                  [notice]
Executing: cd  && git diff-files --quiet --ignore-submodules --                                                                
  fatal: not a git repository (or any of the parent directories): .git                                                         
Repository not clean. [7.3 sec, 8.99 MB]                                                                            [error]    
sanity check failed. [7.3 sec, 8.99 MB]          

Deploying annotated tags

When trying to deploy an annotated tag, I get the following message:

Code not properly deployed, head is at {sha} now.
deploy code failed.

I haven't looked into this much and maybe its by design. Anyway, simple tags work fine.

Add latest tag to version.txt

When using Deployotron on dev/staging, it could be useful if the last tag of the branch deployed from was included in version.txt.

Move git fetch to SanityCheck

Moving the fetching out of deploy would mean lower downtime.

Secondly, we can check if the ref is available and catch errors linke forgetting to push earlier, and without setting the site offline.

Catch ssh errors

If ssh fails, the commands fail, but it's not immediately obvious that it's a ssh problem. Usually it's the sanity check that fails, but it claims that the repo is not clean.

As long as sanity check is always the first action, it could be checked there. If it's not, the handling should be in Action::sh().

Extend

Hi - First, great command!

I didn't see any docs on extending. Is there any way to execute additional actions before/after deploying?

Sorry if I missed something.

Option to ignore dirty repo

Would be handy with a switch to force the deployment even if the deployed site isn't clean. But that would require ability to display the changes, and more interactivity. Something to think about.

Deployotron doesn't like drush 6 on the server.

For some reason, sql-dump manages to attempt to call sql-quey "SHOW TABLES;" through ssh, which is unlikely to work on most servers.

Doing an sql-dump on the server through an alias works though, so it's not sql-dump being generally broken.

Look at git status again.

git status -s doesn't change its returncode when there's changes. It's the lack of output that's the hint,

Behaviour on deploys

We are testing deployments with Deployotron since a couple of days and we are running into some strange behaviour.

  1. When we are deploting we are seeing only "run command:" without any information. is that good behaviour?
    snapshot
  2. After deploying we are detached from the branch and when doing a new deployment it fetches from the detached branch so that it won't find new commits.

How should this work?

Weird VERSION.txt

Something let to a weird VERSION.txt. Haven't investigated whether this is an old git or something else.

Deployment info
---------------
Tags: error: unknown option `points-at', usage: git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>],    or: git tag -d <tagname>...,    or: git tag -l [-n[<num>]] [<pattern>],    or: git tag -v <tagname>..., ,     -l                    list tag names,     -n[<n>]               print <n> lines of each tag message,     -d                    delete tags,     -v                    verify tags, , Tag creation options,     -a                    annotated tag, needs a message,     -m <msg>              message for the tag,     -F <FILE>             message in a file,     -s                    annotated and GPG-signed tag,     -u <key-id>           use another key to sign the tag,     -f, --force           replace the tag if exists, , Tag listing options,     --contains <commit>   print only tags that contain the commit,
SHA: 2a0383e0f6ef5d180097befd57c9dc1bf6f672b1
Time of deployment: Thu, 08 Dec 2016 15:07:54 +0100
Deployer: www-deploy@tst-kb-dru1

ignore-submodules requires recent version of git

We use the --ignore-submodules option when checking for changes on the remote during the sanity check ([ref](git diff-index --cached --quiet HEAD --ignore-submodules --)).

This is not supported on older versions of git (I tested on 1.5.4.3) and causes the deployment to fail as the error message is interpreted as changes.

We should either:

  1. Set a minimum version of git as required for using deployotron and check it during validation
  2. Remove the check and potentially find a different way of implementing this check
  3. Update deployotron to only use the option if using a version of git that supports it

Alias name in dump name

With multiple unrelated sites on the same server, you can't tell one dump from the other.

Alias is better than a sanitized path. If you're deploying to the same site under different aliases, you're asking for it.

Consider --no-remote-drush

Some actions require a working remote drush, which can be broken by subtle PHP compatibility bugs causing the remote Drush to error out with a parse error.

We could have actions that use remote drush to advertise the fact and a switch that would skip all of them for panic situations.

Consider adding log message to VERSION.txt/New Relic/Flowdock

While sha uniquely identifies the deployed version, and the branch gives some indication too, the log message usually tells a human more.

But there's an disclosure of information issue here. Would we like the log message being, essentially, public information.

For New Relic it's a no-brainer, there's no reason not to add the log message. We should just skip messages starting with "Merged", or else they become a tad useless.

Flowdock might as well get all the log entries since the last deployment. It supports the extra text, and it'll mirror the new Github integration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.