From 0e29b4dbe41a6df5728026db66e22fb1a56ed988 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 11:40:15 +0000 Subject: [PATCH 01/12] feat: add dev_container --- .devcontainer/devcontainer.json | 26 ++++++++++++++++++++++++++ Dockerfile.dev | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile.dev diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..b2a3a731 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile.dev" + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..6d955071 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,13 @@ +# Use an official Python runtime as a parent image +FROM python:3.11 + +# Set the working directory to /app +WORKDIR /app + +# Install deps +COPY pyproject.toml /app/ +RUN pip install -e .[dev] + +# Install the entire app +COPY . /app +RUN pip install -e .[dev] \ No newline at end of file From 0a034657ff9ed42a8a4727c37115d45b2c1a9e56 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 11:42:05 +0000 Subject: [PATCH 02/12] ci: install test deps in dev container --- Dockerfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 6d955071..e8038bee 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -10,4 +10,4 @@ RUN pip install -e .[dev] # Install the entire app COPY . /app -RUN pip install -e .[dev] \ No newline at end of file +RUN pip install -e .[dev, tests] \ No newline at end of file From eea7e9b6412071dae6dc6b2f28af73cf93307047 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 11:45:18 +0000 Subject: [PATCH 03/12] ci: optimise layers for deps --- Dockerfile.dev | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index e8038bee..75c14bae 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -6,8 +6,9 @@ WORKDIR /app # Install deps COPY pyproject.toml /app/ -RUN pip install -e .[dev] +RUN pip install .[dev] +RUN pip install .[tests] # Install the entire app COPY . /app -RUN pip install -e .[dev, tests] \ No newline at end of file +RUN pip install -e . From 61bfc1257ec01476c331cf2d6e586268aed2b121 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 11:46:37 +0000 Subject: [PATCH 04/12] ci: install pre-commit hooks on setup --- Dockerfile.dev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile.dev b/Dockerfile.dev index 75c14bae..e5f64445 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -7,6 +7,8 @@ WORKDIR /app # Install deps COPY pyproject.toml /app/ RUN pip install .[dev] +RUN pre-commit install-hooks + RUN pip install .[tests] # Install the entire app From 156cc84d08d10a928c9259d49337cc6d599a2936 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 13:48:19 +0200 Subject: [PATCH 05/12] cleanup --- Dockerfile.dev | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index e5f64445..21e866ad 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -7,7 +7,6 @@ WORKDIR /app # Install deps COPY pyproject.toml /app/ RUN pip install .[dev] -RUN pre-commit install-hooks RUN pip install .[tests] From fd0a59d97bc3e72c5ad1e22c1349e3168012eb04 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 1 Oct 2023 11:56:36 +0000 Subject: [PATCH 06/12] ci: align dockerfile devcontainer python with rest of project --- Dockerfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 21e866ad..0bfbcc00 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.11 +FROM python:3.09 # Set the working directory to /app WORKDIR /app From b3eb9eb4631b0f94ea6080cb602616884950b3c8 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 14:46:40 +0000 Subject: [PATCH 07/12] misc. --- Dockerfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 0bfbcc00..6ebee466 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.09 +FROM python:3.9 # Set the working directory to /app WORKDIR /app From 37f3d8b336aeccf148556da367387b7d6c702e28 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 15:02:22 +0000 Subject: [PATCH 08/12] misc. --- Dockerfile.dev | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 6ebee466..f50b4471 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -7,9 +7,18 @@ WORKDIR /app # Install deps COPY pyproject.toml /app/ RUN pip install .[dev] - RUN pip install .[tests] +# Setup dev env +RUN git init && pre-commit install + +RUN type -p curl >/dev/null || (apt update && apt install curl -y) +curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ +&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ +&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ +&& apt update \ +&& apt install gh -y + # Install the entire app COPY . /app RUN pip install -e . From 388dce336c8fc8497da338729c6cb34727137dfc Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 15:18:45 +0000 Subject: [PATCH 09/12] feat: add preferred extensions --- .devcontainer/devcontainer.json | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b2a3a731..63fb45f2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,20 +7,25 @@ "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. "dockerfile": "../Dockerfile.dev" + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "charliermarsh.ruff", + "ms-python.black-formatter", + "ms-azuretools.vscode-docker" + ] + } } - // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - // Uncomment the next line to run commands after the container is created. // "postCreateCommand": "cat /etc/os-release", - // Configure tool-specific properties. // "customizations": {}, - // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "devcontainer" -} +} \ No newline at end of file From 35f6ecfc8cb47be58b75246fc16a8954c43b0acb Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 15:18:51 +0000 Subject: [PATCH 10/12] ci: add dockerignore --- .dockerignore | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..39497613 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,122 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +.apkg + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.*venv* +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Friggin Apple +.DS_Store + +# PyCharm +.idea/ + +# VSCode +*.code-workspace + +*.mdvlog +*.apkg + +.pytest_cache +pytest.xml +pytest-coverage.txt +BearImages* +test_package +.pytest_results +.git From ad0f51d8fbfcb673e3ce7ef9c352cce5ad6e7ac4 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 15:19:05 +0000 Subject: [PATCH 11/12] container: ensure lazygit does not show pop-up every time --- Dockerfile.dev | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index f50b4471..f681ea73 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.9 +FROM python:3.9-bullseye # Set the working directory to /app WORKDIR /app @@ -12,12 +12,17 @@ RUN pip install .[tests] # Setup dev env RUN git init && pre-commit install -RUN type -p curl >/dev/null || (apt update && apt install curl -y) -curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ -&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ -&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ -&& apt update \ -&& apt install gh -y +RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \ + && curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \ + && tar xf lazygit.tar.gz lazygit \ + && install lazygit /usr/local/bin +RUN mkdir -p ~/.config/lazygit/ && touch ~/.config/lazygit/config.yml && echo "disableStartupPopups: true" >> ~/.config/lazygit/config.yml + +RUN type -p curl >/dev/null || (apt update && apt install curl -y) && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && apt update \ + && apt install gh -y # Install the entire app COPY . /app From 73dcb46273e88509ae4fb872c979d2ab1144635d Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 2 Oct 2023 16:45:49 +0000 Subject: [PATCH 12/12] feat: pre-populate msic --- Dockerfile.dev | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index f681ea73..226c1034 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -10,7 +10,11 @@ RUN pip install .[dev] RUN pip install .[tests] # Setup dev env -RUN git init && pre-commit install +COPY tasks.py pyproject.toml ./ +RUN inv static-type-checks + +COPY .pre-commit-config.yaml ./ +RUN git init && pre-commit run RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \ && curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \