Skip to content

Commit 07064ae

Browse files
authoredMar 9, 2024
📝 Update deployment files and docs (fastapi#660)
1 parent 3de18e5 commit 07064ae

File tree

8 files changed

+269
-102
lines changed

8 files changed

+269
-102
lines changed
 

‎.env

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ SENTRY_DSN=
3838
# Flower
3939
FLOWER_BASIC_AUTH=
4040

41-
# Traefik
42-
TRAEFIK_PUBLIC_NETWORK=traefik-public
43-
TRAEFIK_TAG=traefik
44-
TRAEFIK_PUBLIC_TAG=traefik-public
45-
4641
# Configure these with your own Docker registry images
4742
DOCKER_IMAGE_BACKEND=backend
4843
DOCKER_IMAGE_CELERYWORKER=celery

‎backend/app/core/config.py

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class Settings(BaseSettings):
1717
# 60 minutes * 24 hours * 8 days = 8 days
1818
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
1919
SERVER_HOST: AnyHttpUrl
20-
# BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
21-
# e.g: '["http://localhost", "http://localhost:4200", "http://localhost:3000", \
22-
# "http://localhost:8080", "http://local.dockertoolbox.tiangolo.com"]'
2320
BACKEND_CORS_ORIGINS: list[AnyHttpUrl] | str = []
2421

2522
@field_validator("BACKEND_CORS_ORIGINS", mode="before")

‎deployment.md

+110-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,124 @@
11
# FastAPI Project - Deployment
22

3-
You can deploy the using Docker Compose with a main Traefik proxy outside handling communication to the outside world and HTTPS certificates.
3+
You can deploy the project using Docker Compose in a remote server.
44

5-
And you can use CI (continuous integration) systems to do it automatically.
5+
It expects you to have a Traefik proxy handling communication to the outside world and HTTPS certificates.
6+
7+
And you can use CI (continuous integration) systems to deploy automatically.
68

79
But you have to configure a couple things first.
810

9-
## Traefik network
11+
## Preparation
12+
13+
* Have a remote server ready and available.
14+
* Configure the DNS records of your domain to point to the IP of the server you just created.
15+
* Install and configure [Docker](https://docs.docker.com/engine/install/).
16+
* Create a remote directory to store your code, for example:
17+
18+
```bash
19+
mkdir -p /root/code/fastapi-project/
20+
```
21+
22+
## Public Traefik
23+
24+
We need a Traefik proxy to handle incoming connections and HTTPS certificates.
25+
26+
### Traefik Docker Compose
27+
28+
Copy the Traefik Docker Compose file to your server, to your code directory. You could do it with `rsync`:
29+
30+
```bash
31+
rsync -a docker-compose.traefik.yml root@your-server.example.com:/root/code/fastapi-project/
32+
```
33+
34+
### Traefik Public Network
35+
36+
This Traefik will expect a Docker "public network" named `traefik-public` to communicate with your stack(s).
37+
38+
This way, there will be a single public Traefik proxy that handles the communication (HTTP and HTTPS) with the outside world, and then behind that, you could have one or more stacks.
1039

11-
This stack expects the public Traefik network to be named `traefik-public`.
40+
To create a Docker "public network" named `traefik-public` run:
1241

13-
If you need to use a different Traefik public network name, update it in the `docker-compose.yml` files, in the section:
42+
```bash
43+
docker network create traefik-public
44+
```
45+
46+
### Traefik Environment Variables
47+
48+
The Traefik Docker Compose file expects some environment variables to be set.
1449

15-
```YAML
16-
networks:
17-
traefik-public:
18-
external: true
50+
Create the environment variables for HTTP Basic Auth.
51+
52+
* Create the username, e.g.:
53+
54+
```bash
55+
export USERNAME=admin
56+
```
57+
58+
* Create an environment variable with the password, e.g.:
59+
60+
```bash
61+
export PASSWORD=changethis
62+
```
63+
64+
* Use openssl to generate the "hashed" version of the password and store it in an environment variable:
65+
66+
```bash
67+
export HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD)
1968
```
2069

21-
Change `traefik-public` to the name of the used Traefik network. And then update it in the file `.env`:
70+
* Create an environment variable with the domain name, e.g.:
2271

2372
```bash
24-
TRAEFIK_PUBLIC_NETWORK=traefik-public
73+
export DOMAIN=fastapi-project.example.com
2574
```
75+
76+
* Create an environment variable with the email for Let's Encrypt, e.g.:
77+
78+
```bash
79+
export EMAIL=admin@example.com
80+
```
81+
82+
### Start the Traefik Docker Compose
83+
84+
Now with the environment variables set and the `docker-compose.traefik.yml` in place, you can start the Traefik Docker Compose:
85+
86+
```bash
87+
docker compose -f docker-compose.traefik.yml up -d
88+
```
89+
90+
## Deploy the FastAPI Project
91+
92+
Now that you have Traefik in place you can deploy your FastAPI project with Docker Compose.
93+
94+
You could configure the variables in the `.env` file to match your domain, or you could override them before running the `docker compose` command.
95+
96+
For example:
97+
98+
```bash
99+
export DOMAIN=fastapi-project.example.com
100+
```
101+
102+
And then deploy with Docker Compose:
103+
104+
```bash
105+
docker compose -f docker-compose.yml up -d
106+
```
107+
108+
For production you wouldn't want to have the overrides in `docker-compose.override.yml`, so you would need to explicitly specify the file to use, `docker-compose.yml`.
109+
110+
## URLs
111+
112+
Replace `fastapi-project.example.com` with your domain:
113+
114+
Frontend: https://fastapi-project.example.com
115+
116+
Backend API docs: https://fastapi-project.example.com/docs
117+
118+
Backend API base URL: https://fastapi-project.example.com/api/
119+
120+
PGAdmin: https://pgadmin.fastapi-project.example.com
121+
122+
Flower: https://flower.fastapi-project.example.com
123+
124+
Traefik UI: https://traefik.fastapi-project.example.com

‎docker-compose.override.yml

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: "3.3"
22
services:
33

44
proxy:
5+
image: traefik:v2.3
6+
volumes:
7+
- /var/run/docker.sock:/var/run/docker.sock
58
ports:
69
- "80:80"
710
- "8090:8080"
@@ -10,10 +13,13 @@ services:
1013
# Enable Docker in Traefik, so that it reads labels from Docker services
1114
- --providers.docker
1215
# Add a constraint to only use services with the label for this stack
13-
# from the env var TRAEFIK_TAG
14-
- --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
16+
- --providers.docker.constraints=Label(`traefik.constraint-label`, `traefik-public`)
1517
# Do not expose all Docker services, only the ones explicitly exposed
1618
- --providers.docker.exposedbydefault=false
19+
# Create an entrypoint "http" listening on port 80
20+
- --entrypoints.http.address=:80
21+
# Create an entrypoint "https" listening on port 443
22+
- --entrypoints.https.address=:443
1723
# Enable the access log, with HTTP requests
1824
- --accesslog
1925
# Enable the Traefik log, for configurations and errors
@@ -23,8 +29,12 @@ services:
2329
# Enable the Dashboard and API in insecure mode for local development
2430
- --api.insecure=true
2531
labels:
26-
- traefik.http.routers.${STACK_NAME?Variable not set}-traefik-public-http.rule=Host(`${DOMAIN?Variable not set}`)
27-
- traefik.http.services.${STACK_NAME?Variable not set}-traefik-public.loadbalancer.server.port=80
32+
# Enable Traefik for this service, to make it available in the public network
33+
- traefik.enable=true
34+
- traefik.constraint-label=traefik-public
35+
# Dummy https-redirect middleware that doesn't really redirect, only to
36+
# allow running it locally
37+
- traefik.http.middlewares.https-redirect.contenttype.autodetect=false
2838

2939
db:
3040
ports:
@@ -72,6 +82,13 @@ services:
7282
args:
7383
INSTALL_DEV: ${INSTALL_DEV-true}
7484

85+
frontend:
86+
build:
87+
context: ./frontend
88+
args:
89+
- VITE_API_URL=http://${DOMAIN?Variable not set}
90+
- NODE_ENV=development
91+
7592
networks:
7693
traefik-public:
7794
# For local dev, don't expect an external Traefik network

‎docker-compose.traefik.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
services:
2+
traefik:
3+
image: traefik:v2.3
4+
ports:
5+
# Listen on port 80, default for HTTP, necessary to redirect to HTTPS
6+
- 80:80
7+
# Listen on port 443, default for HTTPS
8+
- 443:443
9+
restart: always
10+
labels:
11+
# Enable Traefik for this service, to make it available in the public network
12+
- traefik.enable=true
13+
# Use the traefik-public network (declared below)
14+
- traefik.docker.network=traefik-public
15+
# Define the port inside of the Docker service to use
16+
- traefik.http.services.traefik-dashboard.loadbalancer.server.port=8080
17+
# Make Traefik use this domain (from an environment variable) in HTTP
18+
- traefik.http.routers.traefik-dashboard-http.entrypoints=http
19+
- traefik.http.routers.traefik-dashboard-http.rule=Host(`traefik.${DOMAIN?Variable not set}`)
20+
# traefik-https the actual router using HTTPS
21+
- traefik.http.routers.traefik-dashboard-https.entrypoints=https
22+
- traefik.http.routers.traefik-dashboard-https.rule=Host(`traefik.${DOMAIN?Variable not set}`)
23+
- traefik.http.routers.traefik-dashboard-https.tls=true
24+
# Use the "le" (Let's Encrypt) resolver created below
25+
- traefik.http.routers.traefik-dashboard-https.tls.certresolver=le
26+
# Use the special Traefik service api@internal with the web UI/Dashboard
27+
- traefik.http.routers.traefik-dashboard-https.service=api@internal
28+
# https-redirect middleware to redirect HTTP to HTTPS
29+
- traefik.http.middlewares.https-redirect.redirectscheme.scheme=https
30+
- traefik.http.middlewares.https-redirect.redirectscheme.permanent=true
31+
# traefik-http set up only to use the middleware to redirect to https
32+
- traefik.http.routers.traefik-dashboard-http.middlewares=https-redirect
33+
# admin-auth middleware with HTTP Basic auth
34+
# Using the environment variables USERNAME and HASHED_PASSWORD
35+
- traefik.http.middlewares.admin-auth.basicauth.users=${USERNAME?Variable not set}:${HASHED_PASSWORD?Variable not set}
36+
# Enable HTTP Basic auth, using the middleware created above
37+
- traefik.http.routers.traefik-dashboard-https.middlewares=admin-auth
38+
volumes:
39+
# Add Docker as a mounted volume, so that Traefik can read the labels of other services
40+
- /var/run/docker.sock:/var/run/docker.sock:ro
41+
# Mount the volume to store the certificates
42+
- traefik-public-certificates:/certificates
43+
command:
44+
# Enable Docker in Traefik, so that it reads labels from Docker services
45+
- --providers.docker
46+
# Do not expose all Docker services, only the ones explicitly exposed
47+
- --providers.docker.exposedbydefault=false
48+
# Create an entrypoint "http" listening on port 80
49+
- --entrypoints.http.address=:80
50+
# Create an entrypoint "https" listening on port 443
51+
- --entrypoints.https.address=:443
52+
# Create the certificate resolver "le" for Let's Encrypt, uses the environment variable EMAIL
53+
- --certificatesresolvers.le.acme.email=${EMAIL?Variable not set}
54+
# Store the Let's Encrypt certificates in the mounted volume
55+
- --certificatesresolvers.le.acme.storage=/certificates/acme.json
56+
# Use the TLS Challenge for Let's Encrypt
57+
- --certificatesresolvers.le.acme.tlschallenge=true
58+
# Enable the access log, with HTTP requests
59+
- --accesslog
60+
# Enable the Traefik log, for configurations and errors
61+
- --log
62+
# Enable the Dashboard and API
63+
- --api
64+
networks:
65+
# Use the public network created to be shared between Traefik and
66+
# any other service that needs to be publicly available with HTTPS
67+
- traefik-public
68+
69+
volumes:
70+
# Create a volume to store the certificates, even if the container is recreated
71+
traefik-public-certificates:
72+
73+
networks:
74+
# Use the previously created public network "traefik-public", shared with other
75+
# services that need to be publicly available via this Traefik
76+
traefik-public:
77+
external: true

‎docker-compose.yml

+59-78
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,5 @@
11
version: "3.3"
22
services:
3-
4-
proxy:
5-
image: traefik:v2.3
6-
networks:
7-
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
8-
- default
9-
volumes:
10-
- /var/run/docker.sock:/var/run/docker.sock
11-
command:
12-
# Enable Docker in Traefik, so that it reads labels from Docker services
13-
- --providers.docker
14-
# Add a constraint to only use services with the label for this stack
15-
# from the env var TRAEFIK_TAG
16-
- --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
17-
# Do not expose all Docker services, only the ones explicitly exposed
18-
- --providers.docker.exposedbydefault=false
19-
# Enable the access log, with HTTP requests
20-
- --accesslog
21-
# Enable the Traefik log, for configurations and errors
22-
- --log
23-
# Enable the Dashboard and API
24-
- --api
25-
labels:
26-
# Enable Traefik for this service, to make it available in the public network
27-
- traefik.enable=true
28-
# Use the traefik-public network (declared below)
29-
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
30-
# Use the custom label "traefik.constraint-label=traefik-public"
31-
# This public Traefik will only use services with this label
32-
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
33-
# traefik-http set up only to use the middleware to redirect to https
34-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
35-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
36-
# Handle host with and without "www" to redirect to only one of them
37-
# Uses environment variable DOMAIN
38-
# To disable www redirection remove the Host() you want to discard, here and
39-
# below for HTTPS
40-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
41-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
42-
# traefik-https the actual router using HTTPS
43-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
44-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
45-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
46-
# Use the "le" (Let's Encrypt) resolver created below
47-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
48-
# Define the port inside of the Docker service to use
49-
- traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
50-
# Handle domain with and without "www" to redirect to only one
51-
# To disable www redirection remove the next line
52-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
53-
# Redirect a domain with www to non-www
54-
# To disable it remove the next line
55-
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
56-
# Redirect a domain without www to www
57-
# To enable it remove the previous line and uncomment the next
58-
# - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
59-
# Middleware to redirect www, to disable it remove the next line
60-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
61-
# Middleware to redirect www, and redirect HTTP to HTTPS
62-
# to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
63-
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect
64-
653
db:
664
image: postgres:12
675
volumes:
@@ -74,19 +12,19 @@ services:
7412
pgadmin:
7513
image: dpage/pgadmin4
7614
networks:
77-
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
15+
- traefik-public
7816
- default
7917
depends_on:
8018
- db
8119
env_file:
8220
- .env
8321
labels:
8422
- traefik.enable=true
85-
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
86-
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
23+
- traefik.docker.network=traefik-public
24+
- traefik.constraint-label=traefik-public
8725
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
8826
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.entrypoints=http
89-
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
27+
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=https-redirect
9028
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
9129
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.entrypoints=https
9230
- traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls=true
@@ -103,7 +41,7 @@ services:
10341
flower:
10442
image: mher/flower:0.9.7
10543
networks:
106-
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
44+
- traefik-public
10745
- default
10846
env_file:
10947
- .env
@@ -114,11 +52,11 @@ services:
11452
# - "--broker_api=http://guest:guest@queue:15672/api//"
11553
labels:
11654
- traefik.enable=true
117-
- traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
118-
- traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
55+
- traefik.docker.network=traefik-public
56+
- traefik.constraint-label=traefik-public
11957
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
12058
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
121-
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
59+
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=https-redirect
12260
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
12361
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
12462
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
@@ -127,6 +65,9 @@ services:
12765

12866
backend:
12967
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
68+
networks:
69+
- traefik-public
70+
- default
13071
depends_on:
13172
- db
13273
env_file:
@@ -143,10 +84,21 @@ services:
14384
INSTALL_DEV: ${INSTALL_DEV-false}
14485
labels:
14586
- traefik.enable=true
146-
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
147-
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
87+
- traefik.docker.network=traefik-public
88+
- traefik.constraint-label=traefik-public
89+
14890
- traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
14991

92+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=Host(`${DOMAIN?Variable not set}`, `www.${DOMAIN?Variable not set}`) && PathPrefix(`/api`, `/docs`, `/redoc`)
93+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http
94+
95+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.rule=Host(`${DOMAIN?Variable not set}`, `www.${DOMAIN?Variable not set}`) && PathPrefix(`/api`, `/docs`, `/redoc`)
96+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.entrypoints=https
97+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
98+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
99+
100+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
101+
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
150102
celeryworker:
151103
image: '${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}'
152104
depends_on:
@@ -166,18 +118,47 @@ services:
166118

167119
frontend:
168120
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
121+
networks:
122+
- traefik-public
123+
- default
169124
build:
170125
context: ./frontend
171-
labels:
172-
- traefik.enable=true
173-
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
174-
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
175-
- traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
126+
args:
127+
- VITE_API_URL=https://${DOMAIN?Variable not set}
128+
- NODE_ENV=production
129+
labels:
130+
- traefik.enable=true
131+
- traefik.docker.network=traefik-public
132+
- traefik.constraint-label=traefik-public
133+
134+
- traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
135+
136+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=Host(`${DOMAIN?Variable not set}`, `www.${DOMAIN?Variable not set}`)
137+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.entrypoints=http
138+
139+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.rule=Host(`${DOMAIN?Variable not set}`, `www.${DOMAIN?Variable not set}`)
140+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.entrypoints=https
141+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls=true
142+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls.certresolver=le
176143

144+
# Handle domain with and without "www" to redirect to only one
145+
# To disable www redirection remove the next line
146+
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^http(s)?://www.(${DOMAIN?Variable not set})/(.*)
147+
# Redirect a domain with www to non-www
148+
# To disable it remove the next line
149+
- traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=http$${1}://${DOMAIN?Variable not set}/$${3}
150+
# Redirect a domain without www to www
151+
# To enable it remove the previous line and uncomment the next
152+
# - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
153+
# Middleware to redirect www, to disable it remove the next line
154+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
155+
# Middleware to redirect www, and redirect HTTP to HTTPS
156+
# to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
157+
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
177158
volumes:
178159
app-db-data:
179160

180161
networks:
181162
traefik-public:
182163
# Allow setting it to false for testing
183-
external: ${TRAEFIK_PUBLIC_NETWORK_IS_EXTERNAL-true}
164+
external: true

‎frontend/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ RUN npm install
99

1010
COPY ./ /app/
1111

12+
ARG VITE_API_URL=${VITE_API_URL}
13+
1214
RUN npm run build
1315

1416

‎scripts/deploy.sh

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
set -e
55

66
DOMAIN=${DOMAIN?Variable not set} \
7-
TRAEFIK_TAG=${TRAEFIK_TAG?Variable not set} \
87
STACK_NAME=${STACK_NAME?Variable not set} \
98
TAG=${TAG?Variable not set} \
109
docker-compose \

0 commit comments

Comments
 (0)
Please sign in to comment.