Skip to content

Commit

Permalink
Create proxy with HTTPS for UCCSER websites
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMorganNZ committed Aug 5, 2021
1 parent 66cbab1 commit 3ac0188
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
certs/*
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# uccser-development-proxy
Proxy for working on UCCSER websites
# UCCSER Development Proxy

This proxy is used when working on the following UCCSER websites:

- [CS Unplugged](https://github.com/uccser/cs-unplugged)
- [CS Field Guide](https://github.com/uccser/cs-field-guide)
- [codeWOF](https://github.com/uccser/codewof)
- [DTHM for Kaiako](https://github.com/uccser/dthm4kaiako)

This proxy allows multiple systems to run on your development environment simultaneously.

# Setup

You will need to have the following tools installed to run this proxy:

- Docker
- Docker Compose
- [mkcert](https://github.com/FiloSottile/mkcert)

Once these tools have been installed, then run `./create-certs.sh`.
The script will create SSL certificates for all our websites.
The script will finish with telling you when the certificates expire, where you will be required to rerun this setup.

# Usage

To run the proxy, run `docker-compose up -d` in this project directory.
Docker will run the proxy in the background.

You can view the dashboard of the proxy by opening a browser and going to `proxy.localhost` in your preferred web browser.

To view logs of the proxy, run `docker-compose logs -f traefik`.

Do shutdown the proxy, run `docker-compose down`.
If you get a error when running this command, saying `ERROR: error while removing network: network uccser-development-proxy`, then one of our website systems is likely still running.
The proxy will be shutdown, but the network will remain active.
If you wish to remove the network, you will need to end all UCCSER website systems first.

# Notes

The proxy binds to ports 80 and 443.
If you are trying to run other systems that wish to bind to these ports, you will need to shutdown the proxy.
4 changes: 4 additions & 0 deletions create-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
mkcert -install
mkdir certs
mkcert -key-file certs/key.pem -cert-file certs/cert.pem proxy.localhost cs-unplugged.localhost *.cs-unplugged.localhost cs-field-guide.localhost *.cs-field-guide.localhost codewof.localhost *.codewof.localhost dthm4kaiako.localhost *.dthm4kaiako.localhost
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.8"

services:
traefik:
image: traefik:v2.4.13
container_name: uccser-development-proxy
ports:
# HTTP/HTTPS ports
- "80:80"
- "443:443"
environment:
- TZ=Pacific/Auckland
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock:ro
# Map certificates into the container
- ./certs:/etc/traefik/:z
# Map static config into the container
- ./traefik.yml:/etc/traefik/traefik.yml:ro
networks:
- uccser-development-proxy
labels:
# General labels
- "traefik.enable=true"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
# HTTPS
- "traefik.http.routers.traefik.entryPoints=web-secure"
- "traefik.http.routers.traefik.service=traefik"
- "traefik.http.routers.traefik.rule=Host(`proxy.localhost`)"
- "traefik.http.routers.traefik.tls=true"

networks:
uccser-development-proxy:
driver: bridge
# Set name so not scoped with stack name
name: uccser-development-proxy
37 changes: 37 additions & 0 deletions traefik.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Defines openings for incoming requests
entryPoints:
web:
address: ":80"
# Global redirect from HTTP to HTTPS
http:
redirections:
entryPoint:
to: web-secure
scheme: https
web-secure:
address: ":443"

providers:
docker:
endpoint: "unix:///var/run/docker.sock"
watch: true
exposedByDefault: false
file:
directory: "/etc/traefik/"
watch: true

tls:
certificates:
- certFile: "/etc/traefik/cert.pem"
keyFile: "/etc/traefik/key.pem"

log:
level: INFO
format: common

global:
sendAnonymousUsage: false

api:
dashboard: true
insecure: true

0 comments on commit 3ac0188

Please sign in to comment.