From a786689fcdd05025497b85a90ac8c3e1e18062b7 Mon Sep 17 00:00:00 2001 From: pythoninthegrass <4097471+pythoninthegrass@users.noreply.github.com> Date: Fri, 11 Aug 2023 07:08:12 +0000 Subject: [PATCH] Add tooling --- .devcontainer/.dockerignore | 13 +++ .devcontainer/Dockerfile | 136 ++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 32 +++++++ .devcontainer/requirements.txt | 21 ++++ .editorconfig | 34 +++++++ .github/dependabot.yml | 18 ++++ .gitignore | 163 ++++++++++++++++++++++++++++++++ .shellcheckrc | 1 + .tool-versions | 2 + .vscode/launch.json | 92 ++++++++++++++++++ .vscode/settings.json | 14 +++ 11 files changed, 526 insertions(+) create mode 100644 .devcontainer/.dockerignore create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/requirements.txt create mode 100644 .editorconfig create mode 100644 .github/dependabot.yml create mode 100644 .gitignore create mode 100644 .shellcheckrc create mode 100644 .tool-versions create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.devcontainer/.dockerignore b/.devcontainer/.dockerignore new file mode 100644 index 0000000..7639f73 --- /dev/null +++ b/.devcontainer/.dockerignore @@ -0,0 +1,13 @@ +!poetry.lock +!pyproject.toml +.cache +.devcontainer +.git +.gitignore +.pytest_cache +.tool-versions +.venv +.vscode +**/__pycache__ +Dockerfile* +README.md diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1097724 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,136 @@ +# syntax=docker/dockerfile:1.6 + +# full semver just for python base image +ARG PYTHON_VERSION=3.11.4 + +FROM python:${PYTHON_VERSION}-slim-bullseye AS builder + +# avoid stuck build due to user prompt +ARG DEBIAN_FRONTEND=noninteractive + +# update apt repos and install dependencies +RUN apt -qq update && apt -qq install \ + --no-install-recommends -y \ + curl \ + gcc \ + libpq-dev \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# pip env vars +ENV PIP_NO_CACHE_DIR=off +ENV PIP_DISABLE_PIP_VERSION_CHECK=on +ENV PIP_DEFAULT_TIMEOUT=100 + +# poetry env vars +ENV POETRY_HOME="/opt/poetry" +ENV POETRY_VERSION=1.5.1 +ENV POETRY_VIRTUALENVS_IN_PROJECT=true +ENV POETRY_NO_INTERACTION=1 + +# path +ENV VENV="/opt/venv" +ENV PATH="$POETRY_HOME/bin:$VENV/bin:$PATH" + +COPY requirements.txt requirements.txt + +RUN python -m venv $VENV \ + && . "${VENV}/bin/activate"\ + && python -m pip install "poetry==${POETRY_VERSION}" \ + && python -m pip install -r requirements.txt + +FROM python:${PYTHON_VERSION}-slim-bullseye AS runner + +# setup standard non-root user for use downstream +ENV USER_NAME=appuser +ENV USER_GROUP=appuser +ENV HOME="/home/${USER_NAME}" +ENV HOSTNAME="${HOST:-localhost}" +ENV VENV="/opt/venv" + +ENV PATH="${VENV}/bin:${VENV}/lib/python${PYTHON_VERSION}/site-packages:/usr/local/bin:${HOME}/.local/bin:/bin:/usr/bin:/usr/share/doc:$PATH" + +# standardise on locale, don't generate .pyc, enable tracebacks on seg faults +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONFAULTHANDLER 1 + +# workers per core +# https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/blob/master/README.md#web_concurrency +ENV WEB_CONCURRENCY=2 + +# avoid stuck build due to user prompt +ARG DEBIAN_FRONTEND=noninteractive + +# install dependencies +RUN apt -qq update && apt -qq install \ + --no-install-recommends -y \ + bat \ + curl \ + dpkg \ + git \ + iputils-ping \ + lsof \ + p7zip \ + perl \ + shellcheck \ + tldr \ + tree \ + && rm -rf /var/lib/apt/lists/* + +RUN groupadd $USER_NAME \ + && useradd -m $USER_NAME -g $USER_GROUP + +# create read/write dirs +RUN < /dev/null +apt update && apt install gh -y +apt remove dpkg -y +rm -rf /var/lib/apt/lists/* + +# fzf +git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf +yes | ~/.fzf/install +EOF + +# qol: .bashrc +RUN tee -a $HOME/.bashrc </**" + ], + // "runtimeExecutable": "${env:HOME}/.n/bin/node" + } + ], + "ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python" +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eb2f393 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "[python]": { + "editor.insertSpaces": true, + "editor.tabSize": 4, + }, + "python.testing.pytestArgs": [ + "." + ], + // ! only disable analysis (pylance) if ruff is installed + // https://github.com/astral-sh/ruff-vscode + // "python.analysis.ignore": [ + // "*" + // ], +}