From 6bc3337a8f750bc621f71528d9fdf1e18570dc8e Mon Sep 17 00:00:00 2001 From: IsaacDSC Date: Sun, 8 Mar 2026 10:57:52 -0300 Subject: [PATCH 1/3] feat: add Nginx service and configuration for API routing - Introduced a new Nginx service in the Docker Compose setup to handle API requests. - Configured Nginx with a custom configuration file to route requests to the appropriate backend services (pubsub, task, backoffice). - Added a script to reload or restart the Nginx container as needed. - Updated example API endpoints to reflect the new Nginx routing on port 8080. --- deployment/app-pgsql/docker-compose.yaml | 28 +++++++++ deployment/app-pgsql/nginx/nginx.conf | 58 +++++++++++++++++++ deployment/app-pgsql/reload-nginx.sh | 18 ++++++ example/example.md | 6 +- .../simulation/multiples_producer_pubsub.sh | 2 +- 5 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 deployment/app-pgsql/nginx/nginx.conf create mode 100755 deployment/app-pgsql/reload-nginx.sh diff --git a/deployment/app-pgsql/docker-compose.yaml b/deployment/app-pgsql/docker-compose.yaml index 2f62d43..dd16e38 100644 --- a/deployment/app-pgsql/docker-compose.yaml +++ b/deployment/app-pgsql/docker-compose.yaml @@ -138,6 +138,34 @@ services: - gqueue - observability + nginx: + image: nginx:alpine + ports: + - 8080:80 + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + backoffice: + condition: service_started + pubsub: + condition: service_started + task: + condition: service_started + networks: + - app-network + deploy: + resources: + limits: + cpus: "0.5" + memory: 128M + reservations: + cpus: "0.1" + memory: 64M + profiles: + - complete + - gqueue + - observability + redis: image: redis:latest ports: diff --git a/deployment/app-pgsql/nginx/nginx.conf b/deployment/app-pgsql/nginx/nginx.conf new file mode 100644 index 0000000..b5bdba4 --- /dev/null +++ b/deployment/app-pgsql/nginx/nginx.conf @@ -0,0 +1,58 @@ +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /tmp/nginx.pid; + +events { + worker_connections 1024; +} + +http { + 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; + types_hash_max_size 2048; + + limit_req_zone $binary_remote_addr zone=api:10m rate=2000r/s; + + server { + listen 80; + server_name _; + client_max_body_size 1m; + + # Common proxy settings (inherited by locations); path is passed through unchanged + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # Prefix routing: most specific first. No path rewrite — backend receives full URI. + location /api/v1/pubsub { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://pubsub:8082; + } + + location /api/v1/task { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://task:8083; + } + + location /api/v1/ { + limit_req zone=api burst=1000 nodelay; + proxy_pass http://backoffice:8081; + } + + location / { + return 404; + } + } +} diff --git a/deployment/app-pgsql/reload-nginx.sh b/deployment/app-pgsql/reload-nginx.sh new file mode 100755 index 0000000..cbb0f72 --- /dev/null +++ b/deployment/app-pgsql/reload-nginx.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Run from repo root or from deployment/app-pgsql. +# Reloads nginx config or restarts the container so changes to nginx.conf take effect. + +set -e +cd "$(dirname "$0")" + +PROFILE="${1:-gqueue}" + +echo "Using profile: $PROFILE" +echo "Reloading nginx config..." +if docker compose --profile "$PROFILE" exec nginx nginx -s reload 2>/dev/null; then + echo "Nginx reloaded." +else + echo "Reload failed (container may not be running). Restarting nginx container..." + docker compose --profile "$PROFILE" up -d --force-recreate nginx + echo "Nginx restarted." +fi diff --git a/example/example.md b/example/example.md index 961c704..1b8f993 100644 --- a/example/example.md +++ b/example/example.md @@ -1,7 +1,7 @@ ### Example create or update event curl -X PATCH \ - http://localhost:8081/api/v1/event/consumer \ + http://localhost:8080/api/v1/event/consumer \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ @@ -11,11 +11,11 @@ curl -X PATCH \ curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ - http://localhost:8081/api/v1/events/payment.charged1 | jq + http://localhost:8080/api/v1/events/payment.charged1 | jq curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ - http://localhost:8081/api/v1/events + http://localhost:8080/api/v1/events curl -X GET \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ diff --git a/example/simulation/multiples_producer_pubsub.sh b/example/simulation/multiples_producer_pubsub.sh index 502179a..5b89b67 100644 --- a/example/simulation/multiples_producer_pubsub.sh +++ b/example/simulation/multiples_producer_pubsub.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -URL="http://localhost:8082/api/v1/pubsub" +URL="http://localhost:8080/api/v1/pubsub" AUTH="Basic YWRtaW46cGFzc3dvcmQ=" DATA_FILE="example/pubsub_event_payload.json" From 1697b6a8528316193bdf72121fbb1e1e677dc423 Mon Sep 17 00:00:00 2001 From: IsaacDSC Date: Mon, 9 Mar 2026 08:56:16 -0300 Subject: [PATCH 2/3] fix: update API endpoint URLs to reflect Nginx routing changes - Changed the API endpoint URLs in example.md and multiples_producer_task.sh from port 8083 to 8080 to align with the new Nginx configuration for API routing. - Ensured consistency across documentation and simulation scripts for proper API interaction. --- example/example.md | 4 ++-- example/simulation/multiples_producer_task.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/example.md b/example/example.md index 1b8f993..03b90ac 100644 --- a/example/example.md +++ b/example/example.md @@ -24,13 +24,13 @@ curl -X GET \ ### Publisher data curl -X POST \ - http://localhost:8082/api/v1/pubsub \ + http://localhost:8080/api/v1/pubsub \ -H "Content-Type: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ -d @example/pubsub_event_payload.json curl -X POST \ - http://localhost:8083/api/v1/task \ + http://localhost:8080/api/v1/task \ -H "Content-Type: application/json" \ -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \ -d @example/task_event_payload.json diff --git a/example/simulation/multiples_producer_task.sh b/example/simulation/multiples_producer_task.sh index f3c45aa..1ff1333 100644 --- a/example/simulation/multiples_producer_task.sh +++ b/example/simulation/multiples_producer_task.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -URL="http://localhost:8083/api/v1/task" +URL="http://localhost:8080/api/v1/task" AUTH="Basic YWRtaW46cGFzc3dvcmQ=" DATA_FILE="example/task_event_payload.json" From 5a36f80a30d6d8e07c8e1f1a01d54ac94b6d760d Mon Sep 17 00:00:00 2001 From: IsaacDSC Date: Mon, 9 Mar 2026 12:33:01 -0300 Subject: [PATCH 3/3] chore: remove reload-nginx.sh script as it is no longer needed - Deleted the reload-nginx.sh script which was used to reload or restart the Nginx container. This change reflects the recent updates to the Nginx service configuration and streamlines the deployment process. --- deployment/app-pgsql/reload-nginx.sh | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100755 deployment/app-pgsql/reload-nginx.sh diff --git a/deployment/app-pgsql/reload-nginx.sh b/deployment/app-pgsql/reload-nginx.sh deleted file mode 100755 index cbb0f72..0000000 --- a/deployment/app-pgsql/reload-nginx.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Run from repo root or from deployment/app-pgsql. -# Reloads nginx config or restarts the container so changes to nginx.conf take effect. - -set -e -cd "$(dirname "$0")" - -PROFILE="${1:-gqueue}" - -echo "Using profile: $PROFILE" -echo "Reloading nginx config..." -if docker compose --profile "$PROFILE" exec nginx nginx -s reload 2>/dev/null; then - echo "Nginx reloaded." -else - echo "Reload failed (container may not be running). Restarting nginx container..." - docker compose --profile "$PROFILE" up -d --force-recreate nginx - echo "Nginx restarted." -fi