C#
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vscode
nginx
src
.gitattributes
.gitignore
Dockerfile
NuGet.config
README.md
TodoBackend.sln
appSettings.azure.json
appSettings.docker.json
appSettings.heroku.json
appSettings.json
docker-compose.yml

README.md

todo-backend-aspnetcore

This is an implementation of the Todo-Backend API in C# on ASP.NET Core.

Infrastructure

Getting started

  • 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

URIs

Deployment using Docker

(using Terminal in OSX, starting directory is project root)

Local

  • 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

Azure

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 or docker-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

Optional: Azure CLI

  • 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
$ 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"

Heroku

$ 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