A simple REST API to store and query Movie information
You can view the hosted demo here: Live Demo
- An AWS Account
 - CircleCI Cloud (or any other CI/CD)
 - Terraform 
1.0.5(Recommended) - Node 
14.7 - Mongo 
5.0.2 - Docker Compose
 
The following sections describe steps to configure each component of the project in order
- Ensure you have mongoDB setup and running locally
 - Fork and 
git clonethe project to your local machine - Add an .env with value for 
MONGO_DB_URIandPORTin the root folder - Run 
npm run startto run the application 
- Fork and 
git clonethe project to your local machine - Add an .env with value for 
MONGO_DB_URIin the root folder - Run 
docker-build . -t <anyname>:<anytag> - Update app:image to your 
<anyname>:<anytag>in docker-compose.yaml and rundocker-compose up - App should now be running on 
http://localhost:80/ 
npm run devto run the app with nodemonnpm run testto run unit testsnpm run lintto run a code analysis
- Fork and 
git clonethe project to your local machine - Set the variables specified in terraform.tfvars in 
/terraform - IMPORTANT : Replace the 
bucketname in the modulesterraform backend "s3"andresource "aws_s3_bucket" "terraform_state"of main.tf with a unique value, otherwise the following steps will fail - Comment out the 
terraform backend "s3"module and run terraform init and terraform apply (The infrastructure needs to be deployed prior to setting up the backend) - Uncomment the 
terraform backend "s3"module and run terraform init -backend-config="access_key=your aws access key" -backend-config="secret_key=your aws secret key" - Run terraform apply
 
- Login to CircleCI cloud and select your forked project, select 
mainbranch forconfig.ymlin the popup - Set the variables specified in .env.example with your values to 
Project Settings > Environment Variablesof the CircleCI project - Setup branch protection rules in settings to your liking
 - After inital deployment, you can test the application via https://
{EC2-Public-IPv4-DNS-here}/movie/{some value} (Swagger will not run as SSL is not setup, check Manual Steps Required section) 
- Adding TLS/SSL needs to be manually configured, this can be achieved either by using an Elastic Load Balancer with a certificate from AWS Certificate Manager or by using a service such as LetsEncrypt or any other method of choice
 - Obtaining a domain (The demo domain was obtained from freenom) and configuration (via AWS Route53 or any preferred method)
 
- A build will be run for every Pull Request made to the 
mainbranch, and the follwing events will occur- Update packages with 
npm ciand save-cache, runeslintfor code analysis and run unit tests withmocha - If above steps pass, docker build will be run for additional validation
 - If all the checks are passed only, will the Pull Request merging be allowed
 
 - Update packages with 
 - A deployment will run for each Pull Request merged to master, consisting of the following steps
- Rebuild Dockerimage and push to Docker Hub with tag set to last git commit hash (this avoid issues when updating docker-compose on server in future steps)
 - Setup AWS CLI and open port 22 via Security Group for connecting to EC2 instance
 - Run 
scpand copy docker-compose.yml - Update running docker-compose instance via 
sshalong with updated image tag, the deployment completes - Close the port 22 previously opened to connect to the EC2 instance
 
 
- Should a step between Opening and Closing Port 22 for SSH & SCP fail , the EC2 instance will be left exposed to the IP used by CircleCI pipeline, 'when: always' was added to the close port step as a potential fix for this
 - Some of the package and file imports may look inconsistent in the source due to the use of in-built experimental ES6 features packaged in node by adding 
{"type":"module"}inpackage.jsonwithout setting up a transpiler such as babel