circulartext commited on
Commit
d3b9ce1
·
1 Parent(s): bee8182

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -7
Dockerfile CHANGED
@@ -7,15 +7,24 @@ WORKDIR /app
7
  # Copy the current directory contents into the container at /app
8
  COPY . /app
9
 
10
- # Copy user and group information from the base image
11
- COPY --from=circulartextapp/readspaceout /etc/passwd /etc/passwd
12
- COPY --from=circulartextapp/readspaceout /etc/group /etc/group
13
-
14
- # Set appropriate permissions for the application directory using UID and GID
15
- RUN if getent passwd user > /dev/null 2>&1 && getent group user > /dev/null 2>&1; then \
16
- chown -R "$USER_ID":"$USER_GROUP" /app && chmod -R 755 /app; \
 
 
 
 
 
 
17
  fi
18
 
 
 
 
19
  # Install gosu (adjust the package manager based on your base image)
20
  RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*
21
 
@@ -23,8 +32,18 @@ RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*
23
  COPY entrypoint.sh /usr/local/bin/entrypoint.sh
24
  RUN chmod +x /usr/local/bin/entrypoint.sh
25
 
 
 
 
26
  # Define the entrypoint script to handle user creation and application startup
27
  ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
28
 
29
  # Default command to run if the user doesn't provide a command
30
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
 
 
 
 
 
 
 
 
7
  # Copy the current directory contents into the container at /app
8
  COPY . /app
9
 
10
+ # Define the user ID in the environment variable USER_ID with a default value
11
+ ARG USER_ID=1000
12
+ ENV USER_ID=$USER_ID
13
+
14
+ # Check if the user already exists
15
+ RUN if [ -z "$USER_ID" ]; then \
16
+ echo "User ID not provided. Using the default user ID 1000."; \
17
+ USER_ID=1000; \
18
+ fi && \
19
+ if id "$USER_ID" >/dev/null 2>&1; then \
20
+ echo "User with ID $USER_ID already exists."; \
21
+ else \
22
+ useradd -m -u "$USER_ID" user; \
23
  fi
24
 
25
+ # Set appropriate permissions for the application directory
26
+ RUN chown -R user:user /app && chmod -R 755 /app
27
+
28
  # Install gosu (adjust the package manager based on your base image)
29
  RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*
30
 
 
32
  COPY entrypoint.sh /usr/local/bin/entrypoint.sh
33
  RUN chmod +x /usr/local/bin/entrypoint.sh
34
 
35
+ # Switch to the user for improved security
36
+ USER user
37
+
38
  # Define the entrypoint script to handle user creation and application startup
39
  ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
40
 
41
  # Default command to run if the user doesn't provide a command
42
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
43
+
44
+ # Set user-specific environment variables
45
+ ENV HOME=/home/user
46
+ ENV PATH=$HOME/.local/bin:$PATH
47
+ ENV MODELSCOPE_CACHE=$HOME/modelscope_cache
48
+ ENV GRADIO_SERVER_NAME=0.0.0.0
49
+