diff --git a/.env.dist b/.env.dist index 3d49a9616..ee7e4e4d6 100644 --- a/.env.dist +++ b/.env.dist @@ -13,9 +13,9 @@ DJANGO_SUPERUSER_USERNAME=admin # do not use in production! DJANGO_SUPERUSER_PASSWORD=admin # do not use in production! DJANGO_SUPERUSER_EMAIL=mail@example.com # do not use in production! AML_LOCATION_PROVIDER=http://ip2country:5000/{} # address of the ip2country container, don't change -ALLOWED_HOSTS=localhost # needs to be changed when running in production +AML_ALLOWED_HOSTS="backend.muscle.local" # needs to be changed when running in production -REACT_APP_API_ROOT=http://localhost:8000 # address of the server, don't change +REACT_APP_API_ROOT=http://backend.muscle.local # address of the server, don't change REACT_APP_EXPERIMENT_SLUG=gmsi # experiment slug that the frontend redirects to REACT_APP_AML_HOME=https://www.amsterdammusiclab.nl # website you will be redirected to if you do not agree with an informed consent form REACT_APP_LOGO_URL= # optional: link to logo diff --git a/docker-compose.yaml b/docker-compose.yaml index 10cb61cb0..cae266f3a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,6 +27,13 @@ services: ports: - 8854:5000 server: + labels: + # Enables Traefik for the Django backend service, + # routes HTTP requests with the host 'backend.muscle.local' to this service, + # and sets 'web' as the (http, insecure) network entry point for these requests. + - "traefik.enable=true" + - "traefik.http.routers.server.rule=Host(`backend.muscle.local`)" + - "traefik.http.routers.server.entrypoints=web" build: context: ./backend dockerfile: DockerfileDevelop @@ -40,6 +47,7 @@ services: source: ./backend target: /server environment: + - AML_ALLOWED_HOSTS=${AML_ALLOWED_HOSTS} - AML_DEBUG=${AML_DEBUG} - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} - DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME} @@ -55,6 +63,13 @@ services: - 8000:8000 command: bash -c "python manage.py migrate && python manage.py bootstrap && python manage.py runserver 0.0.0.0:8000" client: + labels: + # Enables Traefik for the React frontend service, + # routes HTTP requests with the host 'muscle.local' to this service, + # and sets 'web' as the (http, insecure) network entry point for these requests. + - "traefik.enable=true" + - "traefik.http.routers.client.rule=Host(`muscle.local`)" + - "traefik.http.routers.client.entrypoints=web" build: context: ./frontend dockerfile: DockerfileDevelop @@ -85,6 +100,18 @@ services: ports: - 3000:3000 command: sh -c "yarn scss && yarn start" + traefik: + image: traefik:latest + command: + - "--api.insecure=true" + - "--providers.docker=true" + - "--providers.docker.exposedbydefault=false" + - "--entrypoints.web.address=:80" + ports: + - "80:80" + - "8080:8080" # Traefik dashboard + volumes: + - /var/run/docker.sock:/var/run/docker.sock volumes: db_data: db_backup: diff --git a/scripts/add-hosts-entries b/scripts/add-hosts-entries new file mode 100755 index 000000000..82ccbadb2 --- /dev/null +++ b/scripts/add-hosts-entries @@ -0,0 +1,27 @@ +#!/bin/bash + +# Define host entries +HOST_ENTRIES=( + "# MUSCLE" + "127.0.0.1 muscle.local" + "127.0.0.1 backend.muscle.local" + "# END MUSCLE" +) + +# Path to the hosts file +HOSTS_FILE="/etc/hosts" + +# Function to add an entry if it doesn't exist +add_host_entry() { + local entry=$1 + if ! grep -q "$entry" "$HOSTS_FILE"; then + echo "$entry" | sudo tee -a "$HOSTS_FILE" + else + echo "Entry already exists: $entry" + fi +} + +# Add each host entry +for entry in "${HOST_ENTRIES[@]}"; do + add_host_entry "$entry" +done