Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +11 -36
Dockerfile
CHANGED
|
@@ -1,10 +1,7 @@
|
|
| 1 |
-
FROM python:3.9-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
COPY ./pyproject.toml .
|
| 6 |
-
COPY ./poetry.lock .
|
| 7 |
-
|
| 8 |
# Install build dependencies
|
| 9 |
RUN apt-get update \
|
| 10 |
&& apt-get install -y --no-install-recommends build-essential \
|
|
@@ -12,48 +9,26 @@ RUN apt-get update \
|
|
| 12 |
&& poetry config virtualenvs.create false \
|
| 13 |
&& poetry install --no-interaction --no-ansi
|
| 14 |
|
| 15 |
-
FROM python:3.9-slim
|
| 16 |
-
|
| 17 |
-
WORKDIR /app
|
| 18 |
-
|
| 19 |
# Install runtime dependencies
|
| 20 |
RUN apt-get update \
|
|
|
|
| 21 |
&& apt-get clean \
|
| 22 |
&& rm -rf /var/lib/apt/lists/*
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
RUN
|
| 26 |
-
|
| 27 |
-
&& apt-get clean \
|
| 28 |
-
&& rm -rf /var/lib/apt/lists/
|
| 29 |
-
|
| 30 |
-
FROM redis:latest AS redis
|
| 31 |
-
RUN redis-server
|
| 32 |
-
|
| 33 |
-
FROM postgres:latest
|
| 34 |
-
|
| 35 |
-
# Start Postgres
|
| 36 |
-
USER postgres
|
| 37 |
-
|
| 38 |
-
RUN postgres
|
| 39 |
-
|
| 40 |
-
# Switch to the root user
|
| 41 |
-
USER root
|
| 42 |
-
|
| 43 |
-
# Copy the built virtual environment from the builder stage
|
| 44 |
-
COPY --from=builder /usr/local /usr/local
|
| 45 |
-
|
| 46 |
-
# Copy the rest of the backend files to the container
|
| 47 |
-
COPY ./ .
|
| 48 |
-
|
| 49 |
|
| 50 |
# Create user, database, and grant privileges
|
| 51 |
-
RUN su
|
| 52 |
-
RUN su
|
| 53 |
-
RUN su
|
| 54 |
|
|
|
|
| 55 |
ENV DATABASE_URL=postgresql://postadmin:postpass@localhost/siksalaya
|
| 56 |
|
|
|
|
| 57 |
RUN alembic upgrade head
|
|
|
|
| 58 |
# Start the FastAPI app using Uvicorn
|
| 59 |
CMD ["bash", "-c", "redis-server --daemonize yes && uvicorn app:app --host 0.0.0.0 --port 7860"]
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
# Install build dependencies
|
| 6 |
RUN apt-get update \
|
| 7 |
&& apt-get install -y --no-install-recommends build-essential \
|
|
|
|
| 9 |
&& poetry config virtualenvs.create false \
|
| 10 |
&& poetry install --no-interaction --no-ansi
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Install runtime dependencies
|
| 13 |
RUN apt-get update \
|
| 14 |
+
&& apt-get install -y --no-install-recommends redis-server postgresql \
|
| 15 |
&& apt-get clean \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# Start Redis and Postgres
|
| 19 |
+
RUN service redis-server start
|
| 20 |
+
RUN service postgresql start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Create user, database, and grant privileges
|
| 23 |
+
RUN su postgres -c "psql -c \"CREATE USER postadmin WITH PASSWORD 'postpass';\""
|
| 24 |
+
RUN su postgres -c "psql -c \"CREATE DATABASE siksalaya;\""
|
| 25 |
+
RUN su postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE siksalaya TO postadmin;\""
|
| 26 |
|
| 27 |
+
# Set environment variables for Alembic
|
| 28 |
ENV DATABASE_URL=postgresql://postadmin:postpass@localhost/siksalaya
|
| 29 |
|
| 30 |
+
# Run Alembic migrations
|
| 31 |
RUN alembic upgrade head
|
| 32 |
+
|
| 33 |
# Start the FastAPI app using Uvicorn
|
| 34 |
CMD ["bash", "-c", "redis-server --daemonize yes && uvicorn app:app --host 0.0.0.0 --port 7860"]
|