Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config (Traefik): Configure a Traefik reverse proxy Docker container to use muscle.local and backend.muscle.local domains #717

Merged
merged 6 commits into from
Jan 23, 2024

Conversation

drikusroor
Copy link
Contributor

@drikusroor drikusroor commented Jan 17, 2024

Not sure if we want this, but during yesterday's demo session I heard some people talking about not remembering the urls and port numbers to use for the application and the backend. This PR adds a Traefik container that reroutes http://localhost:3000 and http://localhost:8000 to http://muscle.local and http://backend.muscle.local, which is easier to remember (and of course you can also just type muscle.local and backend.muscle.local).

Additionally, it adds a idempotent script (./scripts/add-hosts-entries) to add the hostnames to the hostfile in /etc/hosts file, which is required Traefik to work.

@drikusroor drikusroor self-assigned this Jan 17, 2024
Copy link
Collaborator

@BeritJanssen BeritJanssen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Perhaps just "muscle" (instead of "muscle.local") might even do? Just for my understanding: where does the actual mapping of the routes to the relevant localhost ports happen? Is it in the add-hosts-entries script? I worry that the port mappings are not explicit now, so it might be a bit hocus-pocus to future developers.

@drikusroor
Copy link
Contributor Author

Nice! Perhaps just "muscle" (instead of "muscle.local") might even do? Just for my understanding: where does the actual mapping of the routes to the relevant localhost ports happen? Is it in the add-hosts-entries script? I worry that the port mappings are not explicit now, so it might be a bit hocus-pocus to future developers.

That happens in the Traefik container (see the docker-compose.yml configuration). Traefik functions as a reverse proxy here. The add-hosts-entries script only maps the domains to 127.0.0.1. As Traefik runs on port 80 it will be hit when you send requests to 127.0.0.1 and then proxy it internally:

muscle.local => 127.0.0.1(:80) (Traefik) => localhost:8000

The only thing I'm still thinking about is how to execute the add-hosts-entries script together with docker compose up (-d --build) so that the hosts will always be up to date with the Traefik configuration.

@BeritJanssen
Copy link
Collaborator

Perhaps add some comments to the docker-compose then to explain what the traefik settings do?

@drikusroor drikusroor merged commit a9111d9 into develop Jan 23, 2024
10 checks passed
@drikusroor drikusroor deleted the config/traefik branch January 23, 2024 14:27
@drikusroor
Copy link
Contributor Author

Nice! Perhaps just "muscle" (instead of "muscle.local") might even do? Just for my understanding: where does the actual mapping of the routes to the relevant localhost ports happen? Is it in the add-hosts-entries script? I worry that the port mappings are not explicit now, so it might be a bit hocus-pocus to future developers.

I don't think the port mappings are that important. Traefik communicates with Docker and simply proxies to that specific Docker service. What might be interesting to check is to start up the newly added Traefik container (I just merged the PR) and navigate to http://localhost:8080, which is the backend interface of Traefik that shows you how the different services, load balancers, etc. are currently configured.

Also, I've added some explanation to the Wiki of how to start up the Development environment: https://github.com/Amsterdam-Music-Lab/MUSCLE/wiki/2.-Start-the-application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants