circulartext commited on
Commit
91a68c0
1 Parent(s): 2ab4091

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +47 -0
Dockerfile ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the base Docker image with necessary dependencies
2
+ FROM circulartextapp/spaceread as base
3
+
4
+ # Set the working directory to /app
5
+ WORKDIR /app
6
+
7
+ # Copy the current directory contents into the container at /app
8
+ COPY . /app
9
+
10
+ # Define the username in the environment variable USERNAME with a default value
11
+ ARG USERNAME=default_user
12
+ ENV USERNAME=$USERNAME
13
+
14
+ # Check if the user already exists
15
+ RUN if id "$USERNAME" >/dev/null 2>&1; then \
16
+ echo "User $USERNAME already exists."; \
17
+ else \
18
+ useradd -m -u 1000 -s /bin/bash "$USERNAME"; \
19
+ fi
20
+
21
+ # Set appropriate permissions for the application directory
22
+ RUN chown -R "$USERNAME":"$USERNAME" /app && chmod -R 755 /app
23
+
24
+ # Switch to the user for improved security
25
+ USER "$USERNAME"
26
+
27
+ # Intermediate image with additional packages
28
+ FROM debian:bullseye-slim as packages
29
+
30
+ # Install gosu using apt-get
31
+ RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*
32
+
33
+ # Final image
34
+ FROM base
35
+
36
+ # Copy gosu from the packages image
37
+ COPY --from=packages /usr/sbin/gosu /usr/sbin/gosu
38
+
39
+ # Set the entrypoint script as executable
40
+ COPY entrypoint.sh /usr/local/bin/entrypoint.sh
41
+ RUN chmod +x /usr/local/bin/entrypoint.sh
42
+
43
+ # Define the entrypoint script to handle user creation and application startup
44
+ ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
45
+
46
+ # Default command to run if the user doesn't provide a command
47
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]