Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit .elasticbeanstalk/config.yml in Elastic Beanstalk

Is it a good approach to commit the .elasticbeanstalk/config.yml inside the git repo of a project which uses eb deploy?

We want to deploy using our CI and so we can not use the interactive eb init. What we are thinking now is to define our dev, uat and prod inside that config.yml (if possible) and to point to that environment using eb deploy.

We saw that we could perform eb init with all necessary parameters in ebcli version2 but not in version 3 anymore? So it seems the approach is changed?

Can someone explain how to deploy EB for multiple environments, without interaction?

like image 584
DenCowboy Avatar asked Feb 09 '18 10:02

DenCowboy


2 Answers

  1. We want to deploy using our CI and so we can not use the interactive eb init

You can suppress the interactive mode as follows:

eb init --platform <platform-name> --region <region-name> <application-name>

  1. Is it a good approach to commit the .elasticbeanstalk/config.yml inside the git repo of a project which uses eb deploy?
  2. Can someone explain how to deploy EB for multiple environments, without interaction?

By design, the EBCLI avoids committing the .elasticbeanstalk/ directory since it can contain developer-specific information, which when committed to VC can cause confusion. So, it's best avoided from VC. You are free to commit it to version control. Ensure there's no sensitive information here. Logs, and saved configurations are usually stored in .elasticbeanstalk/.

  1. You can copy pertinent portions of the .elasticbeanstalk/config.yml file into root-level file from which CI could read information such as the environment name to use.
  2. Locally, you could create a pre-commit Git hook that would read the default environment name from the .elasticbeanstalk/config.yml file into the root-level file -- let's call it .environment_config.sh. It could be a statement as simple as export BEANSTALK_ENVIRONMENT_NAME=<environment name from .elasticbeanstalk/config.yml>
  3. On the CI server:

    3.1. Ensure PWD is git init-ed. Systems such as Jenkins usually are git init-ed with the necessary branch, so CI can simply source .environment_config.sh at this point and load the name of the environment to deploy.

    3.2. eb init --platform <platform-name> --region <region-name> <application-name>

    3.3. eb use $BEANSTALK_ENVIRONMENT_NAME

    3.4. eb deploy

(You could combine 3.3. and 3.4. by performing eb deploy $BEANSTALK_ENVIRONMENT_NAME instead; I just wanted to demonstrate the use of eb use)

like image 83
progfan Avatar answered Nov 12 '22 21:11

progfan


The EB CLI is really meant to be used from a workstation. I think you'd be better off scripting your CI with the AWS CLI.

A deployment with eb deploy will archive your code in S3 (or CodeCommit), create a new application version then update the environment with the new version label. All of those operations are supported with AWS CLI commands.

Or, you could write your own deployment script in Python with boto3. That's an easy option too. That's basically what the EB CLI is.

like image 23
Tim Christensen Avatar answered Nov 12 '22 23:11

Tim Christensen