Skip to content

Commit

Permalink
Automatically run DB migrations on start
Browse files Browse the repository at this point in the history
  • Loading branch information
EricTendian committed Jan 6, 2025
1 parent 645fad0 commit 9775b6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ jobs:
run: |
docker compose --ansi never logs -f &
sleep 10
uv run alembic upgrade head
./make.sh test -s
12 changes: 4 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,16 @@ ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev $WHISPER_IMPLEMENTATION_GROUP

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /src
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev $WHISPER_IMPLEMENTATION_GROUP

# $WHISPER_INSTALL_INSTRUCTIONS

COPY alembic.ini alembic.ini
COPY app app
COPY config config
COPY docker/docker-entrypoint.sh /usr/local/bin/
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ if [ "$1" = 'api' ]; then
/bin/sh -c "while true; do find /tmp -type f -mmin +10 -delete; sleep 60; done" &
disown

if [ -n "$POSTGRES_HOST" ]; then
# Check if we have run any DB migrations yet
CURRENT_DB_VERSION="$(uv run alembic current)"
if [ -z "$CURRENT_DB_VERSION" ]; then
uv run alembic upgrade head
fi
fi

exec uv run uvicorn app.api:app --host 0.0.0.0 --log-level ${UVICORN_LOG_LEVEL:-info}
elif [ "$1" = 'worker' ]; then
# Clean up any old temp files
Expand Down

0 comments on commit 9775b6f

Please sign in to comment.