diff --git a/docker/docker-compose-separate-msl-api.yml b/docker/docker-compose-separate-msl-api.yml index 8d4b4d5..98303ff 100644 --- a/docker/docker-compose-separate-msl-api.yml +++ b/docker/docker-compose-separate-msl-api.yml @@ -16,6 +16,7 @@ volumes: nginx_certificates: mslapi_signal: mslapi_storage: + ckan_api_key: services: ckan: @@ -38,6 +39,7 @@ services: - CKAN_SITE_URL=${CKAN_SITE_URL} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: + - ckan_api_key:/ckan_api_key - ckan_config:/etc/ckan - ckan_home:/usr/lib/ckan - ckan_storage:/var/lib/ckan @@ -78,6 +80,7 @@ services: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MSLAPI_ROLE=WEBSERVER volumes: + - ckan_api_key:/ckan_api_key - mslapi_signal:/signal - mslapi_storage:/storage @@ -88,6 +91,7 @@ services: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MSLAPI_ROLE=QUEUE_WORKER volumes: + - ckan_api_key:/ckan_api_key - mslapi_signal:/signal - mslapi_storage:/storage diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 50ebd5e..de344bf 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -16,6 +16,7 @@ volumes: nginx_certificates: mslapi_signal: mslapi_storage: + ckan_api_key: services: ckan: @@ -38,6 +39,7 @@ services: - CKAN_SITE_URL=${CKAN_SITE_URL} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: + - ckan_api_key:/ckan_api_key - ckan_config:/etc/ckan - ckan_home:/usr/lib/ckan - ckan_storage:/var/lib/ckan @@ -80,6 +82,7 @@ services: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MSLAPI_ROLE=BOTH volumes: + - ckan_api_key:/ckan_api_key - mslapi_signal:/signal - mslapi_storage:/storage diff --git a/docker/images/ckan/Dockerfile b/docker/images/ckan/Dockerfile index b9a8ef9..e758350 100644 --- a/docker/images/ckan/Dockerfile +++ b/docker/images/ckan/Dockerfile @@ -46,6 +46,7 @@ RUN apt-get -q -y update \ sqlite3 \ pwgen \ uuid-runtime \ + sudo \ && apt-get -q clean \ && rm -rf /var/lib/apt/lists/* @@ -80,6 +81,7 @@ ADD ckan-uwsgi.ini /etc/ckan/default/ckan-uwsgi.ini ENV PATH=${CKAN_VENV}/bin:${PATH} ENV EPOS_MSL_FQDN=epos-msl.local ENV CKAN_ADMIN_PASSWORD="testtest" +ENV CKAN_MSLAPI_PASSWORD="testtest" # Install CKAN and plugins RUN ckan-pip3 install -U pip && \ @@ -103,7 +105,7 @@ ADD ./ckan-entrypoint.sh /ckan-entrypoint.sh ENTRYPOINT ["/ckan-entrypoint.sh"] RUN chmod +x /ckan-entrypoint.sh -USER ckan +USER root EXPOSE 8080 CMD ["/ckan-entrypoint.sh"] diff --git a/docker/images/ckan/ckan-entrypoint.sh b/docker/images/ckan/ckan-entrypoint.sh index 580e5f5..b54c7db 100644 --- a/docker/images/ckan/ckan-entrypoint.sh +++ b/docker/images/ckan/ckan-entrypoint.sh @@ -53,7 +53,11 @@ else echo "Initializing configuration ..." echo "Initializing database ..." /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" db init /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" user add ckanadmin password="$CKAN_ADMIN_PASSWORD" email=ckanadmin@localhost name=ckanadmin + /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" user add mslapi password="$CKAN_MSLAPI_PASSWORD" email=mslapi@localhost name=mslapi /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" sysadmin add ckanadmin + /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" sysadmin add mslapi + sudo chown ckan /ckan_api_key + /usr/lib/ckan/default/bin/ckan -c "$CKAN_CONFIG_FILE" user token add mslapi mslapi | tail -1 | sed 's/^\t//' > /ckan_api_key/api.key touch "$CKAN_INIT_STATUS_FILE" echo "Configuration and database initialization finished." fi diff --git a/docker/images/msl-api/msl-api-entrypoint.sh b/docker/images/msl-api/msl-api-entrypoint.sh index dbe560c..ec7c88d 100644 --- a/docker/images/msl-api/msl-api-entrypoint.sh +++ b/docker/images/msl-api/msl-api-entrypoint.sh @@ -40,6 +40,17 @@ CREATE USER 'msl'@'%' IDENTIFIED BY 'msl'; GRANT ALL PRIVILEGES ON mslapi.* TO 'msl'@'%'; FLUSH PRIVILEGES; " + + # Wait until CKAN API key has been generated, then + # add it to the config. + CKAN_API_KEY_FILE="/ckan_api_key/api.key" + while ! [ -f "$CKAN_API_KEY_FILE" ] + do echo "Waiting for CKAN API key to be available ..." + sleep 1 + done + export CKAN_API_KEY=$(cat "$CKAN_API_KEY_FILE") + perl -pi.bak -e '$ckan_api_key=$ENV{CKAN_API_KEY}; s/PUT_API_TOKEN_HERE/"$ckan_api_key"/ge' "/var/www/msl_api/.env" + cd /var/www/msl_api # Initialize the MSL-API application set -x