Gurucool_Test / Dockerfile
ashwinR's picture
Update Dockerfile
9b79f17
raw
history blame
1.49 kB
FROM python:3.9-slim AS builder
WORKDIR /app
COPY ./pyproject.toml .
COPY ./poetry.lock .
# Install build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& pip install --upgrade pip poetry \
&& poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi
FROM python:3.9-slim
WORKDIR /app
# Install runtime dependencies
RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install PostgreSQL client
RUN apt-get update \
&& apt-get install -y --no-install-recommends postgresql-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/
FROM redis:latest AS redis
RUN redis-server
FROM postgres:latest
# Start Postgres
USER postgres
RUN postgres
# Switch to the root user
USER root
# Copy the built virtual environment from the builder stage
COPY --from=builder /usr/local /usr/local
# Copy the rest of the backend files to the container
COPY ./ .
# Create user, database, and grant privileges
RUN su psql -U postgres -c "CREATE USER postadmin WITH PASSWORD 'postpass';"
RUN su psql -U postgres -c "CREATE DATABASE siksalaya;"
RUN su psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE siksalaya TO postadmin;"
ENV DATABASE_URL=postgresql://postadmin:postpass@localhost/siksalaya
RUN alembic upgrade head
# Start the FastAPI app using Uvicorn
CMD ["bash", "-c", "redis-server --daemonize yes && uvicorn app:app --host 0.0.0.0 --port 7860"]