Spaces:
Sleeping
Sleeping
Commit
·
23fcb7a
1
Parent(s):
dcdf3ee
Update Dockerfile
Browse files- Dockerfile +31 -16
Dockerfile
CHANGED
@@ -1,32 +1,47 @@
|
|
1 |
-
# Use a suitable base Docker image with necessary dependencies
|
2 |
-
FROM circulartextapp/spaceread
|
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 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Set appropriate permissions for the application directory
|
17 |
-
RUN chown -R
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
|
22 |
-
#
|
23 |
-
COPY entrypoint.sh /
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
|
28 |
# Define the entrypoint script to handle user creation and application startup
|
29 |
-
ENTRYPOINT ["/
|
30 |
|
31 |
# Default command to run if the user doesn't provide a command
|
32 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
|
|
|
|
|
|
|
|
|
1 |
# Set the working directory to /app
|
2 |
WORKDIR /app
|
3 |
|
4 |
# Copy the current directory contents into the container at /app
|
5 |
COPY . /app
|
6 |
|
7 |
+
# Set the user ID in the environment variable USER_ID with a default value
|
8 |
+
ARG USER_ID=1000
|
9 |
+
ENV USER_ID=$USER_ID
|
10 |
+
|
11 |
+
# Define the user group in the environment variable USER_GROUP with a default value
|
12 |
+
ARG USER_GROUP=appuser
|
13 |
+
ENV USER_GROUP=$USER_GROUP
|
14 |
+
|
15 |
+
# Create the user and group if they don't already exist
|
16 |
+
RUN if [ -z "$USER_ID" ]; then \
|
17 |
+
echo "User ID not provided. Using the default user ID 1000."; \
|
18 |
+
USER_ID=1000; \
|
19 |
+
fi && \
|
20 |
+
if [ -z "$USER_GROUP" ]; then \
|
21 |
+
echo "User group not provided. Using the default user group appuser."; \
|
22 |
+
USER_GROUP=appuser; \
|
23 |
+
fi && \
|
24 |
+
if id "$USER_ID" >/dev/null 2>&1; then \
|
25 |
+
echo "User with ID $USER_ID already exists."; \
|
26 |
+
else \
|
27 |
+
adduser --uid "$USER_ID" --disabled-password --gecos '' "$USER_GROUP"; \
|
28 |
+
fi
|
29 |
|
30 |
# Set appropriate permissions for the application directory
|
31 |
+
RUN chown -R "$USER_ID:$USER_GROUP" /app && chmod -R 755 /app
|
32 |
|
33 |
+
# Install gosu (adjust the package manager based on your base image)
|
34 |
+
RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*
|
35 |
|
36 |
+
# Set the entrypoint script as executable
|
37 |
+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
38 |
+
RUN chmod +x /usr/local/bin/entrypoint.sh
|
39 |
|
40 |
+
# Switch to the user for improved security
|
41 |
+
USER "$USER_ID:$USER_GROUP"
|
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"]
|