Laravel Elastic Beanstalk Deploy Extension

Home   »   Laravel Elastic Beanstalk Deploy Extension

# The following script will deploy a Laravel 5 applicaion on AWS Elastic Beanstalk.
# Add to .ebextensions at the root of your application and name your commands file (e.g., commands.config)

# -------------------------------- Commands ------------------------------------
# Use "commands" key to execute commands on the EC2 instance. The commands are
# processed in alphabetical order by name, and they run before the application
# and web server are set up and the application version file is extracted.
# ------------------------------------------------------------------------------
commands:
  01updateComposer:
    command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /root

  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: document_root
    value: /public

  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: memory_limit
    value: 512M

# ---------------------------- Container Commands ------------------------------
# You can use the container_commands key to execute commands for your container.
# The commands in container_commands are processed in alphabetical order by
# name. They run after the application and web server have been set up and the
# application version file has been extracted, but before the application
# version is deployed. They also have access to environment variables such as
# your AWS security credentials. Additionally, you can use leader_only. One
# instance is chosen to be the leader in an Auto Scaling group. If the
# leader_only value is set to true, the command runs only on the instance
# that is marked as the leader.
#
# Artisan commands include environment flag for production. If you are not
# deploying to a production environment, update the flag.
# ------------------------------------------------------------------------------
commands:
  01_node_install:
    # run this command from /tmp directory
    cwd: /tmp
    # don't run the command if node is already installed (file /usr/bin/node exists)
    test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
    # install node
    command: 'curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash - && sudo yum install -y nodejs && sudo npm install [email protected] -g'

container_commands:
  01express:
    command: "echo AWS Container Commands started, starting Composer install."

  02installComposer:
    command: "php /opt/elasticbeanstalk/support/composer.phar install"
    cwd: "/var/app/ondeck"

  03express:
    command: "echo Composer install completed, starting Laravel migration"

  04migrations:
    command: "php artisan migrate --force --no-interaction"
    cwd: "/var/app/ondeck"

  05express:
    command: "echo Completed Laravel migration, starting permission update"

  06permission:
    command: "sudo chmod -R 777 /var/app/ondeck/storage/logs"
    cwd: "/var/app/ondeck"

  07express:
    command: "echo Completed permissions, running npm build."

  08npm_build:
    command: "sudo rm -rf node_modules && sudo npm install"
    cwd: "/var/app/ondeck"

  09npm_run_production:
    command: "sudo npm run prod && echo container commands completed"
    cwd: "/var/app/ondeck"

Leave a Reply

Your email address will not be published. Required fields are marked *