Skip to content

Commit 2fabeb1

Browse files
authored
Refactor: pems_web package (#181)
2 parents f990e96 + 2b87130 commit 2fabeb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+541
-254
lines changed

.devcontainer/Dockerfile

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
1-
FROM caltrans/pems:web
1+
ARG PYTHON_VERSION=3.12
22

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
341
COPY . .
442

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+
552
# install devcontainer requirements
653
RUN pip install -e .[dev,test]
754

@@ -10,16 +57,3 @@ RUN pip install --no-cache-dir -r docs/requirements.txt
1057

1158
# install streamlit requirements
1259
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

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DJANGO_DB_RESET=true
88
DJANGO_DB_NAME=django
99
DJANGO_DB_USER=django
1010
DJANGO_DB_PASSWORD=django_password
11-
DJANGO_DB_FIXTURES="pems/local_fixtures.json"
11+
DJANGO_DB_FIXTURES=pems_web/src/pems_web/local_fixtures.json
1212

1313
# PostgreSQL settings
1414
POSTGRES_HOSTNAME=postgres

.github/workflows/deploy-troubleshoot.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,11 @@ jobs:
2424
cache: pip
2525
cache-dependency-path: "**/pyproject.toml"
2626

27-
- name: Write python packages to file
28-
run: |
29-
python -m venv .venv
30-
source .venv/bin/activate
31-
pip install pipdeptree
32-
pip install -e .
33-
mkdir -p pems/static
34-
pipdeptree
35-
pipdeptree >> pems/static/requirements.txt
36-
3727
- name: Write commit SHA to file
38-
run: echo "${{ github.sha }}" >> pems/static/sha.txt
28+
run: echo "${{ github.sha }}" >> pems_web/src/pems_web/static/sha.txt
3929

4030
- name: Write tag to file
41-
run: echo "${{ github.ref_name }}" >> pems/static/version.txt
31+
run: echo "${{ github.ref_name }}" >> pems_web/src/pems_web/static/version.txt
4232

4333
- name: Configure AWS Credentials
4434
uses: aws-actions/configure-aws-credentials@v4

.github/workflows/deploy.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,11 @@ jobs:
5050
cache: pip
5151
cache-dependency-path: "**/pyproject.toml"
5252

53-
- name: Write python packages to file
54-
run: |
55-
python -m venv .venv
56-
source .venv/bin/activate
57-
pip install pipdeptree
58-
pip install -e .
59-
mkdir -p pems/static
60-
pipdeptree
61-
pipdeptree >> pems/static/requirements.txt
62-
6353
- name: Write commit SHA to file
64-
run: echo "${{ github.sha }}" >> pems/static/sha.txt
54+
run: echo "${{ github.sha }}" >> pems_web/src/pems_web/static/sha.txt
6555

6656
- name: Write tag to file
67-
run: echo "${{ github.ref_name }}" >> pems/static/version.txt
57+
run: echo "${{ github.ref_name }}" >> pems_web/src/pems_web/static/version.txt
6858

6959
- name: Configure AWS Credentials
7060
uses: aws-actions/configure-aws-credentials@v4

.github/workflows/tests-pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/upload-artifact@v4
3636
with:
3737
name: coverage-report
38-
path: pems/static/coverage
38+
path: static/coverage
3939

4040
- name: Coverage comment
4141
uses: py-cov-action/python-coverage-comment-action@v3

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*.tmp
66
*.egg-info
77
static/
8-
!pems/static
8+
!pems_web/src/pems_web/static
99
__pycache__/
1010
.coverage
1111
.DS_Store

bin/makemigrations.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ python manage.py makemigrations
77

88
# reformat with black
99

10-
python -m black pems/districts/migrations/*.py
10+
python -m black pems_web/src/pems_web/**/migrations/*.py

bin/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ nginx
1111

1212
# start the application server
1313

14-
python -m gunicorn -c $GUNICORN_CONF pems.wsgi
14+
python -m gunicorn -c $GUNICORN_CONF pems_web.wsgi

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
web:
55
build:
66
context: .
7-
dockerfile: appcontainer/Dockerfile
7+
dockerfile: pems_web/container/Dockerfile
88
image: caltrans/pems:web
99
command: ["-c", "bin/setup.sh && exec bin/start.sh"]
1010
depends_on:

infra/copilot/web/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ http:
1818
image:
1919
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#image-build
2020
build:
21-
dockerfile: ../appcontainer/Dockerfile
21+
dockerfile: ../pems_web/container/Dockerfile
2222
context: ../
2323
# Port exposed through your container to route traffic to it.
2424
port: 8000

0 commit comments

Comments
 (0)