Skip to content

Commit

Permalink
Fix api dying (#353)
Browse files Browse the repository at this point in the history
Adds a startup script to use in dockerfile instead of a list style CMD

---------

Co-authored-by: Faisal Alquaddoomi <[email protected]>
  • Loading branch information
glass-ships and falquaddoomi authored Sep 29, 2023
1 parent bc16562 commit 3481eaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN apt-get update -y && \

# copy project requirement files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY . /opt/monarch-app
COPY . /opt/monarch-app/backend

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN curl -sSL https://install.python-poetry.org | python3 && \
Expand All @@ -41,12 +41,12 @@ RUN curl -sSL https://install.python-poetry.org | python3 && \

FROM builder-base as production
ENV SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
ENV UVICORN_WORKERS=8
# ENV UVICORN_WORKERS=8
WORKDIR /opt/monarch-app/backend

RUN poetry install

CMD ["/opt/poetry/bin/poetry", "run", "uvicorn", "src.monarch_py.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "${UVICORN_WORKERS}"]
CMD /opt/monarch-app/backend/start_api.sh

### Image URLs for reference ###
#
Expand Down
7 changes: 7 additions & 0 deletions backend/start_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

# check for uvicorn workers env var, default to 1
UVICORN_WORKERS=${UVICORN_WORKERS:-1}

# Start the API
/opt/poetry/bin/poetry run uvicorn src.monarch_py.api.main:app --host 0.0.0.0 --port 8000 --workers ${UVICORN_WORKERS}

0 comments on commit 3481eaf

Please sign in to comment.