Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.certs
/.certs
/.env
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
default: start

certificate:
./scripts/genlocalcrt.sh clean

start:
./start.sh
./scripts/start.sh

stop:
./stop.sh
./scripts/stop.sh

status:
./scripts/status.sh

status-watch:
watch -n 300 ./scripts/status.sh

view-logs:
./logs.sh
./scripts/logs.sh
20 changes: 17 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
traefik:
image: traefik:1.6.6-alpine
container_name: traefik
container_name: "${NAME}_traefik"
command: --docker
ports:
- '80:80'
Expand All @@ -15,9 +15,23 @@ services:
networks:
- proxy
labels:
- 'traefik.frontend.rule=Host:monitor.localhost'
- 'traefik.frontend.rule=Host:monitor.${BASE_DOMAIN}'
- 'traefik.port=8080'

portainer:
depends_on:
- traefik
image: portainer/portainer
container_name: "${NAME}_portainer"
command: --no-auth -H unix:///var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- proxy
labels:
- 'traefik.port=9000'
- 'traefik.frontend.rule=Host:portainer.${BASE_DOMAIN}'

networks:
proxy:
external: true
external: true
25 changes: 0 additions & 25 deletions genlocalcrt.sh

This file was deleted.

6 changes: 0 additions & 6 deletions logs.sh

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/defaults/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME=dtp
BASE_DOMAIN=localhost
22 changes: 22 additions & 0 deletions scripts/defaults/cert.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[req]
default_bits = 2048
prompt = no
default_md = sha256
x509_extensions = v3_req
distinguished_name = dn

[dn]
C = GB
ST = Kent
L = Canterbury
O = Deeson
emailAddress = adamd@deeson.co.uk
CN = localhost

[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
DNS.2 = *.localhost
DNS.3 = docker.local
1 change: 1 addition & 0 deletions scripts/defaults/cert.cnf.dns
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#DNS.4 = example.com
59 changes: 59 additions & 0 deletions scripts/genlocalcrt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

script_path=$(dirname $0)
working_dir=$(pwd)
cd "$script_path/.."
repo_root=$(pwd)

clean=0
if [ "$1" == "clean" ]; then
clean=1
fi

defaults="${script_path}/defaults"
cert_dir=.certs
if [ ! -e "${cert_dir}" ]; then
mkdir -p "${cert_dir}"
fi

if [ ! -f "${cert_dir}/cert.cnf" ]; then
cp "${defaults}/cert.cnf" "${cert_dir}/cert.cnf"
fi

if [ ! -f "${cert_dir}/cert.cnf.dns" ]; then
cp "${defaults}/cert.cnf.dns" "${cert_dir}/cert.cnf.dns"
fi

local_cert="${cert_dir}/local.crt"
local_key="${cert_dir}/local.key"

if [ "${clean}" -eq 1 ]; then
if [ -f "${local_cert}" ]; then
unlink "${local_cert}"
fi
if [ -f "${local_key}" ]; then
unlink "${local_key}"
fi
fi

if [ -f "${local_cert}" ] && [ -f "${local_key}" ] ; then
echo 'Certificate exists'
exit
fi

# Generate a self-signed certificate if one is missing.
# Certificate generation steps from https://somoit.net/security/security-create-self-signed-san-certificate-openssl.
openssl=`which openssl`
$openssl req \
-new \
-x509 \
-nodes \
-sha256 \
-days 3650 \
-newkey rsa:2048 \
-keyout "${local_key}" \
-out "${local_cert}" \
-config <(cat "${cert_dir}/cert.cnf" \
<(cat "${cert_dir}/cert.cnf.dns"))
7 changes: 7 additions & 0 deletions scripts/logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

script_path=$(dirname $0)
cd "$script_path/.." \
&& docker-compose logs -f traefik
10 changes: 8 additions & 2 deletions start.sh → scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env bash

set -e

script_path=$(dirname $0)
cd $script_path
cd "$script_path/.."

if [ ! -f .env ]; then
cp "${script_path}/defaults/.env" .env
fi

if [ ! -e ./.certs ]; then
mkdir ./.certs
fi

./genlocalcrt.sh ./.certs
./scripts/genlocalcrt.sh

if [ -z "$(docker network ls | fgrep -i proxy)" ]; then
docker network create proxy
Expand Down
12 changes: 12 additions & 0 deletions scripts/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

script_path=$(dirname $0)
cd "$script_path/.."

docker ps
echo -e
df -h
echo -e
uptime
5 changes: 3 additions & 2 deletions stop.sh → scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

set -e

script_path=$(dirname $0)
cd $script_path
cd "$script_path/.."

docker-compose down