Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
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 \
openssh-client

# 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 []
21 changes: 16 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
],
Comment on lines +10 to +13

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this from postAttachCommand to postCreateCommand after stumbling into this old SO thread that Aidan Feldman had commented on a while ago. I can't recall what minor build issue led me there, but I got past it.

Anyway, a commenter suggested that postCreate would be better since it should only need to run once when the devcontainer is (re)built. This works fine for me, but I admittedly didn't look into it any further to see if there's a reason we wouldn't want to do it post-create.

"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
Expand All @@ -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"
]
}
}
Expand Down
26 changes: 0 additions & 26 deletions .devcontainer/devcontainer.pre-built.json

This file was deleted.

6 changes: 0 additions & 6 deletions .devcontainer/postAttach.sh

This file was deleted.

9 changes: 9 additions & 0 deletions .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
black
flake8
isort
pre-commit
pytest
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 127
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repos:
rev: v0.48.0
hooks:
- id: markdownlint
language_version: system

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a trick needed to get this to install on Alpine (in addition to installing node and npm in the Dockerfile).


- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand Down
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
14 changes: 8 additions & 6 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment on lines +24 to 27

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8001 matches what the Benefits does. I think switching to 8001 in template-devcontainer would be worthwhile, since 8000 is the default port for a lot of services that might be run for the primary purpose of your dev container.

- ./:/home/compiler/src
- ./:/compiler/app
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"