Elastic Beanstalk uses Docker to power its multi-container Docker platform type. This project is a boilerplate code for a multi-container Elastic Beanstalk application.
This document contains a small documentation on how to create an Elastic Beanstalk multi-container environment.
The first thing is to install the EB tools (this assume that Brew has been installed), and boot2docker:
brew install awsebcli
.brew install boot2docker
.- Verify that it works by typing the
eb
command in the terminal.
In order to being able to use the AWS tools, you will need to specify the IAM you need to use, as explained here.
A typical Elastic Beanstalk project will look like this:
.ebextensions/
server.config
.elasticbeanstalk/
php-app/
public/
index.php
src/
ComponentA/
...
ComponentB/
...
vendor/
proxy/
conf.d/
default.conf
.gitignore
.ebignore
Dockerrun.aws.json
The .ebextensions
folder is a special Elastic Beanstalk folder that allows to personnalize the underlying instances. Typically we will use this
to add server variables that can then be configured right into the Elastic Beanstalk environment.
The .elasticbeanstalk
folder is a special Elastic Beanstalk folder that is not commited and contains some local config info.
The php-app
folder will contain all the PHP code. It can be splitted into multiple modules.
The proxy
folder contains the Nginx configuration.
The .ebignore
is like a .gitignore
, but is used by Elastic Beanstalk instead. For instance, you may want to add the /vendor
folder into
the .gitignore
, but not into the .ebignore
, so that it's part of the deployed ZIP.
Finally, the Dockerrun.aws.json
file allows to configure the Docker configuration of the Elastic Beanstalk instance. In this skeleton,
it creates a multi-container that uses a PHP7 customized image (that comes with Opcache, Intl, PdoMysql, PdoPgsql), as well as Nginx for
webserver.
- Create the project on Elastic Beanstalk console.
- Create a new environment using the Elastic Beanstalk console for that project.
- Once in the project, type
eb init
. This command will require to select the newly created project. - Type
eb use environmentName
in the given branch. This will tie the current branch to this EB environment. You could therefore create one "production" environment that will be tied to the master branch using the commandeb use production
while on the master branch, and a "development" environment that will be tied to the develop branch using the commandeb use develop
while on the develop branch.
In order to develop locally:
- Type
eb local run
. This will launchboot2docker
and replicate the environment by creating all the images specified in theDockerrun.aws.json
file. - Open a new terminal tab and type
eb local open
. This will open the browser. - If the project needs to specify environment variables (typically, the database connection info), you can set them locally using the
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
- Once you're done, type
Cmd + C
in order to properly shut down all the resources.
In order to deploy:
- Type
eb deploy
. You can also deploy to a specific environment by doingeb deploy environmentName
.
If your product contains multiple environments that share the same code (for instance a worker and webserver environments), unfortunately 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 so that you can map one branch to multiple named environments.
- First, customize the
deploy.php
file to your needs. - Then, type the
deploy.php
command.