Skip to content

Commit 0a32543

Browse files
committed
Wired up migrations into docker startup
1 parent 360651f commit 0a32543

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

backend/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
FROM python:3.11-slim
22

3+
# set working directory
34
WORKDIR /app
45

6+
# install dependencies
57
COPY requirements.txt .
68
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
79

10+
# copy app source code
811
COPY app ./app
12+
COPY alembic.ini ./alembic.ini
13+
COPY alembic ./alembic
914

15+
# environment variables
1016
ENV PYTHONUNBUFFERED=1
1117

12-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
18+
# entrypoint: run migrations then start up
19+
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
1320

1421

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ services:
2828
interval: 5s
2929
timeout: 5s
3030
retries: 5
31+
32+
migrate:
33+
image: eventrelay-api:latest
34+
command: alembic upgrade head
35+
environment:
36+
POSTGRES_USER: eventrelayuser
37+
POSTGRES_PASSWORD: 123
38+
POSTGRES_DB: eventrelay
39+
POSTGRES_HOST: db
40+
POSTGRES_PORT: 5432
41+
depends_on:
42+
db:
43+
condition: service_healthy
3144

3245
volumes:
3346
postgres_data:

0 commit comments

Comments
 (0)