diff --git a/.github/workflows/infrastructure.yaml b/.github/workflows/infrastructure.yaml index 7917ef9..67a522a 100644 --- a/.github/workflows/infrastructure.yaml +++ b/.github/workflows/infrastructure.yaml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v4 - name: Terraform validate and apply - uses: ./.github/actions/terraform + uses: ../.github/actions/terraform with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -31,7 +31,7 @@ jobs: apply: true - name: Build image - uses: ./.github/actions/docker-build + uses: ../.github/actions/docker-build with: context: ./proxy dockerfile: ./proxy/Dockerfile @@ -56,7 +56,7 @@ jobs: uses: actions/checkout@v4 - name: Build and push proxy image - uses: ./.github/actions/docker-build + uses: ../.github/actions/docker-build with: context: ./proxy dockerfile: ./proxy/Dockerfile @@ -79,7 +79,7 @@ jobs: steps: - name: Terraform validate and apply - uses: ./.github/actions/terraform + uses: ../.github/actions/terraform with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/proxy/Dockerfile b/proxy/Dockerfile index 070ba3e..66592e8 100644 --- a/proxy/Dockerfile +++ b/proxy/Dockerfile @@ -1,5 +1,5 @@ -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 EXPOSE 80 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..88cd73c --- /dev/null +++ b/proxy/traefik.yml @@ -0,0 +1,70 @@ +http: + routers: + # Catch-all router for unmatched subdomains + catch-all: + rule: "HostRegexp(`{subdomain:[a-z0-9-]+}.*`)" + entryPoints: + - web + service: frontend-service + middlewares: + - headers + + # Backend subdomain + backend: + rule: "Host(`backend.{subdomain:[a-z0-9-]+}.*`)" + entryPoints: + - web + service: app-service + middlewares: + - headers + + # Docker Dashboard subdomain + dockerdashboard: + rule: "Host(`dockerdashboard.{subdomain:[a-z0-9-]+}.*`)" + entryPoints: + - web + service: docker-dashboard-service + middlewares: + - headers + + # MongoDB Dashboard subdomain + mongodashboard: + rule: "Host(`mongodashboard.{subdomain:[a-z0-9-]+}.*`)" + entryPoints: + - web + service: mongodb-dashboard-service + middlewares: + - 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: + headers: + headers: + customRequestHeaders: + X-Real-IP: "{remote_ip}" + X-Forwarded-For: "{remote_ip}" + X-Forwarded-Proto: "{scheme}" + +entryPoints: + web: + address: ":80"