dsmueller commited on
Commit
e491e2f
·
1 Parent(s): 314c1af

Updated order of operations

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -38
Dockerfile CHANGED
@@ -1,11 +1,7 @@
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.11.5-bookworm
3
 
4
- # Do root things: clone repo and install dependencies. libsndfile1 for spotlight. libhdf5-serial-dev for vector distance.
5
- # USER root
6
-
7
- RUN useradd -m -u 1000 user && chown -R user:user /home/user && chmod -R 777 /home/user
8
-
9
  RUN apt-get update && apt-get install -y \
10
  libhdf5-serial-dev \
11
  libsndfile1 \
@@ -13,65 +9,56 @@ RUN apt-get update && apt-get install -y \
13
  git \
14
  && rm -rf /var/lib/apt/lists/*
15
 
 
 
 
 
16
  USER user
17
 
18
- # Set home to the user's home directory
19
  ENV HOME=/home/user \
20
- PATH=/home/user/.local/bin:$PATH
21
  WORKDIR $HOME
22
 
23
- # Create directories for the app code to be copied into
24
- RUN mkdir $HOME/app
25
- RUN mkdir $HOME/config
26
- RUN mkdir $HOME/db
27
- RUN mkdir $HOME/src
28
-
29
- # Give all users read/write permissions to the app code directories
30
- RUN chmod 777 $HOME/app
31
- RUN chmod 777 $HOME/config
32
- RUN chmod 777 $HOME/db
33
- RUN chmod 777 $HOME/src
34
 
35
  # Set environment variables
36
  ENV PATH="$HOME/.venv/bin:$PATH"
37
 
38
- # Install Poetry and configure it to install to a user-writable location
39
  RUN curl -sSL https://install.python-poetry.org | python3 - \
40
  && poetry config virtualenvs.create true \
41
  && poetry config cache-dir /home/user/.cache/poetry \
42
  && poetry config virtualenvs.path /home/user/.local/share/virtualenvs
43
 
44
- # Clone the repository instead of copying files
45
- RUN git clone https://github.com/dan-s-mueller/aerospace_chatbot.git /tmp/aerospace_chatbot
46
-
47
- # Copy Poetry files from the cloned repo and install dependencies
48
- COPY --chown=user:user /tmp/aerospace_chatbot/pyproject.toml /tmp/aerospace_chatbot/poetry.lock ./
49
- RUN python3 -m pip install --user --no-warn-script-location poetry \
50
- && poetry config virtualenvs.in-project true \
51
- && poetry install --no-interaction --no-ansi
52
-
53
- # Copy the files from the cloned repo to the appropriate locations
54
- RUN cp -r /tmp/aerospace_chatbot/app/* $HOME/app/ && \
55
  cp -r /tmp/aerospace_chatbot/config/* $HOME/config/ && \
56
  cp -r /tmp/aerospace_chatbot/db/* $HOME/db/ && \
57
  cp -r /tmp/aerospace_chatbot/src/* $HOME/src/ && \
 
 
 
58
  rm -rf /tmp/aerospace_chatbot
59
 
60
- # Set up run env variables.
61
  ENV LOCAL_DB_PATH=$HOME/db
62
  ENV AEROSPACE_CHATBOT_CONFIG='admin'
63
  ENV PYTHONPATH=$HOME/src:$PYTHONPATH
64
 
65
- # Set final work directory for the application
66
  WORKDIR $HOME/app
67
- RUN pwd
68
- RUN ls -R
69
 
70
- # Expose the port Streamlit runs on
71
- EXPOSE 8501
72
 
73
- # The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.
 
74
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
75
 
76
- # An ENTRYPOINT allows you to configure a container that will run as an executable.
77
  ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.11.5-bookworm
3
 
4
+ # Install system dependencies first
 
 
 
 
5
  RUN apt-get update && apt-get install -y \
6
  libhdf5-serial-dev \
7
  libsndfile1 \
 
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # Create user and set up directories
13
+ RUN useradd -m -u 1000 user && chown -R user:user /home/user && chmod -R 777 /home/user
14
+
15
+ # Switch to user
16
  USER user
17
 
18
+ # Set home and working directory
19
  ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
  WORKDIR $HOME
22
 
23
+ # Create and set permissions for directories
24
+ RUN mkdir -p $HOME/app $HOME/config $HOME/db $HOME/src && \
25
+ chmod 777 $HOME/app $HOME/config $HOME/db $HOME/src
 
 
 
 
 
 
 
 
26
 
27
  # Set environment variables
28
  ENV PATH="$HOME/.venv/bin:$PATH"
29
 
30
+ # Install Poetry
31
  RUN curl -sSL https://install.python-poetry.org | python3 - \
32
  && poetry config virtualenvs.create true \
33
  && poetry config cache-dir /home/user/.cache/poetry \
34
  && poetry config virtualenvs.path /home/user/.local/share/virtualenvs
35
 
36
+ # Clone repo and set up project
37
+ RUN git clone https://github.com/dan-s-mueller/aerospace_chatbot.git /tmp/aerospace_chatbot && \
38
+ cp /tmp/aerospace_chatbot/pyproject.toml /tmp/aerospace_chatbot/poetry.lock ./ && \
39
+ cp -r /tmp/aerospace_chatbot/app/* $HOME/app/ && \
 
 
 
 
 
 
 
40
  cp -r /tmp/aerospace_chatbot/config/* $HOME/config/ && \
41
  cp -r /tmp/aerospace_chatbot/db/* $HOME/db/ && \
42
  cp -r /tmp/aerospace_chatbot/src/* $HOME/src/ && \
43
+ python3 -m pip install --user --no-warn-script-location poetry && \
44
+ poetry config virtualenvs.in-project true && \
45
+ poetry install --no-interaction --no-ansi && \
46
  rm -rf /tmp/aerospace_chatbot
47
 
48
+ # Set up run env variables
49
  ENV LOCAL_DB_PATH=$HOME/db
50
  ENV AEROSPACE_CHATBOT_CONFIG='admin'
51
  ENV PYTHONPATH=$HOME/src:$PYTHONPATH
52
 
53
+ # Set final work directory
54
  WORKDIR $HOME/app
 
 
55
 
56
+ # Debug commands
57
+ RUN pwd && ls -R
58
 
59
+ # Expose port and set health check
60
+ EXPOSE 8501
61
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
62
 
63
+ # Set entrypoint
64
  ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]