Skip to content

Commit

Permalink
Ar/fixing fastapi ea endpoint (#378)
Browse files Browse the repository at this point in the history
* adding health check endpoint - GKE ingress needs for checking service status

* changing endpoint path as static already exist for streamlit app

* updating Dockerfile file to work with new fastapi endpoint
  • Loading branch information
ali-encord authored May 5, 2023
1 parent 22c5287 commit 1342a87
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
47 changes: 36 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,55 @@ FROM python:3.9-slim

ARG POETRY_VERSION="1.2.2"

WORKDIR /app
RUN groupadd --gid 1000 appuser \
&& useradd --uid 1000 --gid 1000 -ms /bin/bash appuser

COPY .env pyproject.toml poetry.lock README.md /app
COPY ./src/ /app/src

ENV PYTHONPATH=${PYTHONPATH}:${PWD}
RUN pip3 install --no-cache-dir --upgrade \
pip \
virtualenv

RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
ffmpeg
ffmpeg \
sqlite3

RUN apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

RUN pip install .

WORKDIR /data
USER appuser
WORKDIR /home/appuser

RUN curl -sSL https://install.python-poetry.org | \
python - --version ${POETRY_VERSION}

ENV PATH="/home/appuser/.local/bin:$PATH"

COPY .env pyproject.toml poetry.lock /home/appuser

RUN poetry cache clear pypi --all
RUN poetry config virtualenvs.create true \
&& poetry config virtualenvs.in-project true \
&& poetry config experimental.new-installer true \
&& poetry install --no-root --without dev

COPY ./src/ /home/appuser/src
COPY README.md /home/appuser

RUN poetry install --only-root

EXPOSE 8501

ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
COPY run.sh /home/appuser

USER root
RUN mkdir /data && chown appuser: /data -R
USER appuser

RUN git config --global --add safe.directory '*'
EXPOSE 8000

HEALTHCHECK CMD ecord-active --version
ENTRYPOINT ["encord-active"]
ENTRYPOINT ["./run.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ encord-active quickstart
or you can use <a href="https://hub.docker.com/r/encord/encord-active"><img src="https://www.docker.com/wp-content/uploads/2022/03/horizontal-logo-monochromatic-white.png" height="20"/></a>:

```shell
docker run -it --rm -p 8501:8501 -v ${PWD}:/data encord/encord-active quickstart
docker run -it --rm -p 8501:8501 -p 8000:8000 -v ${PWD}:/data encord/encord-active quickstart
```

After opening the UI, we recommend you to head to the [workflow documentation][encord-active-docs-workflow] to see some common workflows.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you have trouble installing `encord-active`, you can find more detailed instr
You can also run the docker image instead of install Encord Active

```shell
docker run -it -p 8501:8501 -v ${PWD}:/data encord/encord-active <command>
docker run -it -p 8501:8501 -p 8000:8000 -v ${PWD}:/data encord/encord-active <command>
```

:::
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To learn more about how to use the command line interface, see the [Command Line
We also provide a docker image which works exctly the same as the cli.

```shell
docker run -it --rm -p 8501:8501 -v ${PWD}:/data encord/encord-active <command>
docker run -it --rm -p 8501:8501 -p 8000:8000 -v ${PWD}:/data encord/encord-active <command>
```

This will mount your current working directory, so everything that happens inside the docker container will persist after it is done.
Expand All @@ -70,7 +70,7 @@ This will mount your current working directory, so everything that happens insid
If you intend to use Encord Active with an Encord Annotate project you'll need to mount a voulume with your SSH key as well.

```shell
docker run -it --rm -p 8501:8501 -v ${PWD}:/data -v ${HOME}/.ssh:/root/.ssh encord/encord-active
docker run -it --rm -p 8501:8501 -p 8000:8000 -v ${PWD}:/data -v ${HOME}/.ssh:/root/.ssh encord/encord-active
```

Then, when asked for your SSH key, you can point to `~/.ssh/<your-key-file>`
27 changes: 27 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

APP_PID=
stopRunningProcess() {
# Based on https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script
if test ! "${APP_PID}" = '' && ps -p ${APP_PID} > /dev/null ; then
> /proc/1/fd/1 echo "Stopping ${COMMAND_PATH} which is running with process ID ${APP_PID}"

kill -TERM ${APP_PID}
> /proc/1/fd/1 echo "Waiting for ${COMMAND_PATH} to process SIGTERM signal"

wait ${APP_PID}
> /proc/1/fd/1 echo "All processes have stopped running"
else
> /proc/1/fd/1 echo "${COMMAND_PATH} was not started when the signal was sent or it has already been stopped"
fi
}

trap stopRunningProcess EXIT TERM

source .venv/bin/activate

encord-active visualize --target /data

APP_ID=${!}

wait ${APP_ID}
7 changes: 6 additions & 1 deletion src/encord_active/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
allow_headers=["*"],
)

app.mount("/static", StaticFiles(directory=path), name="static")
app.mount("/ea-static", StaticFiles(directory=path), name="static")


async def get_project_file_structure(project: str) -> ProjectFileStructure:
Expand Down Expand Up @@ -187,3 +187,8 @@ def search(project: ProjectFileStructureDep, query: str, type: SearchType, scope
"ids": [item.identifier for item in result.result_identifiers],
"snippet": snippet,
}


@app.get("/health")
def health_check() -> bool:
return True
2 changes: 1 addition & 1 deletion src/encord_active/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _get_url(label_row_structure: LabelRowStructure, du_hash: str, frame: str):
label_row_structure.iter_data_unit(du_hash), None
)
if data_unit:
return f"static/{parse.quote(data_unit.path.relative_to(label_row_structure.path.parents[2]).as_posix())}"
return f"ea-static/{parse.quote(data_unit.path.relative_to(label_row_structure.path.parents[2]).as_posix())}"


def _transform_object(object_: dict):
Expand Down

0 comments on commit 1342a87

Please sign in to comment.