Skip to content

Commit

Permalink
refactor(devcontainer): build on the appcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Dec 9, 2024
1 parent d6ad986 commit 15e2781
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
36 changes: 1 addition & 35 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
ARG PYTHON_VERSION=3.12
FROM caltrans/pems:app

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
USER=caltrans

# create non-root $USER and home directory
RUN useradd --create-home --shell /bin/bash $USER && \
chown -R $USER /home/$USER

# switch to $USER
USER $USER

# enter src directory
WORKDIR /home/$USER/src

# update PATH for local pip installs
ENV PATH="$PATH:/home/$USER/.local/bin"

# upgrade pip
RUN python -m pip install --upgrade pip

# copy assets
COPY . .

# install devcontainer requirements
RUN pip install -e .[dev]

# install docs requirements
RUN pip install --no-cache-dir -r docs/requirements.txt

# install pre-commit environments in throwaway Git repository
# https://stackoverflow.com/a/68758943
RUN git init . && \
pre-commit install-hooks && \
rm -rf .git

CMD sleep infinity

ENTRYPOINT []
2 changes: 1 addition & 1 deletion .devcontainer/postAttach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eux

# initialize pre-commit
git config --global --add safe.directory /home/$USER/src
pre-commit install --overwrite
pre-commit install --install-hooks --overwrite
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ DJANGO_DB_RESET=true
DJANGO_STORAGE_DIR=.
DJANGO_DB_FILE=django.db

# Other Django config
DJANGO_DEBUG=true

# uncomment to start the elasticstack services with compose
# COMPOSE_PROFILES=elasticstack

Expand Down
6 changes: 4 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ services:
build:
context: .
dockerfile: .devcontainer/Dockerfile
image: caltrans/pems:main
image: caltrans/pems:dev
env_file: .env
# https://code.visualstudio.com/docs/remote/create-dev-container#_use-docker-compose
entrypoint: sleep infinity
volumes:
- ./:/home/caltrans/src

docs:
image: caltrans/pems:main
image: caltrans/pems:dev
entrypoint: mkdocs
command: serve --dev-addr "0.0.0.0:8000"
ports:
Expand Down

0 comments on commit 15e2781

Please sign in to comment.