From d75baea2d5659f4874c892d8b7700db9d8c60ebc Mon Sep 17 00:00:00 2001 From: Harikrishnan Balagopal Date: Tue, 27 Aug 2024 16:36:04 +0530 Subject: [PATCH] feat: add a Dockerfile Signed-off-by: Harikrishnan Balagopal --- Dockerfile | 17 +++++++++++++++++ Makefile | 10 ++++++++++ README.md | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a015ea8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.11 AS builder +SHELL ["/bin/bash", "-c"] +WORKDIR /app +COPY requirements.txt requirements.txt +RUN python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt +COPY . . +RUN source .venv/bin/activate && pip install . + +FROM python:3.11 AS runner +SHELL ["/bin/bash", "-c"] +WORKDIR /app +COPY --from=builder /app/.venv /app/.venv +COPY workdir/model.json model.json +COPY workdir/data.csv data.csv +ENV VIRTUAL_ENV="/app/.venv" +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" +CMD ["python3", "-m", "fm_training_estimator.ui.cli", "--model_path", "model.json", "--lookup_data_path", "data.csv", "input.json"] diff --git a/Makefile b/Makefile index 046a51e..98e27c1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +IMAGE ?= icr.io/ftplatform/fm_training_estimator:latest + .PHONY: build build: lint fmt install tox -e build @@ -37,3 +39,11 @@ run-cli: .PHONY: run-api run-api: python -m fm_training_estimator.ui.api ./workdir/data.csv ./workdir/model.json --use_model_features=True + +.PHONY: cbuild +cbuild: + docker build -t ${IMAGE} -f Dockerfile . + +.PHONY: cpush +cpush: + docker push ${IMAGE} diff --git a/README.md b/README.md index 832f698..b9315ad 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,22 @@ make run-web-ui This will start the UI on `localhost:3000` port. (The web ui has other options, not covered in this simple setup. If you want to skip the model whitelisting or change the port, directly run the UI as shown in the README in the `./fm_training_estimator/ui` folder.) + +### Container Image + +To build the estimator container image: + +1. Make sure both `model.json` and `data.csv` files are present in the `workdir` folder. + +2. Use this command to build and push the image: + +```shell +make cbuild +make cpush # If you want to push to the container registry +``` + +3. Use this command to run the image: + +```shell +docker run --rm -it -v "/path/to/input.json:/app/input.json" icr.io/ftplatform/fm_training_estimator:latest +```