First, make sure that you are in the \`production\` branch. Open up the project directory, and make sure there are no local changes made and the latest version of the production branch is on your machine.
Before doing any of the following steps, make sure that all the production environment variables that are supposed to go to the server must be in the .env.production file. If you do not add all the production ENV values inside the \`.env.production\` file, the backend will crash
Here are the steps to get the production build released:
1. Set up AWS CLI
1. Install the AWS CLI on your local machine and run \`aws configure\`. You’ll need Access Key and Secret for an AWS user that has full access to ECRs. Enter those and values in the CLI
2. Get ECR Access
1. Run the following command in your terminal, and you should get an “Login Succeeded” message:
2. aws ecr get-login-password --region us-east-1 | docker login --username AWS -- password-stdin [182113959702.dkr.ecr.us-east-1.amazonaws.com](http://182113959702.dkr.ecr.us-east-1.amazonaws.com "")
3. Build a Docker image, tag it, and push
1. Go to the project directory, and then into /server, and run the following command to create a Docker image of the code: docker build --platform linux/amd64 -t factiii-server
2. Once the image build is completed, you have to tag it with respect to the ECR repository, run the following command: docker tag factiii-server:latest [182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii](http://182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii "")server:latest
3. And after it has been tagged, you can push the image to ECR registry by running the following command: docker push [182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii-server:latest](http://182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii-server:latest "")
4. After this stage, almost all the work to be done on the local machine is completed. For the next steps, you will need SSH access to the production EC2 instance that was mentioned earlier.
4. Access the server
1. SSH into the server using the key-pair or password, and run the following commands to deploy the production image
1. Remove the existing Docker image: “docker rm 182113959702.dkr.ecr.us-east[1.amazonaws.com/factiii-server:latest”](http://1.amazonaws.com/factiii-server:latest%E2%80%9D "")
2. Pull the latest copy of the image: “docker pull 182113959702.dkr.ecr.us-east[1.amazonaws.com/factiii-server:latest”](http://1.amazonaws.com/factiii-server:latest%E2%80%9D "")
3. Stop and delete the current container: “docker stop prod” and “docker rm prod”
4. Run the following command to start the production container once again: docker run -d \ --name prod -p 5001:3000 \ --network prod_network [https://182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii](https://182113959702.dkr.ecr.us-east-1.amazonaws.com/factiii "")server:latest
5. Extras
1. In case the Nginx config must be updated, just modify the \`/nginx/nginx.conf\` file, and run the following commands to restart Nginx: “docker stop nginx” and then “docker start nginx
2. After every deployment, make sure if the API is working manually. Also, see if the database connection has succeeded by checking the logs by running “docker logs prod”.