Skip to content

Commit

Permalink
switch to traefik
Browse files Browse the repository at this point in the history
  • Loading branch information
khanzadimahdi committed Jan 10, 2025
1 parent 24c1572 commit 3951411
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
70 changes: 70 additions & 0 deletions proxy/dynamic.yml
Original file line number Diff line number Diff line change
@@ -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}"
56 changes: 0 additions & 56 deletions proxy/nginx.conf

This file was deleted.

19 changes: 19 additions & 0 deletions proxy/traefik.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3951411

Please sign in to comment.