Kaballas commited on
Commit
3561597
·
verified ·
1 Parent(s): f491ef3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -32
Dockerfile CHANGED
@@ -1,39 +1,27 @@
1
- # Use a base image
2
- FROM ubuntu:20.04
3
 
4
- # Set environment variable to non-interactive mode
5
- ENV DEBIAN_FRONTEND=noninteractive
6
 
7
- # Install PostgreSQL and dependencies
8
- RUN apt-get update && apt-get install -y \
9
- postgresql postgresql-contrib \
10
- python3 python3-pip \
11
- tzdata && \
12
- rm -rf /var/lib/apt/lists/*
 
13
 
14
- # Reset DEBIAN_FRONTEND
15
- ENV DEBIAN_FRONTEND=interactive
 
16
 
17
- # Set environment variables for PostgreSQL
18
- ENV POSTGRES_DB=mydatabase
19
- ENV POSTGRES_USER=myuser
20
- ENV POSTGRES_PASSWORD=mypassword
21
 
22
- # Install application dependencies
23
- COPY requirements.txt /app/requirements.txt
24
- RUN pip3 install -r /app/requirements.txt
25
 
26
- # Copy FastAPI application code
27
- COPY app.py /app/app.py
28
 
29
- # Set up the PostgreSQL database and user
30
- RUN service postgresql start && \
31
- su - postgres -c "psql -c \"CREATE USER myuser WITH PASSWORD 'mypassword';\"" && \
32
- su - postgres -c "createdb mydatabase" && \
33
- su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;\""
34
-
35
- # Expose PostgreSQL and FastAPI ports
36
- EXPOSE 5432 8080
37
-
38
- # Start PostgreSQL and FastAPI app together
39
- CMD service postgresql start && cd app && uvicorn app:app --host 0.0.0.0 --port 8080
 
1
+ FROM postgres:17
 
2
 
3
+ # Create user with UID 1000 (required by HF Spaces)
4
+ RUN useradd -m -u 1000 user
5
 
6
+ # Set environment variables
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH \
9
+ POSTGRES_PASSWORD=password \
10
+ POSTGRES_USER=postgres \
11
+ POSTGRES_DB=postgres \
12
+ PGDATA=/home/user/pgdata
13
 
14
+ # Create data directory with correct permissions
15
+ RUN mkdir -p /home/user/pgdata && \
16
+ chown -R user:user /home/user/pgdata
17
 
18
+ # Switch to user
19
+ USER user
 
 
20
 
21
+ WORKDIR $HOME/app
 
 
22
 
23
+ # Expose PostgreSQL port
24
+ EXPOSE 5432
25
 
26
+ # Start PostgreSQL
27
+ CMD ["postgres"]