A simple script to deploy PHP applications to AWS ElasticBeanstalk

v1.4.1 2018-01-19 19:24 UTC

This package is auto-updated.

Last update: 2024-12-11 03:23:59 UTC


README

A simple script to deploy PHP applications in a few minutes to ElasticBeanstalk.

Installation

Composer

composer global require "leroy-merlin-br/dployer=*@dev"

Global config for dployer

AWS config

You have 2 options to configure AWS:

  • Environment Variables
  • JSON configuration file

Environment Variables

You must fill the following environment variables.

  • DPLOYER_PROFILE : Your profile's name in AWS.
  • DPLOYER_REGION : Your region you want to deploy something.
  • DPLOYER_AWS_KEY : Your secret AWS key.
  • DPLOYER_AWS_SECRET : Your secret AWS SECRET.

JSON Configuration File

  • Create the following configuration file: ~/.aws/config.json
{
    "includes": ["_aws"],
    "services": {
        "default_settings": {
            "params": {
                "profile": "my_profile",
                "region": "sa-east-1",
                "key": "YOURSUPERKEY",
                "secret": "YoUrSuPeRsEcReT"
            }
        }
    }
}

AWS Bucket

Add the following line in the end of the ~/.bashrc file:

export DPLOYER_BUCKET=your-bucket-identifier-0-12345678

Usage

Inside the folder that you want to deploy, just run:

dployer deploy ApplicationName elasticbeanstalked-environment

Options

You can use the following options:

  • -c (--config): Use a custom configuration file different from .dployer
  • -i (--interactive): Asks before run each command in configuration file
  • -v (--verbose): Display command outputs
  • -f (--force): Continue with deploy process even if a script exits with error

Project configuration

In order to optimize the deploy of your project, you can create a configuration file to keep application and environment variables. In addition, you gain some extra features, like: events to run the scripts that you want and options to copy extra files and delete some files before zip them.

Just create a .dployer file in project root dir.

Note: Once you have .dployer file with application and environment variables defined, you can just run the command as following:

dployer deploy

Sample .dployer

{
    "application": "ApplicationName",
    "environment": "my-environment",
    "scripts": {
        "init": "composer dumpautoload",
        "before-pack": [
            "gulp build --production"
        ],
        "before-deploy": [
            "echo 'Deploying new version'",
            "echo 'Another important command to run before deploy'"
        ],
        "finish": [
            "gulp clean",
            "echo 'Nicely done'"
        ]
    },
    "copy-paths": [
        "vendor",
        "public/assets"
    ],
    "exclude-paths": [
        ".git",
        "vendor/**/*.git"
    ]
}

Events

Dployer triggers 4 events in deploy flow:

  • init: Runs after initial validations and before any command of deploy
  • before-pack: Runs before create the zip file
  • before-deploy: Runs before create ElasticBeanstalk version and upload zip
  • finish: Runs after upload new version

copy-paths

The dployer just clone your current git branch inside a temp folder, then it creates a zip file. But sometimes, you want to deploy some files which are ignored by git (inside .gitignore file).

In this case, you can put these files/folders in copy-paths key in configuration file as demonstrated in sample section.

.dployer

(...)
"copy-paths": [
    "vendor",
    "public/assets/"
]
(...)

exclude-paths

In another case, sometimes you want to exclude some files/folders too.

.dployer

(...)
"exclude-paths": [
    ".git",
    "vendor/**/*.git"
]
(...)