#!/bin/bash
# This example will run a basic nginx server provisionned with an index.html file
# Make sure to replace "site.example.com" with a public accessible domain poiting to the server you will run this on.

# This nginx container will get a configuration generated by the docker-gen instance and act as a reverse-proxy
echo "Starting nginx instance..."
docker run -d -p 80:80 -p 443:443 \
    --name nginx \
    -v /etc/nginx/conf.d  \
    -v /etc/nginx/vhost.d \
    -v /usr/share/nginx/html \
    -v $(pwd)/../../volumes/proxy/certs:/etc/nginx/certs:ro \
    nginx

# This nginx-gen container using the docker-gen image will generate a 'default.conf' file from the 'nginx.tmpl' located in volumes/proxy/templates.
echo "Starting docker-gen instance..."
docker run -d \
    --name nginx-gen \
    --volumes-from nginx \
    -v $(pwd)/../../volumes/proxy/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    jwilder/docker-gen \
    -notify-sighup nginx -watch -only-exposed -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf


echo "Starting letsencrypt-nginx-proxy-companion..."
docker run -d \
    -e "NGINX_DOCKER_GEN_CONTAINER=nginx-gen" \
    --volumes-from nginx \
    -v $(pwd)/../../volumes/proxy/certs:/etc/nginx/certs:rw \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    jrcs/letsencrypt-nginx-proxy-companion


# This an example service that will get picked up and served by the reverse proxy.
# Make sure you change all the default values in this file and in volumes/examples/simple-site
echo "Starting simple-site nginx example..."
docker run -d \
    --name simple-site \
    -e "VIRTUAL_HOST=site.example.com" \
    -e "LETSENCRYPT_HOST=site.example.com" \
    -e "LETSENCRYPT_EMAIL=mail@example.com" \
    -v $(pwd)/../../volumes/examples/simple-site/conf.d/:/etc/nginx/conf.d \
    nginx
