Skip to content

Commit

Permalink
feat: add Souin
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Aug 24, 2023
1 parent ae6daab commit 02e5026
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/.env
Expand Up @@ -19,6 +19,8 @@ TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
TRUSTED_HOSTS=^(localhost|caddy)$
OIDC_SERVER_URL=https://localhost/oidc/realms/demo
OIDC_SWAGGER_CLIENT_ID=api-platform-swagger
# The api url that is called to invalidate cached resources
SOUIN_API_URL=http://caddy/souin-api/souin

###> symfony/framework-bundle ###
APP_ENV=dev
Expand Down
2 changes: 1 addition & 1 deletion api/Dockerfile
Expand Up @@ -119,7 +119,7 @@ ARG TARGETARCH
WORKDIR /srv/app

# Download Caddy compiled with the Mercure and Vulcain modules
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
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

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

Expand Down
8 changes: 8 additions & 0 deletions api/config/packages/api_platform.yaml
Expand Up @@ -9,9 +9,17 @@ api_platform:
graphql:
graphql_playground: false
mercure: ~
http_cache:
public: true
invalidation:
enabled: true
purger: 'api_platform.http_cache.purger.souin'
urls: ['%env(SOUIN_API_URL)%']
defaults:
stateless: true
cache_headers:
max_age: 0
shared_max_age: 3600
vary: ['Content-Type', 'Authorization', 'Origin']
extra_properties:
standard_put: true
Expand Down
8 changes: 8 additions & 0 deletions api/docker/caddy/Caddyfile
@@ -1,12 +1,20 @@
{
# Debug
{$CADDY_DEBUG}
order cache before rewrite
cache {
api {
souin
}
}
}

{$SERVER_NAME}

log

{$CADDY_CACHE}

# Matches requests for OIDC routes
@oidc expression path('/oidc/*')

Expand Down
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Expand Up @@ -27,6 +27,7 @@ services:
environment:
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
CADDY_CACHE: cache

database:
environment:
Expand Down

0 comments on commit 02e5026

Please sign in to comment.