diff --git a/.github/workflows/infrastructure.yaml b/.github/workflows/infrastructure.yaml index 7917ef9..e2f042d 100644 --- a/.github/workflows/infrastructure.yaml +++ b/.github/workflows/infrastructure.yaml @@ -78,6 +78,9 @@ jobs: - build-and-push-images steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Terraform validate and apply uses: ./.github/actions/terraform with: diff --git a/Makefile b/Makefile index 373cff8..aadf5fe 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ up: docker compose -f compose.nats.yaml --project-name nats up --pull always --detach docker compose -f compose.docker.yaml --project-name docker up --pull always --detach docker compose -f compose.docker_dashboard.yaml --project-name docker_dashboard up --pull always --detach - docker compose -f compose.proxy.yaml --project-name proxy up --pull always --detach + docker compose -f compose.proxy.yaml --project-name proxy up --pull always --detach --build down: docker compose -f compose.proxy.yaml --project-name proxy down --volumes --remove-orphans diff --git a/proxy/Dockerfile b/proxy/Dockerfile index 070ba3e..32c1165 100644 --- a/proxy/Dockerfile +++ b/proxy/Dockerfile @@ -1,5 +1,6 @@ -FROM nginx:1.26-alpine +FROM traefik:v3.3 -COPY ./nginx.conf /etc/nginx/conf.d/default.conf +COPY ./traefik.yml /etc/traefik/traefik.yml +COPY ./dynamic.yml /etc/traefik-dynamic/dynamic.yml -EXPOSE 80 +EXPOSE 80 8080 diff --git a/proxy/dynamic.yml b/proxy/dynamic.yml new file mode 100644 index 0000000..b227839 --- /dev/null +++ b/proxy/dynamic.yml @@ -0,0 +1,70 @@ +# HTTP routers, services, and middlewares +http: + routers: + + # Backend subdomain + backend: + rule: HostRegexp(`^backend\..+\..+$`) + entryPoints: + - http + service: app-service + middlewares: + - add-headers + + # Docker Dashboard subdomain + dockerdashboard: + rule: HostRegexp(`^dockerdashboard\..+\..+$`) + entryPoints: + - http + service: docker-dashboard-service + middlewares: + - add-headers + + # MongoDB Dashboard subdomain + mongodashboard: + rule: HostRegexp(`^mongodashboard\..+\..+$`) + entryPoints: + - http + service: mongodb-dashboard-service + middlewares: + - add-headers + + # Catch-all router for unmatched subdomains + catch-all: + rule: HostRegexp(`.+`) + entryPoints: + - http + service: frontend-service + middlewares: + - add-headers + + services: + frontend-service: + loadBalancer: + servers: + - url: "http://frontend:3000" + + app-service: + loadBalancer: + servers: + - url: "http://app:80" + + docker-dashboard-service: + loadBalancer: + servers: + - url: "http://docker_dashboard:9000" + + mongodb-dashboard-service: + loadBalancer: + servers: + - url: "http://mongodb_dashboard:8081" + + middlewares: + # Middleware to add headers to all requests + add-headers: + headers: + customRequestHeaders: + X-Real-IP: "{remote_ip}" + X-Forwarded-For: "{remote_ip}" + X-Forwarded-Proto: "{scheme}" + X-Forwarded-Host: "{host}" diff --git a/proxy/nginx.conf b/proxy/nginx.conf deleted file mode 100644 index 749055f..0000000 --- a/proxy/nginx.conf +++ /dev/null @@ -1,56 +0,0 @@ -# Server block to catch-all unmatched subdomains -server { - listen 80 default_server; - - server_name "_"; - - location / { - proxy_pass http://frontend:3000; - 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; - } -} - -# Server block for backend subdomain -server { - listen 80; - server_name "backend.*"; - - location / { - proxy_pass http://app:80; - 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; - } -} - -# Server block for dockerdashboard subdomain -server { - listen 80; - server_name "dockerdashboard.*"; - - location / { - proxy_pass http://docker_dashboard:9000; - 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; - } -} - -# Server block for mongodashboard subdomain -server { - listen 80; - server_name "mongodashboard.*"; - - location / { - proxy_pass http://mongodb_dashboard:8081; - 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; - } -} diff --git a/proxy/traefik.yml b/proxy/traefik.yml new file mode 100644 index 0000000..9ef0811 --- /dev/null +++ b/proxy/traefik.yml @@ -0,0 +1,19 @@ +# Define the entry points to listen on port 80 for HTTP +entryPoints: + http: + address: ":80" # Listen on port 80 for HTTP requests + +# Enable access logs +log: + level: DEBUG + format: common + filePath: "/dev/stdout" # Logs to stdout + +# Enable the Traefik dashboard (optional, for debugging purposes) +api: + insecure: true # Enable insecure dashboard (for local testing, don't use in production) + dashboard: true # Enable the dashboard view + +providers: + file: + directory: /etc/traefik-dynamic