├── php-app ├── composer.json ├── public │ └── index.php └── composer.lock ├── .ebignore ├── .gitignore ├── .ebextensions └── server.config ├── proxy └── conf.d │ └── default.conf ├── deploy.php ├── Dockerrun.aws.json └── README.md /php-app/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "zendframework/zend-servicemanager": "2.5.*" 4 | } 5 | } -------------------------------------------------------------------------------- /php-app/public/index.php: -------------------------------------------------------------------------------- 1 | [ 14 | 'webserver-production', // The production webserver environment 15 | 'worker-production', // The production worker environment 16 | ], 17 | 18 | 'develop' => [ 19 | 'webserver-development', // The development webserver environment 20 | 'worker-development', // The development worker environment 21 | ] 22 | ]; 23 | 24 | $gitHash = exec('git log -1 --format="%H"'); 25 | $branch = exec('git rev-parse --abbrev-ref HEAD'); 26 | 27 | if (!isset($environments[$branch])) { 28 | echo 'No environments are bound to the branch ' . $branch . PHP_EOL; 29 | die(); 30 | } 31 | 32 | foreach ($environments[$branch] as $environment) { 33 | echo "\nStarting deployment for environment $environment...\n"; 34 | passthru("eb deploy $environment"); 35 | echo "\nDeployment for environment $environment has completed\n"; 36 | } -------------------------------------------------------------------------------- /Dockerrun.aws.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSEBDockerrunVersion": 2, 3 | "volumes": [ 4 | { 5 | "name": "php-app", 6 | "host": { 7 | "sourcePath": "/var/app/current/php-app" 8 | } 9 | }, 10 | { 11 | "name": "nginx-proxy-conf", 12 | "host": { 13 | "sourcePath": "/var/app/current/proxy/conf.d" 14 | } 15 | } 16 | ], 17 | "containerDefinitions": [ 18 | { 19 | "name": "php-app", 20 | "image": "maestrooo/eb-docker-php7:latest", 21 | "essential": true, 22 | "memory": 128, 23 | "mountPoints": [ 24 | { 25 | "sourceVolume": "php-app", 26 | "containerPath": "/var/www/html", 27 | "readOnly": true 28 | } 29 | ] 30 | }, 31 | { 32 | "name": "nginx-proxy", 33 | "image": "nginx", 34 | "essential": true, 35 | "memory": 128, 36 | "portMappings": [ 37 | { 38 | "hostPort": 80, 39 | "containerPort": 80 40 | } 41 | ], 42 | "links": [ 43 | "php-app" 44 | ], 45 | "mountPoints": [ 46 | { 47 | "sourceVolume": "php-app", 48 | "containerPath": "/var/www/html", 49 | "readOnly": true 50 | }, 51 | { 52 | "sourceVolume": "nginx-proxy-conf", 53 | "containerPath": "/etc/nginx/conf.d", 54 | "readOnly": true 55 | }, 56 | { 57 | "sourceVolume": "awseb-logs-nginx-proxy", 58 | "containerPath": "/var/log/nginx" 59 | } 60 | ] 61 | } 62 | ] 63 | } -------------------------------------------------------------------------------- /php-app/composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "651b29f7ef41fef6bdcb4728b418faa1", 8 | "packages": [ 9 | { 10 | "name": "zendframework/zend-servicemanager", 11 | "version": "2.5.1", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/zendframework/zend-servicemanager.git", 15 | "reference": "3b22c403e351d92526c642cba0bd810bc22e1c56" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/zendframework/zend-servicemanager/zipball/3b22c403e351d92526c642cba0bd810bc22e1c56", 20 | "reference": "3b22c403e351d92526c642cba0bd810bc22e1c56", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.3.23" 25 | }, 26 | "require-dev": { 27 | "fabpot/php-cs-fixer": "1.7.*", 28 | "phpunit/phpunit": "~4.0", 29 | "zendframework/zend-di": "~2.5", 30 | "zendframework/zend-mvc": "~2.5" 31 | }, 32 | "suggest": { 33 | "ocramius/proxy-manager": "ProxyManager 0.5.* to handle lazy initialization of services", 34 | "zendframework/zend-di": "Zend\\Di component" 35 | }, 36 | "type": "library", 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "2.5-dev", 40 | "dev-develop": "2.6-dev" 41 | } 42 | }, 43 | "autoload": { 44 | "psr-4": { 45 | "Zend\\ServiceManager\\": "src/" 46 | } 47 | }, 48 | "notification-url": "https://packagist.org/downloads/", 49 | "license": [ 50 | "BSD-3-Clause" 51 | ], 52 | "homepage": "https://github.com/zendframework/zend-servicemanager", 53 | "keywords": [ 54 | "servicemanager", 55 | "zf2" 56 | ], 57 | "time": "2015-06-03 15:32:02" 58 | } 59 | ], 60 | "packages-dev": [], 61 | "aliases": [], 62 | "minimum-stability": "stable", 63 | "stability-flags": [], 64 | "prefer-stable": false, 65 | "prefer-lowest": false, 66 | "platform": [], 67 | "platform-dev": [] 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Elastic Beanstalk 2 | 3 | Elastic Beanstalk uses Docker to power its multi-container Docker platform type. This project is a boilerplate code for a multi-container Elastic 4 | Beanstalk application. 5 | 6 | This document contains a small documentation on how to create an Elastic Beanstalk multi-container environment. 7 | 8 | ## Installing AWS EB tools 9 | 10 | The first thing is to install the EB tools (this assume that Brew has been installed), and boot2docker: 11 | 12 | * `brew install awsebcli`. 13 | * `brew install boot2docker`. 14 | * Verify that it works by typing the `eb` command in the terminal. 15 | 16 | ## Specifying the AWS IAM user 17 | 18 | In order to being able to use the AWS tools, you will need to specify the IAM you need to use, as 19 | [explained here](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-credentials). 20 | 21 | ## Preparing the EB project 22 | 23 | A typical Elastic Beanstalk project will look like this: 24 | 25 | .ebextensions/ 26 | server.config 27 | .elasticbeanstalk/ 28 | php-app/ 29 | public/ 30 | index.php 31 | src/ 32 | ComponentA/ 33 | ... 34 | ComponentB/ 35 | ... 36 | vendor/ 37 | proxy/ 38 | conf.d/ 39 | default.conf 40 | .gitignore 41 | .ebignore 42 | Dockerrun.aws.json 43 | 44 | The `.ebextensions` folder is a special Elastic Beanstalk folder that allows to personnalize the underlying instances. Typically we will use this 45 | to add server variables that can then be configured right into the Elastic Beanstalk environment. 46 | 47 | The `.elasticbeanstalk` folder is a special Elastic Beanstalk folder that is not commited and contains some local config info. 48 | 49 | The `php-app` folder will contain all the PHP code. It can be splitted into multiple modules. 50 | 51 | The `proxy` folder contains the Nginx configuration. 52 | 53 | The `.ebignore` is like a `.gitignore`, but is used by Elastic Beanstalk instead. For instance, you may want to add the `/vendor` folder into 54 | the `.gitignore`, but not into the `.ebignore`, so that it's part of the deployed ZIP. 55 | 56 | Finally, the `Dockerrun.aws.json` file allows to configure the Docker configuration of the Elastic Beanstalk instance. In this skeleton, 57 | it creates a multi-container that uses a PHP7 customized image (that comes with Opcache, Intl, PdoMysql, PdoPgsql), as well as Nginx for 58 | webserver. 59 | 60 | ## Creating the EB project 61 | 62 | ### General 63 | 64 | * Create the project on Elastic Beanstalk console. 65 | * Create a new environment using the Elastic Beanstalk console for that project. 66 | * Once in the project, type `eb init`. This command will require to select the newly created project. 67 | * Type `eb use environmentName` in the given branch. This will tie the current branch to this EB environment. You could therefore create one 68 | "production" environment that will be tied to the master branch using the command `eb use production` while on the master branch, and a 69 | "development" environment that will be tied to the develop branch using the command `eb use develop` while on the develop branch. 70 | 71 | ### Local 72 | 73 | In order to develop locally: 74 | 75 | * Type `eb local run`. This will launch `boot2docker` and replicate the environment by creating all the images specified in the 76 | `Dockerrun.aws.json` file. 77 | * Open a new terminal tab and type `eb local open`. This will open the browser. 78 | * If the project needs to specify environment variables (typically, the database connection info), you can set them locally using the 79 | `setenv` command. For instance: `eb local setenv RDS_HOSTNAME=url RDS_PORT=3306 RDS_USERNAME=my_username RDS_PASSWORD=my_password RDS_DB_NAME=test` 80 | * Once you're done, type `Cmd + C` in order to properly shut down all the resources. 81 | 82 | ### Deploy 83 | 84 | In order to deploy: 85 | 86 | * Type `eb deploy`. You can also deploy to a specific environment by doing `eb deploy environmentName`. 87 | 88 | If your product contains multiple environments that share the same code (for instance a worker and webserver environments), unfortunately 89 | EB CLI does not allow to deploy the exact same code to multiple environments. To that extent, this skeleton comes with a small utility called 90 | so that you can map one branch to multiple named environments. 91 | 92 | * First, customize the `deploy.php` file to your needs. 93 | * Then, type the `deploy.php` command. --------------------------------------------------------------------------------