Basic react app in Production-Grade workflow with CICD and automatic deployment onto AWS Elastic Beanstalk. We are going to Docker to facilitate development, test and production deployment.
Developers can run docker-compose -f docker-compose-dev.yml up --build
to bring up 2 docker containers simultaneasly, one for development and one for testing.
Because we are making use of Volumes, developers can edit in real-time the source code, and both the containers will automatically reflect the changes.
For production deployment, we are using a multi-step build process:
- Built the NodeJS application in the first container
- Create a new Nginx container and move the build folder across to leave behing all the binaries that aren't suitable for a production environment
In this repository you can find the pipeline configurations for both GitHub Actions and TravisCI (use one at time).
Every time you merge code into main
your code will be tested and, if successful, deployed onto AWS Elastic Beanstalk.
Create a production docker-compose.yml file in the root of the project and paste the following:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- '80:80'
- Go to AWS Management Console
- Search for IAM and click the IAM Service.
- Click Roles under Access Management in the left sidebar.
- Click the Create role button.
- Select AWS Service under Trusted entity type. Then select EC2 under common use cases.
- Search for AWSElasticBeanstalk and select the AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier and AWSElasticBeanstalkMulticontainerDocker policies. Click the Next button.
- Give the role the name of aws-elasticbeanstalk-ec2-role
- Click the Create role button.
- Go to AWS Management Console
- Search for Elastic Beanstalk and click the Elastic Beanstalk service.
- If you've never used Elastic Beanstalk before you will see a splash page. Click the Create Application button. If you have created Elastic Beanstalk environments and applications before, you will be taken directly to the Elastic Beanstalk dashboard. In this case, click the Create environment button. There is now a flow of 6 steps that you will be taken through.
- You will need to provide an Application name, which will auto-populate an Environment Name.
- Scroll down to find the Platform section. You will need to select the Platform of Docker. This will auto-select several default options. Change the Platform branch to Docker running on 64bit Amazon Linux 2. The new 2023 branch currently has issues with single-container deployments.
- Scroll down to the Presets section and make sure that free tier eligible has been selected:
- Click the Next button to move to Step #2.
- You will be taken to a Service Access configuration form. Select Create and use new service role and name it aws-elasticbeanstalk-service-role. You will then need to set the EC2 instance profile to the aws-elasticbeanstalk-ec2-role created earlier.
- Click the Skip to Review button as Steps 3-6 are not applicable.
- Click the Submit button and wait for your new Elastic Beanstalk application and environment to be created and launch.
- Click the link below the checkmark under Domain. This should open the application in your browser and display a Congratulations message.
- Go to AWS Management Console
- Search for S3 and click the S3 service.
- Find and click the elasticbeanstalk bucket that was automatically created with your environment.
- Click Permissions menu tab
- Find Object Ownership and click Edit
- Change from ACLs disabled to ACLs enabled. Change Bucket owner Preferred to Object Writer. Check the box acknowledging the warning.
- Click Save changes.
- Search for the "IAM Security, Identity & Compliance Service"
- Click "Create Individual IAM Users" and click "Manage Users"
- Click "Add User"
- Enter any name you’d like in the "User Name" field.
- Click "Next"
- Click "Attach Policies Directly"
- Search for "beanstalk"
- Tick the box next to "AdministratorAccess-AWSElasticBeanstalk"
- Click "Next"
- Click "Create user"
- Select the IAM user that was just created from the list of users
- Click "Security Credentials"
- Scroll down to find "Access Keys"
- Click "Create access key"
- Select "Command Line Interface (CLI)"
- Scroll down and tick the "I understand..." check box and click "Next"