6
6
# https://docs.docker.com/compose/compose-file/compose-versioning/
7
7
version : " 3.8"
8
8
9
+ # These are volumes managed by Docker
9
10
volumes :
10
11
lab_mock :
12
+ letsencrypt :
11
13
12
14
services :
13
15
14
16
reverse-proxy :
15
17
container_name : reverse-proxy
16
18
image : traefik:v3.0
17
- command :
18
- # Remove this for production, this exposes the web UI
19
- - " --api.insecure=true"
20
- - " --providers.docker"
21
19
# healthcheck:
22
20
# test: ["CMD", "wget", "-q", "-O", "-", "http://localhost:8080/health"]
23
21
# interval: 30s
24
22
# timeout: 10s
25
- # retries: 3
23
+ # retries: 3
24
+ command :
25
+ # Remove this for production, this exposes the web UI
26
+ - " --providers.docker=true"
27
+ - " --providers.docker.exposedbydefault=false"
28
+ - " --entrypoints.web.address=:80"
29
+ - " --entrypoints.http.http.redirections.entryPoint.to=:443"
30
+ - " --entrypoints.http.http.redirections.entryPoint.scheme=https"
31
+ - " --entrypoints.http.http.redirections.entrypoint.permanent=true"
32
+ - " --entrypoints.https.address=:443"
33
+ # This allows us to use the staging server for development
34
+ # We could potentially move this to a variable name
35
+ # - "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
36
+ - " --certificatesResolvers.letsencrypt.acme.email=${SOA_EMAIL}"
37
+ - " --certificatesResolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
38
+ - " --certificatesResolvers.letsencrypt.acme.httpChallenge.entrypoint=http"
26
39
ports :
27
- # Remove this for production, this is the web UI
28
- - 8080:8080
29
- - 80:80
30
- - 443:443
40
+ - " 80:80"
41
+ - " 443:443"
31
42
labels :
43
+ - " traefik.enable=true"
44
+ # Minimum SSL version set to TLS 1.2
45
+ - " traefik.http.routers.${PROJ_NAME}-root.tls"
46
+ # The rule host will determine what domain the SSL cert
47
+ # will be provisioned for
48
+ - " traefik.http.routers.${PROJ_NAME}-root.rule=Host(`${PROJ_FQDN}`)"
49
+ - " traefik.http.routers.${PROJ_NAME}-root.tls.certResolver=letsencrypt"
50
+ - " traefik.tls.options.default.minVersion=VersionTLS12"
51
+ # Proxy the bucket or another container for the web client
52
+ - " traefik.http.middlewares.bucket-header.headers.customrequestheaders.host=${BUCKET_FQDN}"
53
+ # Declare a service to reverer proxy
54
+ - " traefik.http.services.bucket-service.loadbalancer.server.url=http://${BUCKET_FQDN}"
55
+ # Declare a router and attach the service to it
56
+ - " traefik.http.routers.web-client.entrypoints=https"
57
+ - " traefik.http.routers.web-client.rule=Host(`${PROJ_FQDN}`)"
58
+ - " traefik.http.routers.web-client.service=bucket-service"
59
+ - " traefik.http.routers.web-client.middlewares=bucket-header"
32
60
# Send X-Frame-Options to DENY
33
61
- " traefik.http.middlewares.testheader.headers.frameDeny=true"
34
62
# HSTS security headers
@@ -43,12 +71,12 @@ services:
43
71
# This is to expose the docker socker to the reverse proxy
44
72
# for it to use the docker provider
45
73
- /var/run/docker.sock:/var/run/docker.sock:ro
74
+ - letsencrypt:/letsencrypt
46
75
# The reverse proxy should be the last thing to be started
47
76
# it depends on the entire stack to be healthy
48
77
depends_on :
49
78
- lab_mock
50
79
51
-
52
80
# Mock application
53
81
# - In development we read secrets from .env.development
54
82
# - Provides a FastAPI based API that runs using uvicorn in development
@@ -59,8 +87,21 @@ services:
59
87
dockerfile : Dockerfile
60
88
env_file :
61
89
- .env.development
90
+ labels :
91
+ # Explicitly tell Traefik to expose this container
92
+ - " traefik.enable=true"
93
+ # Declare a middleware that strips the api prefix, this
94
+ # is required for FastaPI to mount on the root and for us
95
+ # to proxy the urls on the /api endpoint
96
+ - " traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api/"
97
+ # The router for this container is going to respond to the host
98
+ # of the project and root level url
99
+ - " traefik.http.routers.${PROJ_NAME}-api.rule=Host(`${PROJ_FQDN}`) && PathPrefix(`/api/`)"
100
+ - " traefik.http.routers.${PROJ_NAME}-api.middlewares=strip-api-prefix"
62
101
restart : unless-stopped
63
102
ports :
103
+ # This is to test if the app is working locally
104
+ # In production this would be proxied through traefik
64
105
- " 8000:80"
65
106
volumes :
66
107
- ./src/lab_mock:/opt/lab_mock
0 commit comments