From b6dff129ffabf0ed7ba8bd1b9a8a568da70763b5 Mon Sep 17 00:00:00 2001 From: Chuck Lantz Date: Fri, 23 Dec 2022 08:32:53 -0600 Subject: [PATCH] Match current template, add info on Features and image metadata (#62) * Match current template, add info on Features and image metadata * Update * Fix typo * Fix typo * Remove bad comment about user name * Update portsAttributs ref * Remove otherPortsAttributes given the reference * Typo --- .devcontainer/Dockerfile | 30 --------------- .devcontainer/devcontainer.json | 66 ++++++++------------------------- README.md | 19 +++++++--- 3 files changed, 30 insertions(+), 85 deletions(-) delete mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 01c6efb..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.202.3/containers/python-3/.devcontainer/base.Dockerfile -# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster -ARG VARIANT=3-bullseye -FROM mcr.microsoft.com/devcontainers/python:0-${VARIANT} - -# [Optional] Allow the vscode user to pip install globally w/o sudo -ENV PIP_TARGET=/usr/local/pip-global -ENV PYTHONPATH=${PIP_TARGET}:${PYTHONPATH} -ENV PATH=${PIP_TARGET}/bin:${PATH} -RUN if ! cat /etc/group | grep -e "^pip-global:" > /dev/null 2>&1; then groupadd -r pip-global; fi \ - && usermod -a -G pip-global vscode \ - && umask 0002 && mkdir -p ${PIP_TARGET} \ - && chown :pip-global ${PIP_TARGET} \ - && ( [ ! -f "/etc/profile.d/00-restore-env.sh" ] || sed -i -e "s/export PATH=/export PATH=\/usr\/local\/pip-global:/" /etc/profile.d/00-restore-env.sh ) - -# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 -ARG NODE_VERSION="none" -RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi - -# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. -# COPY requirements.txt /tmp/pip-tmp/ -# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ -# && rm -rf /tmp/pip-tmp - -# [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends - -# [Optional] Uncomment this line to install global node packages. -# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 417995c..1ff5991 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,58 +1,29 @@ -// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.3/containers/python-3 +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python { "name": "Python 3", - "build": { - "dockerfile": "Dockerfile", - "context": "..", - "args": { - // Update 'VARIANT' to pick a Python version: 3, 3.9, 3.8, 3.7, 3.6. - // Append -bullseye or -buster to pin to an OS version. - // Use -bullseye variants on local on arm64/Apple Silicon. - "VARIANT": "3.9-bullseye", - // Options - "NODE_VERSION": "lts/*" - } - }, - + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:0-3.11", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.profiles.linux": { - "bash": { - "path": "/bin/bash" - } - }, - "python.defaultInterpreterPath": "/usr/local/bin/python", - "python.languageServer": "Default", - "python.linting.enabled": true, - "python.linting.pylintEnabled": true, - "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", - "python.formatting.blackPath": "/usr/local/py-utils/bin/black", - "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", - "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", - "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", - "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", - "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", - "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", - "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" - }, - - // Add the IDs of extensions you want installed when the container is created. + "settings": {}, "extensions": [ - "ms-python.python", - "ms-python.vscode-pylance" + "streetsidesoftware.code-spell-checker" ] } }, - + // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [9000], - // Use 'portsAttributes' to set default properties for specific forwarded ports. More info: https://code.visualstudio.com/docs/remote/devcontainerjson-reference. + // Use 'portsAttributes' to set default properties for specific forwarded ports. + // More info: https://containers.dev/implementors/json_reference/#port-attributes "portsAttributes": { "9000": { "label": "Hello Remote World", @@ -60,14 +31,9 @@ } }, - // Use 'otherPortsAttributes' to configure any ports that aren't configured using 'portsAttributes'. - // "otherPortsAttributes": { - // "onAutoForward": "silent" - // }, - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pip3 install -r requirements.txt", + "postCreateCommand": "pip3 install -r requirements.txt" - // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } diff --git a/README.md b/README.md index 70ae6e8..0349143 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-python) -A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Dev Containers](https://aka.ms/vscode-remote/containers)**. +A **development container** is a running container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Dev Containers](https://aka.ms/vscode-remote/containers)**. This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too. @@ -12,8 +12,9 @@ This is a sample project that lets you try out either option in a few easy steps ### GitHub Codespaces Follow these steps to open this sample in a Codespace: -1. Click the Code drop-down menu and select the **Open with Codespaces** option. -1. Select **+ New codespace** at the bottom on the pane. +1. Click the **Code** drop-down menu. +2. Click on the **Codespaces** tab. +3. Click **Create codespace on main** . For more information on creating your codespace, visit the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace). @@ -41,13 +42,14 @@ Follow these steps to open this sample in a container using the VS Code Dev Cont Once you have this sample opened, you'll be able to work with it like you would locally. -> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root. - Some things to try: 1. **Edit:** - Open `app.py` - Try adding some code and check out the language features. + - Make a spelling mistake and notice it is detected. The [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) extension was automatically installed because it is referenced in `.devcontainer/devcontainer.json`. + - Also notice that utilities like `pylint` and the [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) extension are installed. Tools are installed in the `mcr.microsoft.com/devcontainers/python` image and Dev Container settings and metadata are automatically picked up from [image labels](https://containers.dev/implementors/reference/#labels). + 2. **Terminal:** - Press ctrl+shift+\` to open a terminal window. @@ -79,6 +81,13 @@ Some things to try: - Modify the `"onAutoForward"` attribute in your `portsAttributes` from `"notify"` to `"openBrowser"`. - Press F1 and select the **Dev Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up. +5. **Install Node.js using a Dev Container Feature:** + - Press F1 and select the **Dev Containers: Configure Container Features...** or **Codespaces: Configure Container Features...** command. + - Type "node" in the text box at the top. + - Check the check box next to "Node.js (via nvm) and yarn" (published by devcontainers) + - Click OK + - Press F1 and select the **Dev Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up. + ### More samples - [Tweeter App - Python and Django](https://github.com/Microsoft/python-sample-tweeterapp)