API for the Who Drinks mobile application.
- .NET 5
- MongoDB
- Docker
Download MongoDb. The default installation includes a downloaded service that should run a default standalone server automatically.
If code is changed so that some API calls use Transactions, standalone server configuration will not be sufficient. This is because transactions are not supported with standalone mongo servers. It is advised to use the command line to start up a mongod process manually. The instructions below will be using the same default port 27017 so if there is a Windows Service running, it will need to be shutdown first:
- Stop your MongoDB Windows Service if it is running on port 27017 (the default on standard installations).
- In terminal type the following command:
mongod --port 27017 --dbpath C:\mongo-data --replSet rs0 --bind_ip localhost
. You may change the path (i.e. C:\mongo-data) and name of replica set (i.e. rs0) to your liking. If you have gone through below steps before you can stop here, otherwise first time setups will need to continue with below steps. - Open up another temrinal and connect to mongo shell:
mongo
. You may need to add mongo to your systems PATH variable if you haven't already. rs.initate()
;
Use this method to be able to add break points for debugging.
- Open Solution with Visual Studio.
- Target Docker and click Play button.
- A new browser should open up to swagger page with path /swagger/index.html.
- For API requests, target http://localhost:5000 or https://localhost:5001
- You may need to go to the reverseproxy/nginx.conf file and ensure the upstream app_servers block targets whodrinksapi:5000
upstream app_servers {
server whodrinksapi:5000;
}
- Navigate to root directory in command line and run
docker-compose build
docker-compose up
. No browser will open, but the app should be running on http://localhost:80
- AWS CLI
- AWS access and permissions
- Docker
- Mongo Atlas access and permissions
The following steps have already been completed and can be skipped. This has been placed here for reference.
- Setup login configuration on aws for an account able to write to ecr
- Follow steps 1-5 below in 'New Release'.
- Create repositories for each image to be pushed up and follow steps 6 - 8 in 'New Release'.
- Crate security groups
- Create Task Definition which uses the created docker images (latest version)
- Create ECS cluster.
- Having new ECS Experience switch enabled, it is now possible to create load balancer and target groups on ECS servcie creation as well. For the container to load, select the nginx container.
- Login to the DB Cluster/s and ensure ALB is allowed access using the DNS name (A Record).
- Update reverseproxy/nginx.conf file's upstream target to be 127.0.0.1:5000
upstream app_servers {
server 127.0.0.1:5000;
}
- In appsettings.json (in root of the API project directory), update the db connection string and basic security settings.
- Get password and login:
aws ecr get-login-password | docker login --username AWS --password-stdin <yourawsaccountnumber>.dkr.ecr.ap-southeast-2.amazonaws.com
- Build the updated image:
docker-compose build
- Check the docker image names:
docker image ls
- Tag docker image
docker tag <dockerimagename> <yourawsaccountnumber>.dkr.ecr.ap-southeast-2.amazonaws.com/<docker_repository_name>
- Push up to ecr:
docker push <yourawsaccountnumber>.dkr.ecr.ap-southeast-2.amazonaws.com/<docker_repository_name>
- Repeat steps 2 to 4 for any other images that have changed
- On AWS, go to Task Definition currently being used and either create new revision or update service and tick checkbox for 'Force new deployment'
- Get password and login:
aws ecr get-login-password | docker login --username AWS --password-stdin 209196940283.dkr.ecr.ap-southeast-2.amazonaws.com
- Create repository if needed:
aws ecr create-repository --repository-name whodrinksapi --region ap-southeast-2
- Tag docker image
docker tag whodrinksapi_whodrinksapi 209196940283.dkr.ecr.ap-southeast-2.amazonaws.com/whodrinksapi
- Push up to ecr:
docker push 209196940283.dkr.ecr.ap-southeast-2.amazonaws.com/whodrinksapi
- Create repository for nginx:
aws ecr create-repository --repository-name whodrinksapi-reverseproxy --region ap-southeast-2
- Tag docker image for nginx:
docker tag whodrinksapi_reverseproxy 209196940283.dkr.ecr.ap-southeast-2.amazonaws.com/whodrinksapi-reverseproxy
- Push up nginx tag to ecr:
docker push 209196940283.dkr.ecr.ap-southeast-2.amazonaws.com/whodrinksapi-reverseproxy
Jeffrey Huang - jeffrey.huang@recaura.com