Skip to content

Commit

Permalink
YDA-6048: automatically load CKAN API key
Browse files Browse the repository at this point in the history
Automatically create CKAN API key, and load it into
the configuration of MSL-API.
  • Loading branch information
stsnel committed Dec 19, 2024
1 parent 4a334a0 commit 458d325
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docker/docker-compose-separate-msl-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ volumes:
nginx_certificates:
mslapi_signal:
mslapi_storage:
ckan_api_key:

services:
ckan:
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ volumes:
nginx_certificates:
mslapi_signal:
mslapi_storage:
ckan_api_key:

services:
ckan:
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion docker/images/ckan/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down Expand Up @@ -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 && \
Expand All @@ -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"]
4 changes: 4 additions & 0 deletions docker/images/ckan/ckan-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docker/images/msl-api/msl-api-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 458d325

Please sign in to comment.