Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 0212fd2

Browse files
authored
Feat: set up devcontainer (#22)
2 parents 064fdb7 + b002691 commit 0212fd2

File tree

8 files changed

+119
-0
lines changed

8 files changed

+119
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG PYTHON_VERSION=3.12
2+
3+
FROM python:${PYTHON_VERSION}
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
USER=caltrans
8+
9+
# create non-root $USER and home directory
10+
RUN useradd --create-home --shell /bin/bash $USER && \
11+
chown -R $USER /home/$USER
12+
13+
# switch to $USER
14+
USER $USER
15+
16+
# enter src directory
17+
WORKDIR /home/$USER/src
18+
19+
# update PATH for local pip installs
20+
ENV PATH="$PATH:/home/$USER/.local/bin"
21+
22+
# upgrade pip
23+
RUN python -m pip install --upgrade pip
24+
25+
# copy assets
26+
COPY . .
27+
28+
# install devcontainer requirements
29+
RUN pip install --no-cache-dir -r .devcontainer/requirements.txt
30+
31+
# install pre-commit environments in throwaway Git repository
32+
# https://stackoverflow.com/a/68758943
33+
RUN git init . && \
34+
pre-commit install-hooks && \
35+
rm -rf .git
36+
37+
CMD sleep infinity
38+
39+
ENTRYPOINT []

.devcontainer/devcontainer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "caltrans/pems",
3+
"dockerComposeFile": ["../compose.yml"],
4+
"service": "dev",
5+
"runServices": ["dev"],
6+
"workspaceFolder": "/home/caltrans/src",
7+
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"],
8+
"customizations": {
9+
"vscode": {
10+
// Set *default* container specific settings.json values on container create.
11+
"settings": {
12+
"terminal.integrated.defaultProfile.linux": "bash",
13+
"terminal.integrated.profiles.linux": {
14+
"bash": {
15+
"path": "/bin/bash"
16+
}
17+
}
18+
},
19+
// Add the IDs of extensions you want installed when the container is created.
20+
"extensions": [
21+
"eamodio.gitlens",
22+
"esbenp.prettier-vscode",
23+
"mhutchie.git-graph"
24+
]
25+
}
26+
}
27+
}

.devcontainer/postAttach.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
# initialize pre-commit
5+
git config --global --add safe.directory /home/$USER/src
6+
pre-commit install --overwrite

.devcontainer/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pre-commit

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git/

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ci:
2+
autofix_commit_msg: "chore(pre-commit): autofix run"
3+
autoupdate_commit_msg: "chore(pre-commit): autoupdate hooks"
4+
5+
default_install_hook_types:
6+
- pre-commit
7+
- commit-msg
8+
9+
repos:
10+
- repo: https://github.com/compilerla/conventional-pre-commit
11+
rev: v3.6.0
12+
hooks:
13+
- id: conventional-pre-commit
14+
stages: [commit-msg]
15+
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v5.0.0
18+
hooks:
19+
- id: check-added-large-files
20+
- id: check-merge-conflict
21+
- id: check-yaml
22+
args: [--unsafe]
23+
- id: end-of-file-fixer
24+
- id: fix-byte-order-marker
25+
- id: mixed-line-ending
26+
- id: trailing-whitespace

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"files.encoding": "utf8",
5+
"files.eol": "\n",
6+
"files.insertFinalNewline": true,
7+
"files.trimFinalNewlines": true,
8+
"files.trimTrailingWhitespace": true
9+
}

compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: pems
2+
3+
services:
4+
dev:
5+
build:
6+
context: .
7+
dockerfile: .devcontainer/Dockerfile
8+
image: caltrans/pems:main
9+
volumes:
10+
- ./:/home/caltrans/src

0 commit comments

Comments
 (0)