Skip to content

Commit 295c4d9

Browse files
committed
Optimize docker container building
1 parent 24a2690 commit 295c4d9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ WORKDIR /app
1414

1515
# Path: /app/requirements.txt
1616
COPY --from=generate-requirements /app/requirements.txt ./
17+
RUN ["python3", "-m", "venv", "/venv"]
18+
ENV PATH="/venv/bin:$PATH"
19+
RUN ["python3", "-m", "pip", "install", "-r", "requirements.txt"]
1720

18-
RUN ["pip", "install", "-r", "requirements.txt"]
19-
21+
FROM python:3.12-slim as production
22+
COPY --from=build /venv /venv
2023
COPY src/main.py .
24+
ENV PATH="/venv/bin:$PATH"
2125

22-
ENTRYPOINT [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers" ]
26+
ENTRYPOINT [ "python3", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers" ]
2327

2428
EXPOSE 8000

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async def repeat_url_worker():
167167
async def lifespan(_: FastAPI):
168168
global engine, async_session
169169
if engine is None:
170-
engine = sqlalchemy.ext.asyncio.create_async_engine(environ.get("DATABASE_URL", "sqlite://db.sqlite"))
170+
engine = sqlalchemy.ext.asyncio.create_async_engine(environ.get("DATABASE_URL", "sqlite:///db.sqlite"))
171171
async_session = sqlalchemy.ext.asyncio.async_sessionmaker(engine, expire_on_commit=False)
172172
async with engine.begin() as conn:
173173
await conn.run_sync(Base.metadata.create_all)

0 commit comments

Comments
 (0)