File size: 1,608 Bytes
1984ccf
 
3658992
f9900a1
 
c0e77ac
f9900a1
 
c0e77ac
7b8fd64
 
934aa4a
 
 
 
0c91ad6
 
 
 
934aa4a
 
8d7f247
934aa4a
1130934
23aa172
 
 
 
8d7f247
23aa172
 
1130934
23aa172
 
1130934
23aa172
 
8d7f247
 
 
 
23aa172
 
649c393
f877332
23aa172
0c91ad6
23aa172
 
 
649c393
28175d8
 
0c91ad6
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Use the base Docker image with necessary dependencies
FROM circulartextapp/spaceread as base

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Define the user ID in the environment variable USER_ID with a default value
ARG USER_ID=1000
ENV USER_ID=$USER_ID

# Check if the user already exists
RUN if id "$USER_ID" >/dev/null 2>&1; then \
    echo "User with ID $USER_ID already exists."; \
else \
    useradd -m -u "$USER_ID" user; \
fi

# Set appropriate permissions for the application directory
RUN chown -R user:user /app && chmod -R 755 /app

# Install build tools
RUN mkdir -p /var/lib/apt/lists/partial && \
    chmod 744 /var/lib/apt/lists && \
    chmod 755 /var/lib/apt/lists/partial && \
    apt-get update && apt-get install -y build-essential

# Switch to the user for improved security
USER user

# Intermediate image with additional packages
FROM debian:bullseye-slim as packages

# Install gosu using apt-get
RUN apt-get update && apt-get install -y gosu && rm -rf /var/lib/apt/lists/*

# Final image
FROM base

# Copy gosu from the packages image
COPY --from=packages /usr/sbin/gosu /usr/sbin/gosu

# Set the entrypoint script as executable
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN sudo chmod +x /usr/local/bin/entrypoint.sh

# Define the entrypoint script to handle user creation and application startup
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# Default command to run if the user doesn't provide a command
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]