Skip to content

Commit

Permalink
seperate frankenphp from ingress for local development
Browse files Browse the repository at this point in the history
That we have a more similar setup in development as in prod.

Issue: ecamp#5277
  • Loading branch information
BacLuc committed Jul 17, 2024
1 parent 0e94430 commit f487275
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 42 deletions.
29 changes: 1 addition & 28 deletions api/docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
debug
{$CADDY_GLOBAL_OPTIONS}

frankenphp {
Expand All @@ -22,34 +23,6 @@

{$CADDY_EXTRA_CONFIG}

:3000 {
log {
level DEBUG
}

handle_path /api* {
# rewriting the uri used for php-fcgi did not work
# so we make a hop more to localhost:3001 with the rewritten url where the fcgi happens
# this may slow down the request

reverse_proxy localhost:3001 {
header_up X-Forwarded-Prefix "/api"
}
}

handle /print* {
reverse_proxy print:3003
}

handle /mail* {
reverse_proxy mail:1080
}

handle {
reverse_proxy frontend:3000
}
}

:3001 {
route {
root * /app/public
Expand Down
2 changes: 1 addition & 1 deletion api/docker/varnish/vcl/_config.vcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
backend default {
.host = "api";
.port = "3000";
.port = "3001";
}
6 changes: 0 additions & 6 deletions api/docker/varnish/vcl/default.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ sub vcl_recv {
# Support xkey purge requests
# see https://raw.githubusercontent.com/varnish/varnish-modules/master/src/vmod_xkey.vcc
call fos_tags_xkey_recv;

# exclude other services (frontend, print, etc.)
if (var.get("originalUrl") !~ "^/api") {
return(pass);
}

# exclude API documentation, profiler and graphql endpoint
if (var.get("originalUrl") ~ "^/api/docs"
Expand Down Expand Up @@ -100,4 +95,3 @@ sub vcl_deliver {
set resp.http.Cache-Control = "no-cache, private";
}
}

31 changes: 24 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ services:
- database
- docker-host
ports:
- target: 3000
published: 3000
protocol: tcp
- target: 2019
published: 2019
protocol: tcp
Expand Down Expand Up @@ -81,10 +78,6 @@ services:
- api
volumes:
- ./api/docker/varnish/vcl/:/etc/varnish/:ro
ports:
- target: 8080
published: 3004
protocol: tcp
command: -a :8081,HTTP -p http_max_hdr=96
environment:
- COOKIE_PREFIX=localhost_
Expand Down Expand Up @@ -192,6 +185,30 @@ services:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
network_mode: host
working_dir: /e2e

reverse-proxy:
image: nginx:1.26
container_name: 'ecamp3-reverse-proxy'
volumes:
- ./reverse-proxy-nginx.conf:/etc/nginx/nginx.conf
depends_on:
frontend:
condition: service_started
api:
condition: service_healthy
mail:
condition: service_started
print:
condition: service_started
http-cache:
condition: service_started
ports:
- target: 3000
published: 3000
protocol: tcp
- target: 3004
published: 3004
protocol: tcp

translation:
image: node:22.4.1
Expand Down
70 changes: 70 additions & 0 deletions reverse-proxy-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
resolver 127.0.0.11;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 3000;
server_name localhost;

location / {
proxy_pass http://frontend:3000;
}

location /api/ {
# the Set-Cookie: XDEBUG_SESSION=PHPSTORM; path=/; SameSite=Lax header is set too many times
# temporary workaround from https://stackoverflow.com/a/27551259
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_set_header X-Forwarded-Prefix /api;
proxy_pass http://api:3001/;
}

location /print {
proxy_pass http://print:3003;
}

location /mail {
proxy_pass http://mail:1080;
}
}
server {
listen 3004;
server_name localhost;

location / {
proxy_pass http://frontend:3000;
}

location /api/ {
# the Set-Cookie: XDEBUG_SESSION=PHPSTORM; path=/; SameSite=Lax header is set too many times
# temporary workaround from https://stackoverflow.com/a/27551259
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_set_header X-Forwarded-Prefix /api;
proxy_pass http://http-cache:8080/;
}

location /print {
proxy_pass http://print:3003;
}

location /mail {
proxy_pass http://mail:1080;
}
}
}

0 comments on commit f487275

Please sign in to comment.