1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Edits to devcontainer.json steps

This commit is contained in:
Allison Weins
2021-05-06 19:33:41 +00:00
committed by GitHub
parent 9d243b2b5e
commit c2eebd3c74
3 changed files with 23 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -46,7 +46,7 @@ This example guides you through adding a `devcontainer.json` file from a templat
1. Access the command palette (`shift command P` / `shift control P`), then start typing "dev container". Click **Codespaces: Add Development Container Configuration Files...** 1. Access the command palette (`shift command P` / `shift control P`), then start typing "dev container". Click **Codespaces: Add Development Container Configuration Files...**
!["Codespaces: Add Development Container Configuration Files..." in the command palette](/assets/images/help/codespaces/add-prebuilt-container-command.png) !["Codespaces: Add Development Container Configuration Files..." in the command palette](/assets/images/help/codespaces/add-prebuilt-container-command.png)
3. For this example, click **Python 3**. If you need additional features you can select any container thats specific to Python or a combination of tools such as Python 3 and PostgresSQL. 2. For this example, click **Python 3**. If you need additional features you can select any container thats specific to Python or a combination of tools such as Python 3 and PostgresSQL.
![Select Python option from the list](/assets/images/help/codespaces/add-python-prebuilt-container.png) ![Select Python option from the list](/assets/images/help/codespaces/add-python-prebuilt-container.png)
3. Click the recommended version of Python. 3. Click the recommended version of Python.
![Python version selection](/assets/images/help/codespaces/add-python-version.png) ![Python version selection](/assets/images/help/codespaces/add-python-version.png)
@@ -100,7 +100,7 @@ The newly added `devcontainer.json` file defines a few properties that are descr
// Add the IDs of extensions you want installed when the container is created. // Add the IDs of extensions you want installed when the container is created.
"extensions": [ "extensions": [
"ms-python.python" "ms-python.python",
], ],
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
@@ -162,34 +162,42 @@ With your dev container added and a basic understanding of what everything does,
!["Codespaces: Rebuild Container" in the command palette](/assets/images/help/codespaces/devcontainers-options.png) !["Codespaces: Rebuild Container" in the command palette](/assets/images/help/codespaces/devcontainers-options.png)
2. Update your `devcontainer.json` file after `extensions` to include the following: 2. Update your the `extensions` list in your `devcontainer.json` file to add a few extensions that are useful when working with your project.
```json{:copy} ```json{:copy}
"portsAttributes": { "extensions": [
"5000": { "ms-python.python",
"onAutoForward": "openBrowser" "cstrap.flask-snippets",
}, "streetsidesoftware.code-spell-checker",
],
```
3. Uncomment the `postCreateCommand` to auto-install requirements as part of the codespaces setup process.
```json{:copy}
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r requirements.txt", "postCreateCommand": "pip3 install --user -r requirements.txt",
``` ```
The `portsAttributes` addition forwards port 5000 and automatically opens a browser tab to the forwarded port when you start the application while the `postCreateCommand` will ensure your requirements are installed as part of the codespace setup process.
For more information on `devcontainer.json` properties, see the [devcontainer.json reference](https://code.visualstudio.com/docs/remote/devcontainerjson-reference) on the Visual Studio Code docs. 4. To rebuild your container and apply the devcontainer.json changes, access the command palette (`shift command P` / `shift control P`), then start typing "rebuild". Click **Codespaces: Rebuild Container**.
1. To rebuild your container, access the command palette (`shift command P` / `shift control P`), then start typing "rebuild". Click **Codespaces: Rebuild Container**.
![Rebuild container option](/assets/images/help/codespaces/codespaces-rebuild.png) ![Rebuild container option](/assets/images/help/codespaces/codespaces-rebuild.png)
Rebuilding inside your codespace ensures your changes work as expected before you commit the changes to the repository. If something does result in a failure, youll be placed in a codespace with a recovery container that you can rebuild from to keep adjusting your container. Rebuilding inside your codespace ensures your changes work as expected before you commit the changes to the repository. If something does result in a failure, youll be placed in a codespace with a recovery container that you can rebuild from to keep adjusting your container.
5. Check your changes were successfully applied by verifying the Code Spell Checker and Flask Snippet extensions were installed.
![Extensions list](/assets/images/help/codespaces/python-extensions.png)
### Step 4: Run your application ### Step 4: Run your application
In the previous section, you used the `postCreateCommand` to installing a set of packages via pip3. With our dependencies now installed, we can run our application. In the previous section, you used the `postCreateCommand` to installing a set of packages via pip3. With our dependencies now installed, we can run our application.
1. Run your start command by pressing `F5`. 1. Run your application by pressing `F5` or entering `python -m flask run` in your terminal.
2. When your project starts, you should see a new tab open and connect to the port your project uses. 2. When your project starts, you should see a toast in the bottom right corner with a prompt to connect to the port your project uses.
![Port forwarding toast](/assets/images/help/codespaces/python-port-forwarding.png)
### Step 5: Commit your changes ### Step 5: Commit your changes