This is an implementation of the Todo-Backend API in C# on ASP.NET Core.
- Docker
- Docker Compose for local deployment
- NGINX for load balancing the api
- Consul for service discovery and configuration management
- ELK Stack for log visualisation
- Install the latest version of .NET Core and Docker for your platform
- From the project root dir, use compose to build the app, download all infrastructure containers and run the entire stack:
> docker-compose up -d
- If everything works, start scaling the API:
> docker-compose scale api=5
-
Local Docker (full stack on one VM)
- API: http://localhost:8080
- Consul UI: http://localhost:8500/ui
- Run ToDo Backend tests http://todobackend.com/specs/index.html?http://localhost:8080
-
Azure (full stack on one VM)
-
Heroku (only one API instance)
(using Terminal in OSX, starting directory is project root)
- Build and run just the API, printing all stdout from the container:
$ cd src/TodoBackend.Api/
$ docker build -t todo-backend-aspnetcore:latest .
$ docker run -p 80:5000 todo-backend-aspnetcore
- OR run the entire stack in the backgroud and scale the API to 5 containers:
$ docker-machine up -d
$ docker-machine scale api=5
See https://docs.docker.com/machine/drivers/azure
- Create resource group with virtual machine
$ docker-machine create -d azure \
--azure-ssh-user ops \
--azure-subscription-id <subscription id> \
--azure-location westeurope \
--azure-open-port 80 \
--azure-open-port 8500 \
--azure-open-port 5601 \
machine
- Use
docker-machine
to ssh into the VM in Azure, if required
$ docker-machine ssh machine
- Use
docker-machine
to get the VM's public IP address, if required
$ docker-machine ip machine
- We're using version 5 of the ELK stack, which requires at least 2GB of memory. So let's ssh into the VM and once connected, increase the limit (see Elastic Search documentation for details)
ops@machine:~$ sysctl -w vm.max_map_count=262144
- Set the newly created machine as default. This makes all
docker
commands go to the machine in Azure
$ docker-machine env machine
$ eval $(docker-machine env machine)
- Use the regular
docker
ordocker-compose
CLI to start the entire stack or an individual container. Note that this is NOT how one would start and scale an infrastructure stack in a real production scenario.
$ docker-compose up -d
- Install Azure CLI, login, an set mode to Azure Resource Manager (ARM)
$ npm install -g azure-cli
$ azure login
$ azure config mode arm
- If you have multiple subscriptions, use the CLI to show your subscriptions and select a default
$ azure account list
$ azure account set <subscription id>
- Display details of the VM
$ azure vm show -g docker-machine -n machine
- Show public IP and DNS configuration; add a DNS name to the public IP. The VM is now available as http://todo-backend-aspnetcore.westeurope.cloudapp.azure.com
$ azure network public-ip list -g docker-machine
$ azure network public-ip show -g docker-machine -n machine-ip
$ azure network public-ip create -g docker-machine -n machine-ip -l westeurope -d "todo-backend-aspnetcore" -a "Dynamic"
- Create a Heroku account and create an app (in this example, the app is called
todo-backend-aspnetcore
- Install the Heroku toolbelt: https://devcenter.heroku.com/articles/heroku-command-line
$ cd src/TodoBackend.Api/
$ docker build -t todo-backend-aspnetcore:latest -f Dockerfile.heroku -e ASPNETCORE_ENVIRONMENT=heroku .
$ docker tag todo-backend-aspnetcore registry.heroku.com/todo-backend-aspnetcore/web
$ docker push registry.heroku.com/todo-backend-aspnetcore/web
$ heroku open --app todo-backend-aspnetcore
Alternatively, if the directory contains a Heroku-compatible dockerfile (no EXPOSE
and listening on $PORT
)
$ heroku plugins:install heroku-container-registry
$ heroku heroku container:login
$ heroku container:push web --app todo-backend-aspnetcore
$ heroku open --app todo-backend-aspnetcore