From 0673897dbaacdcda2f18b2b00b82240981886650 Mon Sep 17 00:00:00 2001 From: Michael Wurster Date: Wed, 10 Apr 2024 15:50:09 +0200 Subject: [PATCH] chore: add 'standalone' mode --- .../FastAPI.xml => .run/FastAPI.run.xml | 0 README.md | 2 +- entrypoint.sh | 42 +++++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) rename .idea/runConfigurations/FastAPI.xml => .run/FastAPI.run.xml (100%) diff --git a/.idea/runConfigurations/FastAPI.xml b/.run/FastAPI.run.xml similarity index 100% rename from .idea/runConfigurations/FastAPI.xml rename to .run/FastAPI.run.xml diff --git a/README.md b/README.md index d61ee6c..b9040b1 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ docker build -t planqk-cli-serve . Once the container image has been built, start it with the following command: ```bash -docker run -p 8000:8000 -v "$(pwd):/user_code" planqk-cli-serve +docker run -it -e PORT=8000 -p 8000:8000 -v "$(pwd):/user_code" planqk-cli-serve standalone ``` ## Development diff --git a/entrypoint.sh b/entrypoint.sh index eb812ba..484f090 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,39 @@ #!/bin/bash -set -e -trap 'echo "Error: Command failed with exit code $?" >&2; exit 1' ERR +set -eu +set -o pipefail -if [ -f dependencies.txt ] && cmp -s dependencies.txt /user_code/requirements.txt; then - exec "$@" -else - cp /user_code/requirements.txt dependencies.txt +function main { + local path + + while [[ "${#}" != 0 ]]; do + case "${1}" in + standalone) + echo "Running in standalone mode" + build + start uvicorn src.app:app --reload --host 0.0.0.0 --port $PORT + exit 0 + ;; + + *) + start "${@:-}" + exit 0 + ;; + esac + done +} + +function build() { pip install -r /user_code/requirements.txt -fi + cp /user_code/requirements.txt dependencies.txt +} + +function start() { + if [ -f dependencies.txt ] && cmp -s dependencies.txt /user_code/requirements.txt; then + exec "$@" + else + build + fi +} + +main "${@:-}"