Skip to content

Skeleton for an Elastic Beanstalk application running with a multi-container Docker environment

Notifications You must be signed in to change notification settings

maestrooo/eb-multi-container-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elastic Beanstalk

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.

Installing AWS EB tools

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.

Specifying the AWS IAM user

In order to being able to use the AWS tools, you will need to specify the IAM you need to use, as explained here.

Preparing the EB project

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.

Creating the EB project

General

  • 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 command eb use production while on the master branch, and a "development" environment that will be tied to the develop branch using the command eb use develop while on the develop branch.

Local

In order to develop locally:

  • Type eb local run. This will launch boot2docker and replicate the environment by creating all the images specified in the Dockerrun.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.

Deploy

In order to deploy:

  • Type eb deploy. You can also deploy to a specific environment by doing eb 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.

About

Skeleton for an Elastic Beanstalk application running with a multi-container Docker environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages