-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
84 lines (65 loc) · 2.64 KB
/
Dockerfile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Use an official Python runtime as a parent image
FROM python:3.11.5-bookworm
# Do root things: clone repo and install dependencies. libsndfile1 for spotlight. libhdf5-serial-dev for vector distance.
# USER root
RUN useradd -m -u 1000 user && chown -R user:user /home/user && chmod -R 777 /home/user
# Install sudo and add user to sudoers before switching to non-root
RUN apt-get update && apt-get install -y sudo && \
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER user
# Set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME
# Use sudo for apt-get commands
RUN sudo apt-get update && sudo apt-get install -y \
libhdf5-serial-dev \
libsndfile1 \
curl \
&& sudo rm -rf /var/lib/apt/lists/*
# USER user
# # Set home to the user's home directory
# ENV HOME=/home/user \
# PATH=/home/user/.local/bin:$PATH
# WORKDIR $HOME
# Create directories for the app code to be copied into
RUN mkdir $HOME/app
RUN mkdir $HOME/config
RUN mkdir $HOME/db
RUN mkdir $HOME/src
# Give all users read/write permissions to the app code directories
RUN chmod 777 $HOME/app
RUN chmod 777 $HOME/config
RUN chmod 777 $HOME/db
RUN chmod 777 $HOME/src
# Set environment variables
ENV PATH="$HOME/.venv/bin:$PATH"
# Install Poetry and configure it to install to a user-writable location
RUN curl -sSL https://install.python-poetry.org | python3 - \
&& poetry config virtualenvs.create true \
&& poetry config cache-dir /home/user/.cache/poetry \
&& poetry config virtualenvs.path /home/user/.local/share/virtualenvs
# Copy Poetry files and install dependencies with correct permissions
COPY --chown=user:user pyproject.toml poetry.lock ./
RUN python3 -m pip install --user --no-warn-script-location poetry \
&& poetry config virtualenvs.in-project true \
&& poetry install --no-interaction --no-ansi
# Copy the rest of your application code.
COPY --chown=user:user ./app $HOME/app
COPY --chown=user:user ./config $HOME/config
# COPY --chown=user:user ./db $HOME/db
COPY --chown=user:user ./src $HOME/src
# Set up run env variables.
ENV LOCAL_DB_PATH=$HOME/db
ENV AEROSPACE_CHATBOT_CONFIG='admin'
ENV PYTHONPATH=$HOME/src:$PYTHONPATH
# Set final work directory for the application
WORKDIR $HOME/app
RUN pwd
RUN ls -R
# Expose the port Streamlit runs on
EXPOSE 8501
# The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
# An ENTRYPOINT allows you to configure a container that will run as an executable.
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]