seanpedrickcase commited on
Commit
3f9e976
1 Parent(s): 1cfa6e8

Updated Dockerfile and requirements to include relevant Lambda packages

Browse files
Files changed (3) hide show
  1. Dockerfile +38 -22
  2. Dockerfile_old +82 -0
  3. requirements.txt +1 -0
Dockerfile CHANGED
@@ -1,8 +1,17 @@
 
 
 
1
  # Stage 1: Build dependencies and download models
2
  FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm AS builder
3
 
4
  # Install system dependencies. Need to specify -y for poppler to get it to install
5
  RUN apt-get update \
 
 
 
 
 
 
6
  && apt-get clean \
7
  && rm -rf /var/lib/apt/lists/*
8
 
@@ -20,10 +29,7 @@ COPY lambda_entrypoint.py .
20
  # Stage 2: Final runtime image
21
  FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm
22
 
23
- # Install Lambda web adapter in case you want to run with with an AWS Lamba function URL (not essential if not using Lambda)
24
- COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
25
-
26
- # Install system dependencies. Need to specify -y for poppler to get it to install
27
  RUN apt-get update \
28
  && apt-get install -y \
29
  tesseract-ocr \
@@ -36,11 +42,11 @@ RUN apt-get update \
36
  # Set up a new user named "user" with user ID 1000
37
  RUN useradd -m -u 1000 user
38
 
39
- # Make output folder
40
  RUN mkdir -p /home/user/app/output \
41
- && mkdir -p /home/user/app/tld \
42
- && mkdir -p /home/user/app/logs \
43
- && chown -R user:user /home/user/app
44
 
45
  # Copy installed packages from builder stage
46
  COPY --from=builder /install /usr/local/lib/python3.11/site-packages/
@@ -50,25 +56,35 @@ USER user
50
 
51
  # Set environmental variables
52
  ENV HOME=/home/user \
53
- PATH=/home/user/.local/bin:$PATH \
54
  PYTHONPATH=/home/user/app \
55
- PYTHONUNBUFFERED=1 \
56
  PYTHONDONTWRITEBYTECODE=1 \
57
- GRADIO_ALLOW_FLAGGING=never \
58
- GRADIO_NUM_PORTS=1 \
59
- GRADIO_SERVER_NAME=0.0.0.0 \
60
- GRADIO_SERVER_PORT=7860 \
61
- GRADIO_THEME=huggingface \
62
- TLDEXTRACT_CACHE=$HOME/app/tld/.tld_set_snapshot \
63
- SYSTEM=spaces
64
-
65
  # Set the working directory to the user's home directory
66
  WORKDIR $HOME/app
67
 
68
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
69
  COPY --chown=user . $HOME/app
70
 
71
- # Keep the default entrypoint as flexible
72
- ENTRYPOINT ["python", "-u", "lambda_entrypoint.py"]
 
 
 
 
 
 
 
 
 
73
 
74
- #CMD ["python", "app.py"]
 
 
1
+ # Define a build argument for the mode (gradio or lambda)
2
+ ARG APP_MODE=gradio
3
+
4
  # Stage 1: Build dependencies and download models
5
  FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm AS builder
6
 
7
  # Install system dependencies. Need to specify -y for poppler to get it to install
8
  RUN apt-get update \
9
+ && apt-get install -y \
10
+ g++ \
11
+ make \
12
+ cmake \
13
+ unzip \
14
+ libcurl4-openssl-dev \
15
  && apt-get clean \
16
  && rm -rf /var/lib/apt/lists/*
17
 
 
29
  # Stage 2: Final runtime image
30
  FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm
31
 
32
+ # Install system dependencies
 
 
 
33
  RUN apt-get update \
34
  && apt-get install -y \
35
  tesseract-ocr \
 
42
  # Set up a new user named "user" with user ID 1000
43
  RUN useradd -m -u 1000 user
44
 
45
+ # Create required directories
46
  RUN mkdir -p /home/user/app/output \
47
+ && mkdir -p /home/user/app/tld \
48
+ && mkdir -p /home/user/app/logs \
49
+ && chown -R user:user /home/user/app
50
 
51
  # Copy installed packages from builder stage
52
  COPY --from=builder /install /usr/local/lib/python3.11/site-packages/
 
56
 
57
  # Set environmental variables
58
  ENV HOME=/home/user \
59
+ PATH=/home/user/.local/bin:$PATH \
60
  PYTHONPATH=/home/user/app \
61
+ PYTHONUNBUFFERED=1 \
62
  PYTHONDONTWRITEBYTECODE=1 \
63
+ GRADIO_ALLOW_FLAGGING=never \
64
+ GRADIO_NUM_PORTS=1 \
65
+ GRADIO_SERVER_NAME=0.0.0.0 \
66
+ GRADIO_SERVER_PORT=7860 \
67
+ GRADIO_THEME=huggingface \
68
+ TLDEXTRACT_CACHE=$HOME/app/tld/.tld_set_snapshot \
69
+ SYSTEM=spaces
70
+
71
  # Set the working directory to the user's home directory
72
  WORKDIR $HOME/app
73
 
74
+ # Copy the app code to the container
75
  COPY --chown=user . $HOME/app
76
 
77
+ # Default entrypoint (can be overridden by build argument)
78
+ ARG APP_MODE=gradio
79
+
80
+ # Use a conditional entrypoint based on the APP_MODE argument
81
+ RUN if [ "$APP_MODE" = "gradio" ]; then \
82
+ echo '#!/bin/sh\nexec python app.py' > /entrypoint.sh; \
83
+ else \
84
+ echo '#!/bin/sh\nexec python -m awslambdaric' > /entrypoint.sh; \
85
+ fi && chmod +x /entrypoint.sh
86
+
87
+ ENTRYPOINT [ "/entrypoint.sh" ]
88
 
89
+ # Default command for Lambda mode
90
+ CMD [ "lambda_entrypoint.lambda_handler" ]
Dockerfile_old ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Define custom function directory as root
2
+ ARG FUNCTION_DIR=""
3
+
4
+ # Stage 1: Build dependencies and download models
5
+ FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm AS builder
6
+
7
+ # Install system dependencies. Need to specify -y for poppler to get it to install
8
+ RUN apt-get update \
9
+ && apt-get clean \
10
+ && g++ \
11
+ && make \
12
+ && cmake \
13
+ && unzip \
14
+ && libcurl4-openssl-dev \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ WORKDIR /src
18
+
19
+ COPY requirements.txt .
20
+
21
+ RUN pip install --no-cache-dir --target=/install -r requirements.txt
22
+
23
+ RUN rm requirements.txt
24
+
25
+ # Add lambda_entrypoint.py to the container
26
+ COPY lambda_entrypoint.py .
27
+
28
+ # Stage 2: Final runtime image
29
+ FROM public.ecr.aws/docker/library/python:3.11.9-slim-bookworm
30
+
31
+ # Install Lambda web adapter in case you want to run with with an AWS Lamba function URL (not essential if not using Lambda)
32
+ COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
33
+
34
+ # Install system dependencies. Need to specify -y for poppler to get it to install
35
+ RUN apt-get update \
36
+ && apt-get install -y \
37
+ tesseract-ocr \
38
+ poppler-utils \
39
+ libgl1-mesa-glx \
40
+ libglib2.0-0 \
41
+ && apt-get clean \
42
+ && rm -rf /var/lib/apt/lists/*
43
+
44
+ # Set up a new user named "user" with user ID 1000
45
+ RUN useradd -m -u 1000 user
46
+
47
+ # Make output folder
48
+ RUN mkdir -p /home/user/app/output \
49
+ && mkdir -p /home/user/app/tld \
50
+ && mkdir -p /home/user/app/logs \
51
+ && chown -R user:user /home/user/app
52
+
53
+ # Copy installed packages from builder stage
54
+ COPY --from=builder /install /usr/local/lib/python3.11/site-packages/
55
+
56
+ # Switch to the "user" user
57
+ USER user
58
+
59
+ # Set environmental variables
60
+ ENV HOME=/home/user \
61
+ PATH=/home/user/.local/bin:$PATH \
62
+ PYTHONPATH=/home/user/app \
63
+ PYTHONUNBUFFERED=1 \
64
+ PYTHONDONTWRITEBYTECODE=1 \
65
+ GRADIO_ALLOW_FLAGGING=never \
66
+ GRADIO_NUM_PORTS=1 \
67
+ GRADIO_SERVER_NAME=0.0.0.0 \
68
+ GRADIO_SERVER_PORT=7860 \
69
+ GRADIO_THEME=huggingface \
70
+ TLDEXTRACT_CACHE=$HOME/app/tld/.tld_set_snapshot \
71
+ SYSTEM=spaces
72
+
73
+ # Set the working directory to the user's home directory
74
+ WORKDIR $HOME/app
75
+
76
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
77
+ COPY --chown=user . $HOME/app
78
+
79
+ # Keep the default entrypoint as flexible
80
+ ENTRYPOINT ["python", "-u", "lambda_entrypoint.py"]
81
+
82
+ #CMD ["python", "app.py"]
requirements.txt CHANGED
@@ -17,6 +17,7 @@ openpyxl==3.1.2
17
  Faker==22.2.0
18
  gradio_image_annotation==0.2.5
19
  numpy==1.26.4
 
20
 
21
 
22
 
 
17
  Faker==22.2.0
18
  gradio_image_annotation==0.2.5
19
  numpy==1.26.4
20
+ awslambdaric==3.0.0
21
 
22
 
23