From 9a2aba1a8e5dae3aab23950f663dca9051bf5a7a Mon Sep 17 00:00:00 2001 From: Scott Cranfill Date: Wed, 3 Jun 2026 15:26:40 -0400 Subject: [PATCH 1/2] feat: Update dev container - Build from app container - Add debugging/testing support in VS Code - Add Python code quality tooling --- .devcontainer/Dockerfile | 40 ++++++++--------------- .devcontainer/devcontainer.json | 21 +++++++++--- .devcontainer/devcontainer.pre-built.json | 26 --------------- .devcontainer/postAttach.sh | 6 ---- .devcontainer/postCreate.sh | 9 +++++ .devcontainer/requirements.txt | 4 +++ .flake8 | 2 ++ .pre-commit-config.yaml | 1 + .vscode/launch.json | 19 +++++++++++ .vscode/settings.json | 11 ++++++- compose.yml | 14 ++++---- pyproject.toml | 17 ++++++++++ 12 files changed, 100 insertions(+), 70 deletions(-) delete mode 100644 .devcontainer/devcontainer.pre-built.json delete mode 100644 .devcontainer/postAttach.sh create mode 100644 .devcontainer/postCreate.sh create mode 100644 .flake8 create mode 100644 .vscode/launch.json create mode 100644 pyproject.toml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index bb9e11e..dba8a9b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,42 +1,30 @@ -ARG PYTHON_VERSION=3.11 +FROM slackronyms:latest -FROM python:${PYTHON_VERSION} +# should match the version specified in terraform/pipeline/deploy.yml +ENV TF_VERSION="1.14.5" -ENV PYTHONDONTWRITEBYTECODE=1 \ - PYTHONUNBUFFERED=1 \ - USER=compiler +# switch to root for package installation +USER root -# create non-root $USER and home directory -RUN useradd --create-home --shell /bin/bash $USER && \ - chown -R $USER /home/$USER +# install system packages that don't come preinstalled on Alpine +RUN apk add git \ + nodejs \ + npm -# switch to $USER +# switch back 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 +# install devcontainer requirements (azure-cli and pre-commit) +COPY .devcontainer/requirements.txt .devcontainer/requirements.txt RUN pip install --no-cache-dir -r .devcontainer/requirements.txt # install docs requirements +COPY docs/requirements.txt docs/requirements.txt RUN pip install --no-cache-dir -r docs/requirements.txt # install pre-commit environments in throwaway Git repository # https://stackoverflow.com/a/68758943 +COPY .pre-commit-config.yaml . RUN git init . && \ pre-commit install-hooks && \ rm -rf .git - -CMD sleep infinity - -ENTRYPOINT [] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d1f7668..53ca2c4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,16 @@ { - "name": "compilerla/template-devcontainer", + "name": "slackronyms", "dockerComposeFile": ["../compose.yml"], "service": "dev", - "runServices": ["dev", "docs"], - "workspaceFolder": "/home/compiler/src", - "postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"], + "runServices": [ + "dev", + "docs" + ], + "workspaceFolder": "/compiler/app", + "postCreateCommand": [ + "/bin/bash", + ".devcontainer/postCreate.sh" + ], "customizations": { "vscode": { // Set *default* container specific settings.json values on container create. @@ -22,7 +28,12 @@ "DavidAnson.vscode-markdownlint", "eamodio.gitlens", "esbenp.prettier-vscode", - "mhutchie.git-graph" + "mhutchie.git-graph", + "ms-python.black-formatter", + "ms-python.isort", + "ms-python.flake8", + "ms-python.python", + "tombi-toml.tombi" ] } } diff --git a/.devcontainer/devcontainer.pre-built.json b/.devcontainer/devcontainer.pre-built.json deleted file mode 100644 index 06faa75..0000000 --- a/.devcontainer/devcontainer.pre-built.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "compilerla/template-devcontainer-pre-built", - "image": "ghcr.io/compilerla/template-devcontainer:main", - "postAttachCommand": "pre-commit install --overwrite", - "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": [ - "bpruitt-goddard.mermaid-markdown-syntax-highlighting", - "DavidAnson.vscode-markdownlint", - "eamodio.gitlens", - "esbenp.prettier-vscode", - "mhutchie.git-graph" - ] - } - } -} diff --git a/.devcontainer/postAttach.sh b/.devcontainer/postAttach.sh deleted file mode 100644 index 2e748e6..0000000 --- a/.devcontainer/postAttach.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -eux - -# initialize pre-commit -git config --global --add safe.directory /home/$USER/src -pre-commit install --overwrite diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100644 index 0000000..cfd23a3 --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -eux + +# initialize hook environments +git config --global --add safe.directory /$USER/app +pre-commit install --install-hooks --overwrite + +# manage commit-msg hooks +pre-commit install --hook-type commit-msg diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt index 416634f..2c24905 100644 --- a/.devcontainer/requirements.txt +++ b/.devcontainer/requirements.txt @@ -1 +1,5 @@ +black +flake8 +isort pre-commit +pytest diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0fdb3d0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 127 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bfb134d..ef30ada 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,7 @@ repos: rev: v0.48.0 hooks: - id: markdownlint + language_version: system - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0fa3d51 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // 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": "Run Slack Bolt App", + "type": "debugpy", + "request": "launch", + "cwd": "${workspaceFolder}/slackronyms", + "program": "app.py", + "justMyCode": false, + "env": { + "PYTHONWARNINGS": "default" + } + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 712dd86..1837eb8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,14 @@ "files.trimTrailingWhitespace": true, "[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - } + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + } + }, + "python.testing.cwd": "./slackronyms", + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, } diff --git a/compose.yml b/compose.yml index 0251155..0eee2fb 100644 --- a/compose.yml +++ b/compose.yml @@ -12,15 +12,17 @@ services: build: context: . dockerfile: .devcontainer/Dockerfile - image: compilerla/template-devcontainer:main + image: slackronyms:dev + env_file: .env + entrypoint: sleep infinity volumes: - - ./:/home/compiler/src + - ./:/compiler/app docs: - image: compilerla/template-devcontainer:main + image: slackronyms:dev entrypoint: mkdocs - command: serve --dev-addr "0.0.0.0:8000" + command: serve --dev-addr "0.0.0.0:8001" ports: - - "8000" + - "8001" volumes: - - ./:/home/compiler/src + - ./:/compiler/app diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..20e657c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.black] +line-length = 127 +target-version = ['py312'] +include = '\.pyi?$' + +[tool.isort] +profile = "black" +combine_as_imports = true +line_length = 127 +skip_gitignore = true + +[tool.pytest.ini_options] +testpaths = ["tests"] +log_file = "logs/pytest.log" +log_file_level = "DEBUG" +log_format = "%(asctime)s %(levelname)s %(message)s" +log_date_format = "%Y-%m-%d %H:%M:%S" From 44ad0b29ddec00964ddd3b76d13a4142de801132 Mon Sep 17 00:00:00 2001 From: Scott Cranfill Date: Wed, 3 Jun 2026 21:06:49 +0000 Subject: [PATCH 2/2] fix: add openssh-client to dev container Necessary to be able to commit from within it. --- .devcontainer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dba8a9b..d59b649 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,7 +9,8 @@ USER root # install system packages that don't come preinstalled on Alpine RUN apk add git \ nodejs \ - npm + npm \ + openssh-client # switch back to $USER USER $USER