diff --git a/{{cookiecutter.project_slug}}/docker/content/nginx.conf.template b/{{cookiecutter.project_slug}}/docker/content/nginx.conf.template index 0ecb767..d8df1e0 100644 --- a/{{cookiecutter.project_slug}}/docker/content/nginx.conf.template +++ b/{{cookiecutter.project_slug}}/docker/content/nginx.conf.template @@ -20,7 +20,7 @@ map $fly_machine_id $sticky_action { # Main server block server { - listen $MESOP_PORT; + listen $TO_EXPOSE_SERVICE_PORT; server_name localhost; # Security headers diff --git a/{{cookiecutter.project_slug}}/docker/content/run_fastagency.sh b/{{cookiecutter.project_slug}}/docker/content/run_fastagency.sh index d3396d3..5ab881b 100755 --- a/{{cookiecutter.project_slug}}/docker/content/run_fastagency.sh +++ b/{{cookiecutter.project_slug}}/docker/content/run_fastagency.sh @@ -7,8 +7,12 @@ NATS_FASTAPI_PORT=${NATS_FASTAPI_PORT:-8000} {% if "fastapi" in cookiecutter.app_type %} FASTAPI_PORT=${FASTAPI_PORT:-8008} {% endif %} +{% if "mesop" in cookiecutter.app_type %} export MESOP_PORT=${MESOP_PORT:-8888} - +export TO_EXPOSE_SERVICE_PORT=$MESOP_PORT +{% else %} +export TO_EXPOSE_SERVICE_PORT=$FASTAPI_PORT +{% endif %} # Default number of workers if not set WORKERS=${WORKERS:-1} echo "Number of workers: $WORKERS" @@ -20,10 +24,10 @@ echo "Fly machine ID: $FLY_MACHINE_ID" # Generate nginx config for ((i=1; i<$WORKERS+1; i++)) do - PORT=$((MESOP_PORT + i)) + PORT=$((TO_EXPOSE_SERVICE_PORT + i)) sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template done -envsubst '${MESOP_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf +envsubst '${TO_EXPOSE_SERVICE_PORT},${FLY_MACHINE_ID}' < nginx.conf.template >/etc/nginx/conf.d/default.conf echo "Nginx config:" cat /etc/nginx/conf.d/default.conf @@ -33,14 +37,25 @@ nginx -g "daemon off;" & # Run nats uvicorn server uvicorn {{cookiecutter.project_slug}}.deployment.main_1_nats:app --host 0.0.0.0 --port $NATS_FASTAPI_PORT > /dev/stdout 2>&1 & {% endif %} +{% if cookiecutter.app_type == "fastapi" %} +# Run uvicorn server +# Start multiple single-worker uvicorn instances on consecutive ports +for ((i=1; i<$WORKERS+1; i++)) +do + PORT=$((TO_EXPOSE_SERVICE_PORT + i)) + echo "Starting gunicorn on port $PORT" + uvicorn {{cookiecutter.project_slug}}.deployment.main_1_fastapi:app --workers=1 --host 0.0.0.0 --port $PORT > /dev/stdout 2>&1 & +done +{% else %} # Run uvicorn server uvicorn {{cookiecutter.project_slug}}.deployment.main_{% if "nats" in cookiecutter.app_type %}2_fastapi{% elif "fastapi" in cookiecutter.app_type %}1_fastapi{% endif %}:app --host 0.0.0.0 --port $FASTAPI_PORT > /dev/stdout 2>&1 & +{% endif %} {% if "mesop" in cookiecutter.app_type %} # Run gunicorn server # Start multiple single-worker gunicorn instances on consecutive ports for ((i=1; i<$WORKERS+1; i++)) do - PORT=$((MESOP_PORT + i)) + PORT=$((TO_EXPOSE_SERVICE_PORT + i)) echo "Starting gunicorn on port $PORT" gunicorn --workers=1 {{cookiecutter.project_slug}}.deployment.main{% if "nats" in cookiecutter.app_type %}_3_mesop{% elif "fastapi" in cookiecutter.app_type %}_2_mesop{% endif %}:app --bind 0.0.0.0:$PORT > /dev/stdout 2>&1 & done diff --git a/{{cookiecutter.project_slug}}/scripts/run_docker.sh b/{{cookiecutter.project_slug}}/scripts/run_docker.sh index caaf421..29d93ad 100755 --- a/{{cookiecutter.project_slug}}/scripts/run_docker.sh +++ b/{{cookiecutter.project_slug}}/scripts/run_docker.sh @@ -1,3 +1,3 @@ #!/bin/bash -docker run -it -e OPENAI_API_KEY=$OPENAI_API_KEY {% if cookiecutter.authentication == "google"%}-e GOOGLE_APPLICATION_CREDENTIALS="serviceAccountKey.json"{% endif %} {% if "nats" in cookiecutter.app_type %}-e NATS_URL=$NATS_URL -e FASTAGENCY_NATS_PASSWORD=$FASTAGENCY_NATS_PASSWORD -p 8000:8000{% endif %}{% if "fastapi" in cookiecutter.app_type %} -p 8008:8008{% endif %} -p 8888:8888 {% if "nats" in cookiecutter.app_type %}--network=host{% endif %} deploy_fastagency +docker run -it -e OPENAI_API_KEY=$OPENAI_API_KEY {% if cookiecutter.authentication == "google"%}-e GOOGLE_APPLICATION_CREDENTIALS="serviceAccountKey.json"{% endif %} {% if "nats" in cookiecutter.app_type %}-e NATS_URL=$NATS_URL -e FASTAGENCY_NATS_PASSWORD=$FASTAGENCY_NATS_PASSWORD -p 8000:8000{% endif %}{% if "fastapi" in cookiecutter.app_type %} -p 8008:8008{% endif %}{% if "mesop" in cookiecutter.app_type %} -p 8888:8888{% endif %}{% if "nats" in cookiecutter.app_type %} --network=host{% endif %} deploy_fastagency