.net Core version - acolono/opentrigger-CounterService GitHub Wiki

Demo: https://counter.0xff.887.at/

# get $10 with this promo-code: https://m.do.co/c/ee9404e91d5e
# which can power your vm for 2 months 

# install ubuntu 16.04 + Docker (available as one-click app)
# should work with any docker supported 64bit os - but you have to install docker -> https://get.docker.com/

# log on and make sure you'r up to date
apt-get update && apt-get -y dist-upgrade

# setup a hostname, in my case its 'counter.77tac.com'
# for free, thanks to http://freedns.afraid.org/

# start nginx-proxy + letsencrypt
docker run -d -p 80:80 -p 443:443 \
  --name nginx-proxy \
  -v /etc/nginx/htpasswd \
  -v /etc/nginx/certs \
  -v /etc/nginx/vhost.d \
  -v /usr/share/nginx/html \
  -v /var/run/docker.sock:/tmp/docker.sock:ro \
  --restart always jwilder/nginx-proxy

docker run -d --name nginx-letsencrypt \
  --volumes-from nginx-proxy \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  --restart always \
  jrcs/letsencrypt-nginx-proxy-companion
	
# Download the latest build from here : https://ci.appveyor.com/project/piccaso/opentrigger-counterservice
# make sure you have the right branch and unzip it
# in that case you can skip to 'build app container'

# or build it inside a container
git clone --single-branch -b dotNetCore https://github.com/acolono/opentrigger-CounterService.git
cd opentrigger-CounterService/

docker run -it --rm -v `pwd`:/src microsoft/dotnet \
  bash -c 'cd /src/src/dncCnt/ && dotnet restore && dotnet publish -c Release'

# cd to the publish directory
cd src/dncCnt/bin/Release/netcoreapp1.0/publish/

# build app container
docker build -t cnt .

# start a mariadb instance (mysql would be fine to...)
docker run --name db -e MYSQL_ROOT_PASSWORD=someRandomPassword -d --restart always mariadb

# start the counter app
docker run --name cnt \
  -e connectionString="Server=db;Port=3306;Database=counter;User ID=root;Password=someRandomPassword;Pooling=true" \
  -e "VIRTUAL_HOST=counter.77tac.com" \
  -e "LETSENCRYPT_HOST=counter.77tac.com" \
  -e "[email protected]" \
  --link db:db --restart always -d cnt:latest

# watch the logs to see when your new certificate is ready
docker logs -f nginx-letsencrypt

# optional - basic authentication
docker run --rm -it --volumes-from nginx-proxy jwilder/nginx-proxy \
  bash -c 'apt-get update && apt-get install -y apache2-utils && htpasswd -bc /etc/nginx/htpasswd/counter.77tac.com user pass1234'

# try it
curl https://user:[email protected]/Counter/Increment/2311ca3a-858e-aa46-74ca-01923610ab59

# reboot and see if its still working :)