-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): devcontainer image + compose service
project config for python development basic pytest setup
- Loading branch information
1 parent
67cea0c
commit 36878be
Showing
18 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM cdt/ddrc:app | ||
|
||
COPY . . | ||
|
||
# install devcontainer requirements | ||
RUN pip install -e .[dev,test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "cdt/ddrc", | ||
"dockerComposeFile": ["../compose.yml"], | ||
"service": "dev", | ||
"runServices": ["dev"], | ||
"workspaceFolder": "/cdt/app", | ||
"postStartCommand": ["/bin/bash", "bin/reset_db.sh"], | ||
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"], | ||
"customizations": { | ||
"vscode": { | ||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"terminal.integrated.defaultProfile.linux": "bash", | ||
"terminal.integrated.profiles.linux": { | ||
"bash": { | ||
"path": "/bin/bash" | ||
} | ||
} | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"batisteo.vscode-django", | ||
"bpruitt-goddard.mermaid-markdown-syntax-highlighting", | ||
"DavidAnson.vscode-markdownlint", | ||
"eamodio.gitlens", | ||
"esbenp.prettier-vscode", | ||
"mhutchie.git-graph", | ||
"monosans.djlint", | ||
"ms-python.python", | ||
"ms-python.black-formatter", | ||
"ms-python.flake8", | ||
"qwtel.sqlite-viewer", | ||
"tamasfe.even-better-toml" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -eux | ||
|
||
# initialize pre-commit | ||
git config --global --add safe.directory /$USER/app | ||
pre-commit install --install-hooks --overwrite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
DJANGO_LOCAL_PORT=8000 | ||
|
||
# Django superuser account for backend admin access | ||
DJANGO_SUPERUSER_USERNAME=ddrc-admin | ||
DJANGO_SUPERUSER_EMAIL=[email protected] | ||
DJANGO_SUPERUSER_PASSWORD=superuser12345! | ||
|
||
# Django storage | ||
DJANGO_DB_FILE=django.db | ||
DJANGO_DB_RESET=true | ||
DJANGO_STORAGE_DIR=. | ||
DJANGO_DB_FILE=django.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 127 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ci: | ||
autofix_commit_msg: "chore(pre-commit): autofix run" | ||
autoupdate_commit_msg: "chore(pre-commit): autoupdate hooks" | ||
|
||
default_install_hook_types: | ||
- pre-commit | ||
- commit-msg | ||
|
||
repos: | ||
- repo: https://github.com/compilerla/conventional-pre-commit | ||
rev: v4.0.0 | ||
hooks: | ||
- id: conventional-pre-commit | ||
stages: [commit-msg] | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-merge-conflict | ||
- id: check-yaml | ||
args: [--unsafe] | ||
- id: end-of-file-fixer | ||
- id: fix-byte-order-marker | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Django: DDRC Client", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/manage.py", | ||
"args": ["runserver", "--insecure", "0.0.0.0:8000"], | ||
"django": true, | ||
"env": { | ||
"DJANGO_DEBUG": "true", | ||
"PYTHONWARNINGS": "default" | ||
} | ||
}, | ||
{ | ||
"name": "Django: DDRC Client, Debug=False", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/manage.py", | ||
"args": ["runserver", "--insecure", "0.0.0.0:8000"], | ||
"django": true, | ||
"env": { | ||
"DJANGO_DEBUG": "false", | ||
"DJANGO_STATICFILES_STORAGE": "django.contrib.staticfiles.storage.StaticFilesStorage" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"[django-html][html]": { | ||
"editor.defaultFormatter": "monosans.djlint", | ||
"djlint.enableLinting": true, | ||
"djlint.profile": "django" | ||
}, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"files.associations": { | ||
".pages": "yaml" | ||
}, | ||
"files.encoding": "utf8", | ||
"files.eol": "\n", | ||
"files.insertFinalNewline": true, | ||
"files.trimFinalNewlines": true, | ||
"files.trimTrailingWhitespace": true, | ||
"[markdown]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter" | ||
}, | ||
"[toml]": { | ||
"editor.defaultFormatter": "tamasfe.even-better-toml" | ||
}, | ||
"python.languageServer": "Pylance", | ||
"python.testing.pytestArgs": ["tests/pytest"], | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.unittestEnabled": false, | ||
"workbench.editorAssociations": { | ||
"*.db": "sqlite-viewer.option" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
set -eux | ||
|
||
docker compose build app | ||
|
||
docker compose build dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
# whether to reset database file, defaults to true | ||
DB_RESET="${DJANGO_DB_RESET:-true}" | ||
|
||
if [[ $DB_RESET = true ]]; then | ||
# construct the path to the database file from environment or default | ||
DB_DIR="${DJANGO_STORAGE_DIR:-.}" | ||
DB_FILE="${DJANGO_DB_FILE:-django.db}" | ||
DB_PATH="${DB_DIR}/${DB_FILE}" | ||
|
||
rm -f "${DB_PATH}" | ||
|
||
# run database migrations and other initialization | ||
bin/init.sh | ||
|
||
# create a superuser account for backend admin access | ||
# set username, email, and password using environment variables | ||
# DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL, and DJANGO_SUPERUSER_PASSWORD | ||
python manage.py createsuperuser --no-input | ||
else | ||
echo "DB_RESET is false, skipping" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,31 @@ requires-python = ">=3.12" | |
maintainers = [{ name = "Compiler LLC", email = "[email protected]" }] | ||
dependencies = ["Django==5.1.4", "gunicorn==23.0.0"] | ||
|
||
[project.optional-dependencies] | ||
dev = ["black", "djlint", "flake8", "pre-commit", "setuptools_scm>=8"] | ||
test = ["coverage", "pytest", "pytest-django", "pytest-mock", "pytest-socket"] | ||
|
||
[project.urls] | ||
Code = "https://github.com/compilerla/ddrc" | ||
Issues = "https://github.com/compilerla/ddrc/issues" | ||
|
||
[build-system] | ||
requires = ["setuptools>=75", "setuptools_scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.black] | ||
line-length = 127 | ||
target-version = ["py312"] | ||
include = '\.pyi?$' | ||
|
||
[tool.coverage.run] | ||
branch = true | ||
relative_files = true | ||
source = ["web"] | ||
|
||
[tool.pytest.ini_options] | ||
DJANGO_SETTINGS_MODULE = "web.settings" | ||
|
||
[tool.setuptools.packages.find] | ||
include = ["web*"] | ||
namespaces = false | ||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pytest_socket import disable_socket | ||
|
||
|
||
def pytest_runtest_setup(): | ||
disable_socket() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from web.core.middleware import HEALTHCHECK_PATH | ||
|
||
|
||
def test_healthcheck(client): | ||
response = client.get(HEALTHCHECK_PATH) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# run normal pytests | ||
coverage run -m pytest | ||
|
||
# clean out old coverage results | ||
rm -rf app/static/coverage | ||
|
||
coverage html --directory app/static/coverage |