Skip to content

Commit 73977b3

Browse files
feat: add Souin
1 parent ae6daab commit 73977b3

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

api/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ ARG TARGETARCH
118118

119119
WORKDIR /srv/app
120120

121-
# Download Caddy compiled with the Mercure and Vulcain modules
122-
ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy /usr/bin/caddy
121+
# Download Caddy compiled with the Mercure, Vulcain and Souin modules
122+
ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy&p=github.com/caddyserver/cache-handler /usr/bin/caddy
123123

124124
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
125125

api/config/packages/api_platform.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ api_platform:
99
graphql:
1010
graphql_playground: false
1111
mercure: ~
12+
http_cache:
13+
public: true
1214
defaults:
1315
stateless: true
1416
cache_headers:
@@ -28,6 +30,23 @@ api_platform:
2830
scopes:
2931
openid: (required) Indicates that the application intends to use OIDC to verify the user's identity
3032

33+
when@prod:
34+
parameters:
35+
# The api url that is called to invalidate cached resources
36+
# Can't be set in .env file cause it's only available on prod env
37+
env(SOUIN_API_URL): http://caddy/souin-api/souin
38+
39+
api_platform:
40+
http_cache:
41+
invalidation:
42+
enabled: true
43+
purger: 'api_platform.http_cache.purger.souin'
44+
urls: ['%env(SOUIN_API_URL)%']
45+
defaults:
46+
cache_headers:
47+
max_age: 0
48+
shared_max_age: 3600
49+
3150
services:
3251
app.filter.review.admin.search:
3352
class: 'ApiPlatform\Doctrine\Orm\Filter\SearchFilter'

api/docker/caddy/Caddyfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
# Debug
3-
{$CADDY_DEBUG}
2+
{$CADDY_GLOBAL_OPTIONS}
43
}
54

65
{$SERVER_NAME}
76

87
log
98

9+
{$CADDY_CACHE}
10+
1011
# Matches requests for OIDC routes
1112
@oidc expression path('/oidc/*')
1213

docker-compose.prod.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ services:
2727
environment:
2828
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
2929
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
30+
CADDY_GLOBAL_OPTIONS: |
31+
order cache before rewrite
32+
cache {
33+
api {
34+
souin
35+
}
36+
}
37+
CADDY_CACHE: cache
3038

3139
database:
3240
environment:

helm/api-platform/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data:
1313
mercure-url: "http://{{ include "api-platform.fullname" . }}/.well-known/mercure"
1414
mercure-public-url: {{ .Values.mercure.publicUrl | default "http://127.0.0.1/.well-known/mercure" | quote }}
1515
mercure-extra-directives: {{ .Values.mercure.extraDirectives | quote }}
16+
caddy-global-options: {{ .Values.caddy.globalOptions | quote }}
1617
oidc-server-url: "https://{{ (first .Values.ingress.hosts).host }}/oidc/realms/demo"
1718
oidc-server-url-internal: "http://{{ include "api-platform.fullname" . }}/oidc/realms/demo"
1819
next-auth-url: "https://{{ (first .Values.ingress.hosts).host }}/api/auth"

helm/api-platform/templates/deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ spec:
4040
value: {{ include "api-platform.fullname" . }}-pwa:3000
4141
- name: OIDC_UPSTREAM
4242
value: {{ .Release.Name }}-keycloak:80
43+
- name: CADDY_CACHE
44+
value: cache
45+
- name: CADDY_GLOBAL_OPTIONS
46+
valueFrom:
47+
configMapKeyRef:
48+
name: {{ include "api-platform.fullname" . }}
49+
key: caddy-global-options
4350
- name: MERCURE_EXTRA_DIRECTIVES
4451
valueFrom:
4552
configMapKeyRef:

helm/api-platform/values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ caddy:
3434
pullPolicy: IfNotPresent
3535
# Overrides the image tag whose default is the chart appVersion.
3636
tag: ""
37+
globalOptions: |
38+
order cache before rewrite
39+
cache {
40+
api {
41+
souin
42+
}
43+
}
3744
3845
# You may prefer using the managed version in production: https://mercure.rocks
3946
mercure:

0 commit comments

Comments
 (0)