1

We are doing CI/CD for drupal site using Jenkins. Now, we need to run drush commands which we should run only in single instance.

For this, we have created elastic beanstalk config script with parameter leader_only as true but it still runs drush commands in all instances at time of deployment instead of one instance.

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/drushcmd.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
       . /opt/elasticbeanstalk/support/envvars
        cd /usr/local/bin
        sudo cp /usr/bin/composer.phar /usr/local/bin/composer
        sudo ln -s /usr/local/bin/composer /usr/bin/composer
        composer --version
        git clone https://github.com/drush-ops/drush.git /usr/local/src/drush
        cd /usr/local/src/drush
        git checkout 7.0.0-alpha5
        sudo ln -s /usr/local/src/drush/drush /usr/bin/drush        
        composer install
        export DRUSH_PHP=/usr/bin/php7
        drush --version

container_commands:
  001customize:
    command: "/opt/elasticbeanstalk/hooks/appdeploy/post/drushcmd.sh"
    leader_only: true
    ignoreErrors: true

1 Answers1

0

It's difficult to say directly what is going on but what I believe is happening is after 2-3 deployments, multiple instances in your ELB environment contain the file because the same instance is not being elected as the leader during the deployment process.

You need to delete the drushcmd.sh file on all instances before creating it - you're creating the file on multiple instances.

By deleting (whether it exists or not) the file on all instances, you'll ensure the file only exists on one instance - the leader.

container_commands:
  001_delete_deployment_hook:
    command: "rm -f /opt/elasticbeanstalk/hooks/appdeploy/post/drushcmd.sh"
    ignoreErrors: true
  002_create_deployment_hook:
    command: "/opt/elasticbeanstalk/hooks/appdeploy/post/drushcmd.sh"
    leader_only: true
    ignoreErrors: true

Notice how 001_delete_deployment_hook is missing leader_only to ensure we remove on all instances

gavxn
  • 1