Skip to content

Commit

Permalink
Docker setup: extract host parameters
Browse files Browse the repository at this point in the history
Extract parameters for external host IP and port, and ensure
hostname/IP/port settings are used correctly in all components.
  • Loading branch information
stsnel committed Jan 12, 2025
1 parent 4c2e9ab commit 7c8f3f7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# Image: ckan
CKAN_SITE_ID=default

# Hostname, IP address and port of the catalog
EPOS_MSL_HOST=epos-msl.ckan
EPOS_MSL_HOST_IP=127.0.0.1
EPOS_MSL_HOST_PORT=18443

#
# On AWS, your CKAN_SITE_URL is the output of:
# curl -s http://169.254.169.254/latest/meta-data/public-hostname
Expand Down
7 changes: 6 additions & 1 deletion docker/docker-compose-separate-msl-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ services:
image: ghcr.io/utrechtuniversity/epos-msl-cat-nginx:latest
environment:
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
- EPOS_MSL_HOST_PORT=${EPOS_MSL_HOST_PORT}
ports:
- "18443:443"
- "${EPOS_MSL_HOST_IP}:${EPOS_MSL_HOST_PORT}:443"
volumes:
- nginx_config:/etc/nginx/conf.d
- nginx_certificates:/etc/certificates
Expand Down Expand Up @@ -80,6 +81,8 @@ services:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=WEBSERVER
- FAST_API_TOKEN=${FAST_API_TOKEN}
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
- EPOS_MSL_HOST_PORT=${EPOS_MSL_HOST_PORT}
ports:
- "80"
volumes:
Expand All @@ -94,6 +97,8 @@ services:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=QUEUE_WORKER
- FAST_API_TOKEN=${FAST_API_TOKEN}
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
- EPOS_MSL_HOST_PORT=${EPOS_MSL_HOST_PORT}
volumes:
- ckan_api_key:/ckan_api_key
- mslapi_signal:/signal
Expand Down
5 changes: 4 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ services:
image: ghcr.io/utrechtuniversity/epos-msl-cat-nginx:latest
environment:
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
- EPOS_MSL_HOST_PORT=${EPOS_MSL_HOST_PORT}
ports:
- "18443:443"
- "${EPOS_MSL_HOST_IP}:${EPOS_MSL_HOST_PORT}:443"
volumes:
- nginx_config:/etc/nginx/conf.d
- nginx_certificates:/etc/certificates
Expand Down Expand Up @@ -83,6 +84,8 @@ services:
environment:
- FAST_API_TOKEN=${FAST_API_TOKEN}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
- EPOS_MSL_HOST_PORT=${EPOS_MSL_HOST_PORT}
- MSLAPI_ROLE=BOTH
volumes:
- ckan_api_key:/ckan_api_key
Expand Down
8 changes: 8 additions & 0 deletions docker/images/msl-api/msl-api-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ FLUSH PRIVILEGES;
# Also configure the FAST-API key, which is passed via an environment variable
perl -pi.bak -e '$fast_api_token=$ENV{FAST_API_TOKEN}; s/PUT_FASTAPI_TOKEN_HERE/"$fast_api_token"/ge' "/var/www/msl_api/.env"

# Configure App and and asset URL
if [ "$EPOS_MSL_HOST_PORT" -eq "443" ]
then export APP_ASSET_URL="https://${EPOS_MSL_HOST}"
else export APP_ASSET_URL="https://${EPOS_MSL_HOST}:${EPOS_MSL_HOST_PORT}"
fi
perl -pi.bak -e '$app_url=$ENV{APP_ASSET_URL}; s/PUT_APP_URL_HERE/"$app_url"/ge' "/var/www/msl_api/.env"
perl -pi.bak -e '$asset_url=$ENV{APP_ASSET_URL}; s/PUT_ASSET_URL_HERE/"$asset_url"/ge' "/var/www/msl_api/.env"

cd /var/www/msl_api
# Initialize the MSL-API application
set -x
Expand Down
4 changes: 2 additions & 2 deletions docker/images/msl-api/msl-api.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ APP_KEY=
APP_NAME=MSL
APP_ENV=production
APP_DEBUG=false
APP_URL=https://epos-msl.ckan:18443
ASSET_URL=https://epos-msl.ckan:18443
APP_URL=PUT_APP_URL_HERE
ASSET_URL=PUT_ASSET_URL_HERE

LOG_CHANNEL=stack
LOG_LEVEL=debug
Expand Down
2 changes: 1 addition & 1 deletion docker/images/nginx/ckan.site
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ server {

location / {
proxy_pass http://mslapi_webserver:80/;
proxy_set_header Host $host:18443;
proxy_set_header Host PUT_HOST_HEADER_HERE;
proxy_set_header X-Forwarded-Proto https;
proxy_cache cache;
proxy_cache_bypass $cookie_auth_tkt;
Expand Down
7 changes: 7 additions & 0 deletions docker/images/nginx/nginx-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ else echo "Generating DHParam configuration..."
echo "DHParam generation complete."
fi

# Configure host header for reverse proxy
if [ "$EPOS_MSL_HOST_PORT" -eq "443" ]
then export HOST_HEADER="${EPOS_MSL_HOST}"
else export HOST_HEADER="${EPOS_MSL_HOST}:${EPOS_MSL_HOST_PORT}"
fi
perl -pi.bak -e '$host_header=$ENV{HOST_HEADER}; s/PUT_HOST_HEADER_HERE/"$host_header"/ge' "/etc/nginx/conf.d/ckan.conf"

## Run Nginx
nginx -g "daemon off;"

0 comments on commit 7c8f3f7

Please sign in to comment.