1
- FROM caltrans/pems:web
1
+ ARG PYTHON_VERSION=3.12
2
2
3
+ FROM python:${PYTHON_VERSION}
4
+
5
+ WORKDIR /tmp
6
+
7
+ # install AWS CLI and Copilot CLI (requires root permissions)
8
+ # download AWS Copilot CLI to /tmp to avoid write error (23) from curl command
9
+ RUN HOST_ARCH=$(uname -m) && \
10
+ case "$HOST_ARCH" in \
11
+ x86_64) HOST_ARCH="amd64" ;; \
12
+ aarch64) HOST_ARCH="arm64" ;; \
13
+ esac \
14
+ && if [ "$HOST_ARCH" = "amd64" ]; then \
15
+ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" ; \
16
+ elif [ "$HOST_ARCH" = "arm64" ]; then \
17
+ curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" ; \
18
+ fi \
19
+ && unzip awscliv2.zip \
20
+ && ./aws/install \
21
+ && rm -rf aws awscliv2.zip \
22
+ && curl -Lo copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux \
23
+ && chmod +x copilot \
24
+ && mv copilot /usr/local/bin/copilot
25
+
26
+ ENV PYTHONDONTWRITEBYTECODE=1 \
27
+ PYTHONUNBUFFERED=1 \
28
+ USER=caltrans
29
+ ENV RUNTIME_DIR=/$USER/app
30
+
31
+ # create non-root $USER and home directory
32
+ RUN useradd --create-home --shell /bin/bash $USER \
33
+ && apt-get update \
34
+ && apt-get install -qq --no-install-recommends build-essential gettext \
35
+ && python -m pip install --upgrade pip \
36
+ && mkdir -p "$RUNTIME_DIR"
37
+
38
+ WORKDIR /$USER/app
39
+
40
+ # copy source files and update permissions
3
41
COPY . .
4
42
43
+ RUN git config --global --add safe.directory . \
44
+ && chown -R $USER:$USER /$USER
45
+
46
+ # Switch to non-root user
47
+ USER $USER
48
+
49
+ ENV PATH="$PATH:/$USER/.local/bin" \
50
+ PYTHONUSERBASE="/$USER/.local"
51
+
5
52
# install devcontainer requirements
6
53
RUN pip install -e .[dev,test]
7
54
@@ -10,16 +57,3 @@ RUN pip install --no-cache-dir -r docs/requirements.txt
10
57
11
58
# install streamlit requirements
12
59
RUN pip install --no-cache-dir -r streamlit_app/requirements.txt
13
-
14
- # install AWS Copilot CLI (requires root permissions)
15
- USER root
16
- # download AWS Copilot CLI to /tmp to avoid write error (23) from curl command
17
- WORKDIR /tmp
18
-
19
- RUN curl -Lo copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux \
20
- && chmod +x copilot \
21
- && mv copilot /usr/local/bin/copilot
22
-
23
- # Switch back to non-root user and app directory
24
- USER $USER
25
- WORKDIR /$USER/app
0 commit comments