Skip to content

Commit

Permalink
YDA-6001: run MSL-API worker / web in 1 container
Browse files Browse the repository at this point in the history
Run the MSL-API queue worker and web server in a single container
by default, for ease of development. Retain an alternative setup
with separate containers.
  • Loading branch information
stsnel committed Nov 25, 2024
1 parent 50bde74 commit 45ad927
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 17 deletions.
102 changes: 102 additions & 0 deletions docker/docker-compose-separate-msl-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This is a locally modified version of the upstream CKAN docker compose file.
#
# This version runs two separate containers for MSL-API (one for the web server and
# one for the queue worker)

version: "3"

volumes:
ckan_config:
ckan_home:
ckan_storage:
ckan_coveragedata:
pg_data:
solr_data:
nginx_config:
nginx_certificates:
mslapi_signal:
mslapi_storage:

services:
ckan:
container_name: ckan
image: epos-msl-ckan:latest
links:
- db
- solr
- redis
depends_on:
- db
- solr
- redis
ports:
- "0.0.0.0:${CKAN_PORT}:5000"
environment:
- CKAN_SQLALCHEMY_URL=postgresql://ckan:${POSTGRES_PASSWORD}@db/ckan_default
- CKAN_SOLR_URL=http://solr:8983/solr/ckan
- CKAN_REDIS_URL=redis://redis:6379/1
- CKAN_SITE_URL=${CKAN_SITE_URL}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- ckan_config:/etc/ckan
- ckan_home:/usr/lib/ckan
- ckan_storage:/var/lib/ckan
- ckan_coveragedata:/coverage

nginx:
container_name: nginx
image: epos-msl-nginx:latest
environment:
- EPOS_MSL_HOST=${EPOS_MSL_HOST}
ports:
- "18443:443"
volumes:
- nginx_config:/etc/nginx/conf.d
- nginx_certificates:/etc/certificates

db:
container_name: db
image: postgres:12.20
environment:
- POSTGRES_DB=ckan_default
- POSTGRES_USER=ckan
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PGDATA=/var/lib/postgresql/data/db
volumes:
- pg_data:/var/lib/postgresql/data

mslapi_db:
container_name: mslapi_db
image: mysql:8.0.39-debian
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}

mslapi_webserver:
container_name: mslapi_web
image: epos-msl-api:latest
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=WEBSERVER
volumes:
- mslapi_signal:/signal
- mslapi_storage:/storage

mslapi_worker:
container_name: mslapi_worker
image: epos-msl-api:latest
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=QUEUE_WORKER
volumes:
- mslapi_signal:/signal
- mslapi_storage:/storage

solr:
container_name: solr
image: epos-msl-solr:latest
volumes:
- solr_data:/opt/solr/server/solr/ckan/data

redis:
container_name: redis
image: redis:6.2
20 changes: 6 additions & 14 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This is a locally modified version of the upstream CKAN docker compose file.
# It contains image names for pushing locally built images to a central registry at ECR
#
# This default version runs the MSL-API web server and queue worker in the same
# container.

# docker-compose build && docker-compose up -d
# If "docker-compose logs ckan" shows DB not ready, run "docker-compose restart ckan" a few times.
version: "3"

volumes:
Expand Down Expand Up @@ -71,22 +71,14 @@ services:
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}

# In this Docker Compose setup, the web server container runs both
# the MSL-API web application and the queue worker.
mslapi_webserver:
container_name: mslapi_web
image: epos-msl-api:latest
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=WEBSERVER
volumes:
- mslapi_signal:/signal
- mslapi_storage:/storage

mslapi_worker:
container_name: mslapi_worker
image: epos-msl-api:latest
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MSLAPI_ROLE=QUEUE_WORKER
- MSLAPI_ROLE=BOTH
volumes:
- mslapi_signal:/signal
- mslapi_storage:/storage
Expand Down
9 changes: 7 additions & 2 deletions docker/images/msl-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ RUN apt-get -q -y update \
php8.0-xml \
php8.0-zip \
mysql-client \
supervisor \
&& apt-get -q clean \
&& rm -rf /var/lib/apt/lists/* \
&& wget "https://getcomposer.org/download/$COMPOSER_VERSION/composer.phar" \
-O /usr/local/bin/composer2

ADD msl-api.site /etc/nginx/conf.d/msl-api.conf
ADD msl-api.site /etc/nginx/sites-enabled/msl-api
RUN rm /etc/nginx/sites-enabled/default

ADD msl-api-entrypoint.sh /msl-api-entrypoint.sh
RUN chmod +x /msl-api-entrypoint.sh
Expand All @@ -57,8 +59,11 @@ RUN cd /var/www && \
chown -R www-data:www-data msl_api
USER www-data
ADD msl-api.env /var/www/msl_api/.env
ADD supervisord.conf /etc/supervisor/conf.d/mslapi.conf
RUN cd /var/www/msl_api && \
/usr/bin/php8.0 /usr/local/bin/composer2 install

USER root
RUN chown www-data /var/www/msl_api/.env && \
chmod 0664 /var/www/msl_api/.env

CMD ["/msl-api-entrypoint.sh"]
5 changes: 4 additions & 1 deletion docker/images/msl-api/msl-api-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SIGNALFILE="/signal/mslapi_initialized.sig"
if [ -f "$SIGNALFILE" ]
then echo "MSL-API already initialized. Proceeding with starting $MSLAPI_ROLE ..."
else
if [ "$MSLAPI_ROLE" == "WEBSERVER" ]
if [ "$MSLAPI_ROLE" == "WEBSERVER" ] || [ "$MSLAPI_ROLE" == "BOTH" ]
then # Initialize the MSL-API database
mysql -u root "-p$MYSQL_ROOT_PASSWORD" -h mslapi_db -e "
CREATE DATABASE mslapi;
Expand Down Expand Up @@ -70,5 +70,8 @@ then while true
done
elif [ "$MSLAPI_ROLE" == "WEBSERVER" ]
then /usr/sbin/nginx -g 'daemon off;'
elif [ "$MSLAPI_ROLE" == "BOTH" ]
then echo "Starting both web server and queue worker using supervisord..."
/usr/bin/supervisord
else echo "Error: unknown MSL API role: $MSLAPI_ROLE"
fi
24 changes: 24 additions & 0 deletions docker/images/msl-api/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
stdout_logfile=/var/log/nginx-supervisord.log
stderr_logfile=/var/log/nginx-supervisord-error.log
user=root

[program:laravel-queue]
command=/usr/bin/php8.0 /var/www/msl_api/artisan queue:work --rest=1 --tries=3 --timeout=300
autostart=true
autorestart=true
stdout_logfile=/var/log/laravel-queue-supervisord.log
stderr_logfile=/var/log/laravel-queue-supervisord-error.log
directory=/var/www/msl_api
user=www-data

[group:laravel]
programs=nginx,laravel-queue

0 comments on commit 45ad927

Please sign in to comment.