From 158068a166f765e3f7d88d50e8a2d025a6b46b07 Mon Sep 17 00:00:00 2001 From: Christian Boettcher <c.boettcher@fz-juelich.de> Date: Mon, 17 May 2021 11:30:27 +0200 Subject: [PATCH] move around setting stuff so that docker build process works --- README.md | 2 +- apiserver/.dockerignore | 5 +++++ apiserver/Dockerfile | 18 +++++++++++------- config.env => apiserver/config.env | 2 +- apiserver/config/settings.py | 2 +- apiserver/main.py | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 apiserver/.dockerignore rename config.env => apiserver/config.env (73%) diff --git a/README.md b/README.md index a4450cd..8addbee 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The `context.py` file helps with importing the apiserver-packages, so that the t To build the docker image of the current version, simply run ```bash -docker built -t datacatalog-apiserver ./apiserver +docker build -t datacatalog-apiserver ./apiserver ``` while in the project root directory. diff --git a/apiserver/.dockerignore b/apiserver/.dockerignore new file mode 100644 index 0000000..26d6acc --- /dev/null +++ b/apiserver/.dockerignore @@ -0,0 +1,5 @@ +**/__pycache__ +**/.pytest_cache +README.md +Dockerfile +.dockerignore \ No newline at end of file diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index 80fba08..09150a9 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -2,15 +2,19 @@ FROM tiangolo/uvicorn-gunicorn:python3.8 LABEL maintainer="Christian Böttcher <c.boettcher@fz-juelich.de>" -RUN mkdir -p /app/app/data -RUN mkdir -p /app/app/storage +RUN mkdir -p /app/data +RUN mkdir -p /app/apiserver RUN apt update && apt upgrade -y RUN pip install --no-cache-dir fastapi -COPY ./__init__.py /app/app/ -COPY ./main.py /app/app/ -COPY ./storage/JsonFileStorageAdapter.py /app/app/storage/ -COPY ./storage/LocationStorage.py /app/app/storage/ -COPY ./storage/__init__.py /app/app/storage/ \ No newline at end of file +ADD . /app/apiserver +COPY ./config.env /app/apiserver/config.env + +# This RUN creates a python file that contains the fastapi app, in a location that is expected by the base docker image +# This avoids naming conflicts with the packages in the project folder +RUN echo "from apiserver.main import app" > /app/main.py + +# set data directory properly for the docker container +RUN sed -i 's_./app/data_/app/data_g' /app/apiserver/config.env \ No newline at end of file diff --git a/config.env b/apiserver/config.env similarity index 73% rename from config.env rename to apiserver/config.env index 2eda124..ee76c5c 100644 --- a/config.env +++ b/apiserver/config.env @@ -1,4 +1,4 @@ # contains Settings that can be loaded via pydantic settings .env support # DATACATALOG_APISERVER_HOST="0.0.0.0", # DATACATALOG_APISERVER_PORT=80 -DATACATALOG_APISERVER_JSON_STORAGE_PATH="./app/data" \ No newline at end of file +DATACATALOG_APISERVER_JSON_STORAGE_PATH="./app/data" diff --git a/apiserver/config/settings.py b/apiserver/config/settings.py index 6cc526d..336c89d 100644 --- a/apiserver/config/settings.py +++ b/apiserver/config/settings.py @@ -10,4 +10,4 @@ class ApiserverSettings(BaseSettings): class Config: env_prefix: str = "datacatalog_apiserver_" - env_file: str = "config.env" \ No newline at end of file + env_file: str = "apiserver/config.env" \ No newline at end of file diff --git a/apiserver/main.py b/apiserver/main.py index 9366ebf..0be808c 100644 --- a/apiserver/main.py +++ b/apiserver/main.py @@ -19,7 +19,7 @@ from enum import Enum settings = ApiserverSettings() app = FastAPI( - title="API-Server for the Data Catalogue" + title="API-Server for the Data Catalog" ) adapter: AbstractLocationDataStorageAdapter = JsonFileStorageAdapter(settings) -- GitLab