Skip to content

Commit d61daad

Browse files
committed
Add caddy as reverse procy
1 parent 38b8d83 commit d61daad

11 files changed

+88
-217
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Project Changelog
22

3+
4+
## v0.1.17 (2023-04-01)
5+
6+
#### 💅 Polish
7+
8+
- `Migrate from traefik to Caddy as reverse proxy server`
9+
310
## v0.1.16 (2023-03-25)
411

512
#### 💅 Polish

Diff for: README.md

+4-15
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ This starts pgamin in [http://localhost:15432](http://localhost:15432).
7979
<img src="static/container_architecture.png" align="center"/>
8080
</p>
8181

82-
As this project uses [traefik](https://doc.traefik.io/traefik/routing/routers/) as a reverse proxy, which uses namespaces routing, you can access the documentation with the following path [http://fastapi.localhost/docs](http://fastapi.localhost/docs)
82+
As this project uses [Caddy](https://caddyserver.com/) as a reverse proxy, which uses namespaces routing, you can access the documentation with the following path [http://fastapi.localhost/docs](http://fastapi.localhost/docs)
8383

8484
## Preview
8585

@@ -90,18 +90,8 @@ As this project uses [traefik](https://doc.traefik.io/traefik/routing/routers/)
9090
<img src="static/2.png" align="center"/>
9191
</p>
9292

93-
## Traefik Dashboard
94-
Traefik has been configurated as a reverse proxy on the ingress of the project; you can access Traefik Dashboard using the following link [http://traefik.localhost/](http://traefik.localhost/). You should use **username: test** and **pass: test**. If you want to change the password, you can find more information on how to do it [here](https://doc.traefik.io/traefik/operations/api/)
95-
96-
<p align="center">
97-
<img src="static/traefik1.png" align="center"/>
98-
</p>
99-
<p align="center">
100-
<img src="static/traefik2.png" align="center"/>
101-
</p>
102-
10393
## Static files
104-
All files on static folder will be served by nginx container as static files. You can check it with this link [http://nginx.localhost/1.png](http://nginx.localhost/1.png)
94+
All files on static folder will be served by Caddy container as static files. You can check it with this link [http://static.localhost](http://static.localhost)
10595

10696
## Minio server
10797
This template allows users can upload their photos. The images are stored using the open source Object Storage Service (OSS) [minio](https://min.io/), which provides storage of images using buckets in a secure way through presigned URLs.
@@ -265,8 +255,7 @@ When the build is successful, you can see the SonarQube screen automatically ref
265255
- [x] Add JWT authentication
266256
- [x] Add Pagination
267257
- [x] Add User birthday field with timezone
268-
- [x] Add reverse proxy (traefik) with docker compose
269-
- [x] Add static server with nginx
258+
- [x] Add static server
270259
- [x] Add basic RBAC (Role base access control)
271260
- [x] Add sample heroes, teams and groups on init db
272261
- [x] Add cache configuration using fastapi-cache2 and redis
@@ -290,7 +279,7 @@ When the build is successful, you can see the SonarQube screen automatically ref
290279
- [x] Upgrade typing (Compatible just with python > 3.10)
291280
- [x] Add sample transformers NLP models and use them globally
292281
- [x] Add Celery samples for tasks, and schedule tasks
293-
- [ ] Migrate from traefik reverse proxy to Caddy reverse proxy for automatic ssl
282+
- [x] Migrate from traefik reverse proxy to Caddy reverse proxy for automatic ssl
294283
- [ ] Add a nextjs sample frontend
295284
- [ ] Add testing
296285
- [ ] Add jsonb field on table sample

Diff for: caddy/Caddyfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
3+
}
4+
5+
fastapi.{$EXT_ENDPOINT1}:80, fastapi.{$LOCAL_1}:80, fastapi.{$LOCAL_2}:80, :80 {
6+
reverse_proxy fastapi_server:8000
7+
}
8+
9+
storage.{$EXT_ENDPOINT1}:80, storage.{$LOCAL_1}:80, storage.{$LOCAL_2}:80 {
10+
reverse_proxy minio_server:9000
11+
}
12+
13+
stash.{$EXT_ENDPOINT1}:80, stash.{$LOCAL_1}:80, stash.{$LOCAL_2}:80 {
14+
reverse_proxy minio_server:9090
15+
}
16+
17+
static.{$EXT_ENDPOINT1}:80, static.{$LOCAL_1}:80, static.{$LOCAL_2}:80 {
18+
root * /code/static
19+
file_server browse
20+
}
21+
22+
## Uncomment this to automatic ssl
23+
# fastapi.{$EXT_ENDPOINT1}, fastapi.{$LOCAL_1}, fastapi.{$LOCAL_2} {
24+
# reverse_proxy fastapi_server:8000
25+
# }
26+
27+
# storage.{$EXT_ENDPOINT1}, storage.{$LOCAL_1}, storage.{$LOCAL_2} {
28+
# reverse_proxy minio_server:9000
29+
# }
30+
31+
# stash.{$EXT_ENDPOINT1}, stash.{$LOCAL_1}, stash.{$LOCAL_2} {
32+
# reverse_proxy minio_server:9090
33+
# }
34+
35+
# static.{$EXT_ENDPOINT1}, static.{$LOCAL_1}, static.{$LOCAL_2} {
36+
# root * /code/static
37+
# file_server browse
38+
# }

Diff for: docker-compose-dev.yml

+19-54
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ services:
1515
depends_on:
1616
- database
1717
links:
18-
- traefik-proxy:storage.localhost
19-
labels:
20-
- "traefik.enable=true"
21-
- "traefik.http.routers.fastapi_local.entrypoints=web"
22-
- "traefik.http.routers.fastapi_local.rule=Host(`fastapi.${LOCAL_1}`, `fastapi.${LOCAL_2}`, `fastapi.${EXT_ENDPOINT1}`)"
23-
- "traefik.http.routers.fastapi_local_base.entrypoints=web"
24-
- "traefik.http.routers.fastapi_local_base.rule=Host(`${LOCAL_1}`, `${LOCAL_2}`, `${EXT_ENDPOINT1}`)"
25-
- traefik.http.services.fastapi_localservice.loadbalancer.server.port=8000
18+
- caddy_reverse_proxy:storage.localhost
2619

2720
database:
2821
image: bitnami/postgresql:13.3.0
@@ -84,26 +77,6 @@ services:
8477
- database
8578
- redis_server
8679
env_file: .env
87-
88-
89-
nginx_server:
90-
container_name: nginx_server
91-
restart: unless-stopped
92-
logging:
93-
driver: none
94-
image: "nginx:alpine"
95-
expose:
96-
- 8080
97-
volumes:
98-
- ./static:/code/static
99-
- ./nginx-config-files/nginx.conf:/etc/nginx/nginx.conf
100-
- ./nginx-config-files/app.nginx.template:/etc/nginx/templates/app.nginx.template
101-
- "${EB_LOG_BASE_DIR:-./nginx-config-files}/nginx-proxy:/var/log/nginx"
102-
labels:
103-
- "traefik.enable=true"
104-
- "traefik.http.routers.nginx_local.entrypoints=web"
105-
- "traefik.http.routers.nginx_local.rule=Host(`nginx.${LOCAL_1}`, `nginx.${LOCAL_2}`, `nginx.${EXT_ENDPOINT1}`)"
106-
- traefik.http.services.nginx_local_service.loadbalancer.server.port=8080
10780

10881
minio_server:
10982
image: minio/minio:latest
@@ -119,33 +92,25 @@ services:
11992
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
12093
MINIO_BROWSER_REDIRECT_URL: http://stash.localhost
12194
command: "server /data --console-address ':9090'"
122-
labels:
123-
- traefik.enable=true
124-
- traefik.http.routers.minio.entrypoints=web
125-
- traefik.http.routers.minio.service=minio
126-
- traefik.http.routers.minio.rule=Host(`storage.${LOCAL_1}`, `storage.${LOCAL_2}`, `storage.${EXT_ENDPOINT1}`)
127-
- traefik.http.services.minio.loadbalancer.server.port=9000
128-
- traefik.http.routers.minio-console.entrypoints=web
129-
- traefik.http.routers.minio-console.service=minio-console
130-
- traefik.http.routers.minio-console.rule=Host(`stash.${LOCAL_1}`, `stash.${LOCAL_2}`, `stash.${EXT_ENDPOINT1}`)
131-
- traefik.http.services.minio-console.loadbalancer.server.port=9090
13295

133-
traefik-proxy:
134-
container_name: traefik-proxy
96+
caddy_reverse_proxy:
97+
container_name: caddy_reverse_proxy
98+
image: caddy:alpine
13599
restart: always
136-
image: "traefik:latest"
137-
command:
138-
- "--providers.docker=true"
139100
ports:
140-
- "80:80"
101+
- 80:80
102+
- 8080:8080
103+
- 443:443
104+
environment:
105+
- EXT_ENDPOINT1=${EXT_ENDPOINT1}
106+
- LOCAL_1=${LOCAL_1}
107+
- LOCAL_2=${LOCAL_2}
141108
volumes:
142-
- "/var/run/docker.sock:/var/run/docker.sock:ro"
143-
- ./traefik/traefik.yml:/traefik.yml:ro
144-
- ./traefik/.htpasswd:/.htpasswd
145-
- "${EB_LOG_BASE_DIR:-./traefik}/traefik-proxy:/logs"
146-
labels:
147-
- "traefik.enable=true"
148-
- "traefik.http.routers.dashboard.rule=Host(`traefik.${LOCAL_1}`, `traefik.${LOCAL_2}`, `traefik.${EXT_ENDPOINT1}`)"
149-
- "traefik.http.routers.dashboard.service=api@internal"
150-
- "traefik.http.routers.dashboard.middlewares=auth"
151-
- "traefik.http.middlewares.auth.basicauth.usersfile=/.htpasswd"
109+
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
110+
- ./static:/code/static
111+
- caddy_data:/data
112+
- caddy_config:/config
113+
114+
volumes:
115+
caddy_data:
116+
caddy_config:

Diff for: docker-compose.yml

+20-54
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ services:
1414
depends_on:
1515
- database
1616
links:
17-
- traefik-proxy:storage.localhost
18-
labels:
19-
- "traefik.enable=true"
20-
- "traefik.http.routers.fastapi_local.entrypoints=web"
21-
- "traefik.http.routers.fastapi_local.rule=Host(`fastapi.${LOCAL_1}`, `fastapi.${LOCAL_2}`, `fastapi.${EXT_ENDPOINT1}`)"
22-
- "traefik.http.routers.fastapi_local_base.entrypoints=web"
23-
- "traefik.http.routers.fastapi_local_base.rule=Host(`${LOCAL_1}`, `${LOCAL_2}`, `${EXT_ENDPOINT1}`)"
24-
- traefik.http.services.fastapi_localservice.loadbalancer.server.port=8000
17+
- caddy_reverse_proxy:storage.localhost
2518

2619
database:
2720
image: bitnami/postgresql:13.3.0
@@ -87,25 +80,6 @@ services:
8780
env_file: .env
8881

8982

90-
nginx_server:
91-
container_name: nginx_server
92-
restart: unless-stopped
93-
logging:
94-
driver: none
95-
image: "nginx:alpine"
96-
expose:
97-
- 8080
98-
volumes:
99-
- ./static:/code/static
100-
- ./nginx-config-files/nginx.conf:/etc/nginx/nginx.conf
101-
- ./nginx-config-files/app.nginx.template:/etc/nginx/templates/app.nginx.template
102-
- "${EB_LOG_BASE_DIR:-./nginx-config-files}/nginx-proxy:/var/log/nginx"
103-
labels:
104-
- "traefik.enable=true"
105-
- "traefik.http.routers.nginx_local.entrypoints=web"
106-
- "traefik.http.routers.nginx_local.rule=Host(`nginx.${LOCAL_1}`, `nginx.${LOCAL_2}`, `nginx.${EXT_ENDPOINT1}`)"
107-
- traefik.http.services.nginx_local_service.loadbalancer.server.port=8080
108-
10983
minio_server:
11084
image: minio/minio:latest
11185
restart: always
@@ -119,34 +93,26 @@ services:
11993
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
12094
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
12195
MINIO_BROWSER_REDIRECT_URL: http://stash.localhost
122-
command: "server /data --console-address ':9090'"
123-
labels:
124-
- traefik.enable=true
125-
- traefik.http.routers.minio.entrypoints=web
126-
- traefik.http.routers.minio.service=minio
127-
- traefik.http.routers.minio.rule=Host(`storage.${LOCAL_1}`, `storage.${LOCAL_2}`, `storage.${EXT_ENDPOINT1}`)
128-
- traefik.http.services.minio.loadbalancer.server.port=9000
129-
- traefik.http.routers.minio-console.entrypoints=web
130-
- traefik.http.routers.minio-console.service=minio-console
131-
- traefik.http.routers.minio-console.rule=Host(`stash.${LOCAL_1}`, `stash.${LOCAL_2}`, `stash.${EXT_ENDPOINT1}`)
132-
- traefik.http.services.minio-console.loadbalancer.server.port=9090
96+
command: "server /data --console-address ':9090'"
13397

134-
traefik-proxy:
135-
container_name: traefik-proxy
98+
caddy_reverse_proxy:
99+
container_name: caddy_reverse_proxy
100+
image: caddy:alpine
136101
restart: always
137-
image: "traefik:latest"
138-
command:
139-
- "--providers.docker=true"
140102
ports:
141-
- "80:80"
103+
- 80:80
104+
- 8080:8080
105+
- 443:443
106+
environment:
107+
- EXT_ENDPOINT1=${EXT_ENDPOINT1}
108+
- LOCAL_1=${LOCAL_1}
109+
- LOCAL_2=${LOCAL_2}
142110
volumes:
143-
- "/var/run/docker.sock:/var/run/docker.sock:ro"
144-
- ./traefik/traefik.yml:/traefik.yml:ro
145-
- ./traefik/.htpasswd:/.htpasswd
146-
- "${EB_LOG_BASE_DIR:-./traefik}/traefik-proxy:/logs"
147-
labels:
148-
- "traefik.enable=true"
149-
- "traefik.http.routers.dashboard.rule=Host(`traefik.${LOCAL_1}`, `traefik.${LOCAL_2}`, `traefik.${EXT_ENDPOINT1}`)"
150-
- "traefik.http.routers.dashboard.service=api@internal"
151-
- "traefik.http.routers.dashboard.middlewares=auth"
152-
- "traefik.http.middlewares.auth.basicauth.usersfile=/.htpasswd"
111+
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
112+
- ./static:/code/static
113+
- caddy_data:/data
114+
- caddy_config:/config
115+
116+
volumes:
117+
caddy_data:
118+
caddy_config:

Diff for: nginx-config-files/app.nginx.template

-28
This file was deleted.

Diff for: nginx-config-files/nginx.conf

-66
This file was deleted.

Diff for: static/container_architecture.png

-11.9 KB
Loading

Diff for: static/index.html

Whitespace-only changes.

Diff for: static/traefik1.png

-318 KB
Binary file not shown.

Diff for: static/traefik2.png

-286 KB
Binary file not shown.

0 commit comments

Comments
 (0)