Skip to content

Deployment

Robert Gibboni edited this page Apr 3, 2019 · 2 revisions

This project is deployed to AWS Elastic Beanstalk. Travis has been configured to deploy the project with every successful build of the master branch. Deployment consists of (1) pushing the Docker image to Docker Hub and (2) deploying a new application to Elastic Beanstalk.

Manual

In the event that you need to manually deploy, you can do so as follows.

1. Ensure you have the Elastic Beanstalk Command Line Interface (EB CLI) installed:

pip install awsebcli

2. Make sure you have the access keys for an AWS user with the AWSElasticBeanstalkService policy. You can learn more about access keys and permissions at the following links:

  1. Deploy:

    AWS_ACCESS_KEY_ID=<key> AWS_SECRET_ACCESS_KEY=<secret> eb deploy woeip-production
    

Terraform

Rather than click around in the AWS UI, you should use Terraform to create and modify the infrastructure:

  • Elastic Beanstalk application
  • RDS database
  • Security groups
  • DNS (Route 53) configuration
  • SSL/TLS certificate

Your Terraform user will need the following policies. Additional permissions/policies will be needed, if you choose to use other AWS functionality. In general, it is a good practice to give your users as few permissions as needed.

  • AmazonRoute53FullAccess
  • AWSCertificateManagerFullAccess
  • AWSElasticBeanstalkFullAccess
  • AWSElasticBeanstalkService
  • ElasticLoadBalancingFullAccess

Backend Setup

Terraform uses an S3 backend to keep track of its state, and a DynamoDB table for locking, to prevent multiple users from trying to modify infrastructure at the same time. The S3 bucket and DynamoDB are themselves created via Terraform!

1. Follow the steps at https://www.terraform.io/downloads.html to download Terraform. macOS/Homebrew users can simply run brew install terraform.

  1. Ensure terraform/backend_setup/main.tf has been properly configured.

  2. Go to terraform/backend_setup:

    cd terraform/backend_setup
    
  1. Generate an execution plan:

    terraform plan
    
  2. Apply the changes:

    terraform apply
    
  3. Commit terraform/backend_setup/terraform.tfstate to the repository.

This procedure only needs to be done once.

Applying Changes

Once the backend is setup, you can apply the Terraform that creates the infrastructure on which your project will run.

1. Ensure terraform/terraform.tfvars has been properly configured. See terraform/terraform.example.tfvars for an example of what should be in this file.

  1. DO NOT commit terraform/terraform.tfvars to Git!

  2. Go to terraform:

    cd terraform
    
  1. Generate an execution plan:

    terraform plan
    
  2. Apply the changes:

    terraform apply
    

Note that this process will take at least 10 minutes for the initial database setup. The SSL/TLS certificate setup may also take up to 20 minutes.

The resulting state information will be saved to S3.