From 091fa35aabac5297082d344134be132b59628cd6 Mon Sep 17 00:00:00 2001 From: Boris Arzentar Date: Wed, 16 Oct 2024 23:32:32 +0200 Subject: [PATCH] chore: run alembic migrations in docker entrypoint --- Dockerfile | 8 ++++++-- Dockerfile-old | 49 ------------------------------------------------- entrypoint.sh | 3 +++ 3 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 Dockerfile-old diff --git a/Dockerfile b/Dockerfile index 1262a6f17..3b0f5f3ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY pyproject.toml poetry.lock /app/ RUN pip install poetry -# Create virtualenv +# Don't create virtualenv since docker is already isolated RUN poetry config virtualenvs.create false # Install the dependencies @@ -22,7 +22,11 @@ RUN poetry install --no-root --no-dev # Set the PYTHONPATH environment variable to include the /app directory ENV PYTHONPATH=/app -COPY cognee/ /app/cognee +COPY cognee/ cognee/ + +# Copy Alembic configuration +COPY alembic.ini ./ +COPY alembic/ alembic/ COPY entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh diff --git a/Dockerfile-old b/Dockerfile-old deleted file mode 100644 index 5913ac543..000000000 --- a/Dockerfile-old +++ /dev/null @@ -1,49 +0,0 @@ -FROM python:3.11 - -# Set build argument -ARG DEBUG - -# Set environment variable based on the build argument -ENV DEBUG=${DEBUG} -ENV PIP_NO_CACHE_DIR=true -ENV PATH="${PATH}:/root/.poetry/bin" - -RUN pip install poetry - -WORKDIR /app -COPY pyproject.toml poetry.lock /app/ - -# Install the dependencies -RUN poetry config virtualenvs.create false && \ - poetry install --no-root --no-dev - -RUN apt-get update -q && \ - apt-get install -y -q \ - gcc \ - python3-dev \ - curl \ - zip \ - jq \ - netcat-traditional && \ - pip install poetry && \ - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ - unzip -qq awscliv2.zip && \ - ./aws/install && \ - apt-get clean && \ - rm -rf \ - awscliv2.zip \ - /var/lib/apt/lists/* \ - /tmp/* \ - /var/tmp/* - -WORKDIR /app -# Set the PYTHONPATH environment variable to include the /app directory -ENV PYTHONPATH=/app - -COPY cognee/ /app/cognee - - -COPY entrypoint.sh /app/entrypoint.sh -RUN chmod +x /app/entrypoint.sh - -ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 5e61a885c..cc6918371 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,9 @@ echo "Debug mode: $DEBUG" echo "Environment: $ENVIRONMENT" +# Run migrations +poetry run alembic upgrade head + echo "Starting Gunicorn" if [ "$ENVIRONMENT" = "dev" ]; then