Spaces:
Runtime error
Runtime error
File size: 1,173 Bytes
f491ef3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# Use a base image
FROM ubuntu:20.04
# Set environment variable to non-interactive mode
ENV DEBIAN_FRONTEND=noninteractive
# Install PostgreSQL and dependencies
RUN apt-get update && apt-get install -y \
postgresql postgresql-contrib \
python3 python3-pip \
tzdata && \
rm -rf /var/lib/apt/lists/*
# Reset DEBIAN_FRONTEND
ENV DEBIAN_FRONTEND=interactive
# Set environment variables for PostgreSQL
ENV POSTGRES_DB=mydatabase
ENV POSTGRES_USER=myuser
ENV POSTGRES_PASSWORD=mypassword
# Install application dependencies
COPY requirements.txt /app/requirements.txt
RUN pip3 install -r /app/requirements.txt
# Copy FastAPI application code
COPY app.py /app/app.py
# Set up the PostgreSQL database and user
RUN service postgresql start && \
su - postgres -c "psql -c \"CREATE USER myuser WITH PASSWORD 'mypassword';\"" && \
su - postgres -c "createdb mydatabase" && \
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;\""
# Expose PostgreSQL and FastAPI ports
EXPOSE 5432 8080
# Start PostgreSQL and FastAPI app together
CMD service postgresql start && cd app && uvicorn app:app --host 0.0.0.0 --port 8080
|