From 4396aa6eadf35b9d8b3e8c6ddd1b40eda90a7d30 Mon Sep 17 00:00:00 2001 From: Kyle Finley Date: Fri, 23 Aug 2024 15:47:35 -0400 Subject: [PATCH] improve devcontainer to remove image build --- .devcontainer/.editorconfig | 12 --- .devcontainer/Dockerfile | 52 ----------- .devcontainer/devcontainer.json | 86 ++++++++++++++++--- .devcontainer/files/.bash_completion | 3 - .devcontainer/local-features/README.md | 3 + .devcontainer/local-features/poetry/README.md | 11 +++ .../poetry/devcontainer-feature.json | 26 ++++++ .../local-features/poetry/install.sh | 20 +++++ .vscode/cspell.json | 24 +++--- .vscode/extensions.json | 8 +- docs/source/conf.py | 3 + docs/source/developers/getting_started.rst | 28 +++--- 12 files changed, 175 insertions(+), 101 deletions(-) delete mode 100644 .devcontainer/.editorconfig delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/files/.bash_completion create mode 100644 .devcontainer/local-features/README.md create mode 100644 .devcontainer/local-features/poetry/README.md create mode 100644 .devcontainer/local-features/poetry/devcontainer-feature.json create mode 100644 .devcontainer/local-features/poetry/install.sh diff --git a/.devcontainer/.editorconfig b/.devcontainer/.editorconfig deleted file mode 100644 index 2087dd7a9..000000000 --- a/.devcontainer/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -# top-most EditorConfig file -root = true - -[*] -indent_style = space -indent_size = 4 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = false -insert_final_newline = true diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 4d5681ad8..000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,52 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/ubuntu/.devcontainer/base.Dockerfile - -# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-20.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04 -ARG VARIANT="ubuntu-22.04" -FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} - -# [Optional] Uncomment this section to install additional OS packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends curl git make pkg-config bash-completion \ - python3-virtualenv python3-pip python3-venv python3-dev \ - software-properties-common binutils - -# Setup Apt for newer versions of NodeJS -RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && \ - sudo apt-get install -y nodejs - -# Install nodejs -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends nodejs - -# Add additional python options -RUN sudo add-apt-repository ppa:deadsnakes/ppa - -# Install Python 3.11, 3.10, and 3.9 -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends python3.11 python3.11-venv python3.11-dev \ - python3.10 python3.10-venv python3.10-dev \ - python3.9 python3.9-venv python3.9-dev - - -# Setup alternatives -RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 - -# Update to use python 3.9 by default -RUN update-alternatives --set python $(update-alternatives --list python | grep python3.9) - -# VSCODE user commands -USER vscode - -# Setup Bash Completion -ADD --chown=vscode:vscode files/.bash_completion /home/vscode/.bash_completion -RUN mkdir /home/vscode/.bash_completion.d/ - -# Setup AWS CLI -RUN set -e; \ - pip3 install --no-cache-dir --user awscli pipx; \ - pipx install poetry; \ - pipx inject poetry "poetry-dynamic-versioning[plugin]" poetry-plugin-export; \ - echo "complete -C '/home/vscode/.local/bin/aws_completer' aws" >> ~/.bashrc - -# Setup OS_NAME var for runway builds from this dev container -RUN echo "export OS_NAME=ubuntu-latest" >> ~/.bashrc diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ce1c37d3c..622fe9cb7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,20 +1,86 @@ { - "build": { - "args": { - "VARIANT": "ubuntu-22.04" - }, - "dockerfile": "Dockerfile" + "containerEnv": { + "AWS_DEFAULT_REGION": "${localEnv:AWS_DEFAULT_REGION:us-east-1}", + "AWS_MAX_ATTEMPTS": "20", + "AWS_RETRY_MODE": "adaptive", + "CFNGIN_STACK_POLL_TIME": "3", + "TZ": "${localEnv:TZ:US/Eastern}" }, "customizations": { "vscode": { "extensions": [ - "ms-python.python" - ] + "Compulim.vscode-clock", + "DavidAnson.vscode-markdownlint", + "PeterSchmalfeldt.explorer-exclude", + "SirTori.indenticator", + "Tyriar.sort-lines", + "VisualStudioExptTeam.vscodeintellicode", + "bierner.markdown-checkbox", + "charliermarsh.ruff", + "christian-kohler.path-intellisense", + "donjayamanne.githistory", + "eamodio.gitlens", + "editorconfig.editorconfig", + "github.vscode-github-actions", + "hashicorp.terraform", + "lextudio.restructuredtext", + "mohsen1.prettify-json", + "ms-python.black-formatter", + "ms-python.python", + "ms-python.vscode-pylance", + "oderwat.indent-rainbow", + "redhat.vscode-yaml", + "remcohaszing.schemastore", + "richie5um2.vscode-sort-json", + "streetsidesoftware.code-spell-checker", + "tamasfe.even-better-toml", + "trond-snekvik.simple-rst", + "yzhang.markdown-all-in-one" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "bash": { + "icon": "terminal-bash", + "path": "bash" + }, + "zsh": { + "path": "zsh" + } + } + } } }, "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {} + "./local-features/poetry": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/node:1": {} }, - "name": "Ubuntu", - "remoteUser": "vscode" + "image": "mcr.microsoft.com/devcontainers/python:3.12", + "mounts": [ + { + "source": "${localEnv:HOME}/.aws", + "target": "/home/vscode/.aws", + "type": "bind" + }, + { + "source": "devcontainer-${containerWorkspaceFolderBasename}-node_modules", + "target": "${containerWorkspaceFolder}/node_modules", + "type": "volume" + }, + { + "source": "devcontainer-npm-cache", + "target": "/home/vscode/.npm", + "type": "volume" + }, + { + "source": "devcontainer-${containerWorkspaceFolderBasename}-pre-commit-cache", + "target": "/home/vscode/.cache/pre-commit", + "type": "volume" + } + ], + "name": "devcontainer-runway", + "onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}; sudo apt-get update -y; sudo apt-get install direnv", + "postAttachCommand": "make setup", + "postStartCommand": "sudo chown -R vscode:vscode .venv node_modules ~/.cache/pre-commit ~/.npm ~/.cache/pip ~/.cache/pypoetry" } diff --git a/.devcontainer/files/.bash_completion b/.devcontainer/files/.bash_completion deleted file mode 100644 index debbd6f64..000000000 --- a/.devcontainer/files/.bash_completion +++ /dev/null @@ -1,3 +0,0 @@ -for bcfile in ~/.bash_completion.d/* ; do - [ -f "$bcfile" ] && . $bcfile -done diff --git a/.devcontainer/local-features/README.md b/.devcontainer/local-features/README.md new file mode 100644 index 000000000..47b9dbf43 --- /dev/null +++ b/.devcontainer/local-features/README.md @@ -0,0 +1,3 @@ +# local-feature + +A collection of local devcontainer features. diff --git a/.devcontainer/local-features/poetry/README.md b/.devcontainer/local-features/poetry/README.md new file mode 100644 index 000000000..55ece7432 --- /dev/null +++ b/.devcontainer/local-features/poetry/README.md @@ -0,0 +1,11 @@ +# poetry + +Install `poetry` using `pipx` included on the image. + +## Example Usage + +```json +"features": { + "./local-features/poetry": {} +} +``` diff --git a/.devcontainer/local-features/poetry/devcontainer-feature.json b/.devcontainer/local-features/poetry/devcontainer-feature.json new file mode 100644 index 000000000..59215b686 --- /dev/null +++ b/.devcontainer/local-features/poetry/devcontainer-feature.json @@ -0,0 +1,26 @@ +{ + "description": "Install `poetry` using `pipx` included in the image.", + "documentationURL": "", + "id": "poetry", + "installsAfter": [], + "mounts": [ + { + "source": "devcontainer-pip-cache", + "target": "/home/vscode/.cache/pip", + "type": "volume" + }, + { + "source": "devcontainer-poetry-cache", + "target": "/home/vscode/.cache/pypoetry", + "type": "volume" + }, + { + "source": "devcontainer-${containerWorkspaceFolderBasename}-venv", + "target": "${containerWorkspaceFolder}/.venv", + "type": "volume" + } + ], + "name": "poetry", + "options": {}, + "version": "0.0.0" +} diff --git a/.devcontainer/local-features/poetry/install.sh b/.devcontainer/local-features/poetry/install.sh new file mode 100644 index 000000000..2b09dec82 --- /dev/null +++ b/.devcontainer/local-features/poetry/install.sh @@ -0,0 +1,20 @@ +#! /usr/bin/env bash + +set -eo pipefail + +function __install_poetry { + if [[ -z "$(command -v poetry)" ]]; then + pipx install poetry; + pipx inject poetry "poetry-dynamic-versioning[plugin]" poetry-plugin-export; + fi +} + +function __configure_poetry { + poetry config virtualenvs.create true; + poetry config virtualenvs.in-project true; + poetry config virtualenvs.prefer-active-python true; + poetry config warnings.export false; +} + +__install_poetry; +__configure_poetry; diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 92b0f2a0b..364272980 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -36,7 +36,7 @@ "**/.cache", "**/.envrc", "**/.git", - ".devcontainer/files/.bash_completion", + "**/.devcontainer/devcontainer.json", "**/.gitignore", "**/.runway/**", "**/.secret", @@ -72,20 +72,11 @@ "maxNumberOfProblems": 100, "version": "0.2", "words": [ - "ALGS", - "EOCD", - "FQDNs", - "Fakhreddine", - "Inconsolata", - "Ngin", - "PYXMLSEC", - "Pipefile", - "SPHINXAUTOBUILD", - "SPHINXAUTOBUILDPORT", "absolutepath", "abstractmethod", "accesspoint", "addoption", + "ALGS", "appendleft", "arcname", "argparsing", @@ -116,6 +107,7 @@ "copydir", "datetimez", "devel", + "direnv", "dockerized", "domparator", "downstreams", @@ -124,9 +116,11 @@ "edgelambda", "ekscluster", "eksservicerole", + "EOCD", "errmsg", "excinfo", "execglobals", + "Fakhreddine", "filedes", "filedir", "filehandle", @@ -134,6 +128,7 @@ "fileinfos", "fileout", "foobarfoo", + "FQDNs", "frontmatter", "fstring", "furo", @@ -148,6 +143,7 @@ "humanreadable", "identless", "igittigitt", + "Inconsolata", "indentless", "instancerole", "intersphinx", @@ -175,6 +171,7 @@ "nestedval", "newdir", "newfile", + "Ngin", "nitpicky", "nodegroup", "nodeinstanceprofile", @@ -190,10 +187,13 @@ "outputquery", "paravirtual", "partitionkey", + "Pipefile", "prehook", "prepad", "prevdir", + "pypoetry", "pyupgrade", + "PYXMLSEC", "readacl", "refreshable", "rglob", @@ -209,6 +209,8 @@ "shouldraise", "sourcebucket", "sourcekey", + "SPHINXAUTOBUILD", + "SPHINXAUTOBUILDPORT", "ssmstore", "ssword", "subclasscheck", diff --git a/.vscode/extensions.json b/.vscode/extensions.json index c003f2319..d28ebdcce 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,14 @@ { "recommendations": [ "DavidAnson.vscode-markdownlint", + "charliermarsh.ruff", "editorconfig.editorconfig", + "lextudio.restructuredtext", + "ms-python.black-formatter", "ms-python.python", - "ms-python.vscode-pylance" + "ms-python.vscode-pylance", + "redhat.vscode-yaml", + "streetsidesoftware.code-spell-checker", + "tamasfe.even-better-toml" ] } diff --git a/docs/source/conf.py b/docs/source/conf.py index c2c861d59..7efc58f6c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -230,6 +230,9 @@ # https://sphinxcontribexternal-links.readthedocs.io/latest/configuration.html external_links: dict[str, str] = { "CloudFormation": "https://aws.amazon.com/cloudformation", + "devcontainer": "https://containers.dev/", + "direnv": "https://github.com/direnv/direnv", + "poetry-dynamic-versioning": "https://github.com/mtkennerly/poetry-dynamic-versioning", "troposphere": "https://github.com/cloudtools/troposphere", } external_links_substitutions: dict[str, str] = { diff --git a/docs/source/developers/getting_started.rst b/docs/source/developers/getting_started.rst index 514beb014..e6672d56f 100644 --- a/docs/source/developers/getting_started.rst +++ b/docs/source/developers/getting_started.rst @@ -14,26 +14,30 @@ Before getting started, `fork this repo`_ and `clone your fork`_. Development Environment *********************** -This project includes an optional `VSCode Dev Container `__. -This is an Ubuntu 22.04 image that will launch with operating system pre-requisites already installed and VSCode configured for Python debugging. -It's not required to use this for development work, but does provide an easy and consistent way to get started. +.. tip:: + This project includes a :link:`devcontainer` which can be used for development. + It provides all of the tools required (node, :link:`npm`, :link:`poetry`, :link:`python`, etc) for development and a few bonuses for *quality of life* (:link:`direnv`, :lin:`vscode` extensions, etc). -This project uses poetry_ to create Python virtual environment. + .. seealso:: + - `Devcontainers: Personalizing with dotfile repositories `__ + - `Personalizing GitHub Codespaces for your account `__ + + + It's not required to use this for development work, but does provide an easy and consistent way to get started. + +This project uses :link:`poetry` to create Python virtual environment. This must be installed on your system before setting up your dev environment. -Additionally, the poetry-dynamic-versioning_ plugin should be installed. -Refer to the documentation of poetry-dynamic-versioning_ for how to install it based on how you installed poetry_. +Additionally, the :link:`poetry-dynamic-versioning` plugin should be installed. +Refer to the documentation of :link:`poetry-dynamic-versioning` for how to install it based on how you installed :link:`poetry`. -With poetry_ installed, run ``make setup`` to setup your development environment. +With :link:`poetry` installed, run ``make setup`` to setup your development environment. This will create all the required virtual environments to work on Runway, build docs locally, and run integration tests locally. The virtual environments all have Runway installed as editable meaning as you make changes to the code of your local clone, it will be reflected in all the virtual environments. -.. _poetry: https://python-poetry.org -.. _poetry-dynamic-versioning: https://github.com/mtkennerly/poetry-dynamic-versioning - pre-commit ========== -`pre-commit `__ is configured for this project to help developers follow the coding style. +:link:`pre-commit` is configured for this project to help developers follow the coding style. If you used ``make setup`` to setup your environment, it is already setup for you. If not, you can run ``make setup-pre-commit`` to to install the pre-commit hooks. @@ -43,4 +47,4 @@ You can also run ``make run-pre-commit`` at any time to manually trigger these h pyright Type Checking ===================== -This project uses pyright to perform type checking. To run type checking locally, install pyright (``make setup-npm``) then run ``make lint`` or ``make lint-pyright``. +This project uses :link:`pyright` to perform type checking. To run type checking locally, install pyright (``make setup-npm``) then run ``make lint`` or ``make lint-pyright``.