diff --git a/Dockerfile b/Dockerfile index b37fd3d1150443ed5adb5e45da319d9c13f41002..ad3c1de97d3810f3a0c33eacf52ebd06dbd9fe04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,3 +22,6 @@ RUN if [ "${install_dev}" = "y" ]; then pip install -r requirements.dev.txt; fi COPY sciencebeam_gym ${PROJECT_FOLDER}/sciencebeam_gym COPY *.conf *.sh *.in *.txt *.py ${PROJECT_FOLDER}/ + +COPY scripts ${PROJECT_FOLDER}/scripts +ENV PATH ${PROJECT_FOLDER}/scripts:$PATH diff --git a/Makefile b/Makefile index e69f6c2da0a89ea80201716131023ad5a114cdc8..e8fbb2a36c83a284046f98f457e69c9cf0124841 100644 --- a/Makefile +++ b/Makefile @@ -41,16 +41,24 @@ pytest-not-slow: build-dev $(DOCKER_COMPOSE) run --rm sciencebeam-gym-dev pytest -m 'not slow' $(PYTEST_ARGS) -autocut-start: build +.require-AUTOCUT_MODEL_PATH: + @if [ -z "$(AUTOCUT_MODEL_PATH)" ]; then \ + echo "AUTOCUT_MODEL_PATH required"; \ + exit 1; \ + fi + + +shell-dev: + $(DOCKER_COMPOSE) run --rm sciencebeam-gym bash + + +autocut-start: .require-AUTOCUT_MODEL_PATH build $(DOCKER_COMPOSE) run --rm \ -v "$(AUTOCUT_MODEL_PATH):/tmp/model.pkl" \ -e "AUTOCUT_MODEL_PATH=/tmp/model.pkl" \ -p 8080:8080 \ sciencebeam-gym \ - gunicorn \ - 'sciencebeam_gym.models.text.crf.autocut_app:create_app()' \ - --timeout 10 --log-level debug --workers 1 --worker-class gevent \ - --bind 0.0.0.0:8080 + start-autocut.sh ci-build-and-test: diff --git a/scripts/start-app.sh b/scripts/start-app.sh new file mode 100755 index 0000000000000000000000000000000000000000..bed32c572a98a83e5190c1ace7be8427df9bdb75 --- /dev/null +++ b/scripts/start-app.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-10} +GUNICORN_LOG_LEVEL=${GUNICORN_LOG_LEVEL:-info} +GUNICORN_WORKERS=${GUNICORN_WORKERS:-1} +GUNICORN_WORKER_CLASS=${GUNICORN_WORKER_CLASS:-gevent} +GUNICORN_HOST=${GUNICORN_HOST:-0.0.0.0} +GUNICORN_PORT=${GUNICORN_PORT:-8080} + + +if [ -z "${APP_NAME}" ]; then + echo "APP_NAME required" + exit 1 +fi + + +APP_FACTORY_SUFFIX=':create_app()' + + +CMD="gunicorn \ + "${APP_NAME}${APP_FACTORY_SUFFIX}" \ + --timeout "${GUNICORN_TIMEOUT}" \ + --log-level "${GUNICORN_LOG_LEVEL}" \ + --workers "${GUNICORN_WORKERS}" \ + --worker-class "${GUNICORN_WORKER_CLASS}" \ + --bind "${GUNICORN_HOST}:${GUNICORN_PORT}" \ + $@" + +echo $CMD + +exec $CMD diff --git a/scripts/start-autocut.sh b/scripts/start-autocut.sh new file mode 100755 index 0000000000000000000000000000000000000000..4172735033a7640e22869a3849e205dffecb585b --- /dev/null +++ b/scripts/start-autocut.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +export APP_NAME=sciencebeam_gym.models.text.crf.autocut_app + +exec "$(dirname $0)/start-app.sh" $@