From fb0e2a370db5fc30b6987bb9706108fddd5b9b18 Mon Sep 17 00:00:00 2001 From: Pradeep Bashyal Date: Wed, 31 Jul 2024 10:26:11 -0500 Subject: [PATCH 1/2] pyard-service Docker changes - import pyard on start, not build - use a docker-entrypoint script to start the app - update Makefile to produce versioned docker image --- docker-entrypoint-flask.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 docker-entrypoint-flask.sh diff --git a/docker-entrypoint-flask.sh b/docker-entrypoint-flask.sh new file mode 100755 index 0000000..4077a84 --- /dev/null +++ b/docker-entrypoint-flask.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +# A positive integer generally in the 2-4 x $(NUM_CORES) range. +WORKER_PROCESSES=${WORKERS:-4} + +echo "Starting Magenta with" "${WORKER_PROCESSES}" worker processes. + +if [ "${WORKER_PROCESSES}" != "1" ]; then + WORKER_FLAG="--workers=${WORKER_PROCESSES}" +fi + +# Import pyard before starting the app +pyard-import + +gunicorn --preload --bind 0.0.0.0:8080 --timeout 5000 --log-level info "${WORKER_FLAG}" app:app From 2c95a0da2cd48e5b056ad6444b1a35209ddb9d4f Mon Sep 17 00:00:00 2001 From: Pradeep Bashyal Date: Wed, 31 Jul 2024 10:30:01 -0500 Subject: [PATCH 2/2] Add missing files --- Dockerfile | 7 ++----- Makefile | 6 ++++-- docker-entrypoint-flask.sh | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9147ee..c3c20c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,12 +15,9 @@ RUN pip install --no-cache-dir -r requirements-deploy.txt RUN pip install --no-cache-dir py-ard==$PY_ARD_VERSION -RUN pyard-import && \ - pyard --version && \ - pyard-status - COPY app.py /app/ COPY api.py /app/ COPY api-spec.yaml /app/ -CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--worker-tmp-dir", "/dev/shm", "--timeout", "30", "app:app"] +COPY docker-entrypoint-flask.sh /usr/local/bin/ +CMD ["/usr/local/bin/docker-entrypoint-flask.sh"] diff --git a/Makefile b/Makefile index 05bd3c1..425f10e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ PROJECT_NAME := $(shell basename `pwd`) PACKAGE_NAME := pyard +PYARD_VERSION := 1.2.1 .PHONY: clean clean-test clean-pyc clean-build docs help .DEFAULT_GOAL := help @@ -98,10 +99,11 @@ dist: clean ## builds source and wheel package ls -l dist docker-build: ## build a docker image for the service - docker build --platform=linux/amd64 -t nmdpbioinformatics/pyard-service:latest . + docker build --platform=linux/amd64 -t nmdpbioinformatics/pyard-service:$(PYARD_VERSION).linux-amd64 . + docker tag nmdpbioinformatics/pyard-service:$(PYARD_VERSION) nmdpbioinformatics/pyard-service:latest docker: docker-build ## build a docker image and run the service - docker run --platform=linux/amd64 --rm --name pyard-service -p 8080:8080 nmdpbioinformatics/pyard-service:latest + docker run --platform=linux/amd64 --rm --name pyard-service -p 8080:8080 nmdpbioinformatics/pyard-service:$(PYARD_VERSION).linux-amd64 install: clean ## install the package to the active Python's site-packages pip install --upgrade pip diff --git a/docker-entrypoint-flask.sh b/docker-entrypoint-flask.sh index 4077a84..d2612a8 100755 --- a/docker-entrypoint-flask.sh +++ b/docker-entrypoint-flask.sh @@ -4,13 +4,13 @@ set -e # A positive integer generally in the 2-4 x $(NUM_CORES) range. WORKER_PROCESSES=${WORKERS:-4} -echo "Starting Magenta with" "${WORKER_PROCESSES}" worker processes. +echo "Starting py-ard service with" "${WORKER_PROCESSES}" worker processes. if [ "${WORKER_PROCESSES}" != "1" ]; then WORKER_FLAG="--workers=${WORKER_PROCESSES}" fi -# Import pyard before starting the app +# Import the latest pyard before starting the app pyard-import gunicorn --preload --bind 0.0.0.0:8080 --timeout 5000 --log-level info "${WORKER_FLAG}" app:app