### Install Dev Container CLI with Install Script Source: https://github.com/devcontainers/cli/blob/main/README.md Installs the CLI using a curl script. Ensure your PATH is updated after installation. ```bash curl -fsSL https://raw.githubusercontent.com/devcontainers/cli/main/scripts/install.sh | sh ``` ```bash export PATH="$HOME/.devcontainers/bin:$PATH" ``` -------------------------------- ### Dev Container Build Output Example Source: https://github.com/devcontainers/cli/blob/main/README.md Example output from the 'devcontainer up' command showing the Docker build process. ```bash [88 ms] dev-containers-cli 0.1.0. [165 ms] Start: Run: docker build -f /home/node/vscode-remote-try-rust/.devcontainer/Dockerfile -t vsc-vscode-remote-try-rust-89420ad7399ba74f55921e49cc3ecfd2 --build-arg VARIANT=bullseye /home/node/vscode-remote-try-rust/.devcontainer [+] Building 0.5s (5/5) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 38B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for mcr.microsoft.com/vscode/devcontainers/r 0.4s => CACHED [1/1] FROM mcr.microsoft.com/vscode/devcontainers/rust:1-bulls 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:39873ccb81e6fb613975e11e37438eee1d49c963a436d 0.0s => => naming to docker.io/library/vsc-vscode-remote-try-rust-89420ad7399 0.0s [1640 ms] Start: Run: docker run --sig-proxy=false -a STDOUT -a STDERR --mount type=bind,source=/home/node/vscode-remote-try-rust,target=/workspaces/vscode-remote-try-rust -l devcontainer.local_folder=/home/node/vscode-remote-try-rust --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --entrypoint /bin/sh vsc-vscode-remote-try-rust-89420ad7399ba74f55921e49cc3ecfd2-uid -c echo Container started Container started {"outcome":"success","containerId":"f0a055ff056c1c1bb99cc09930efbf3a0437c54d9b4644695aa23c1d57b4bd11","remoteUser":"vscode","remoteWorkspaceFolder":"/workspaces/vscode-remote-try-rust"} ``` -------------------------------- ### Start Dev Container with Sample Project Source: https://github.com/devcontainers/cli/blob/main/README.md Clones a sample Rust project and starts a dev container for it using the 'up' command. Replace with the actual path. ```bash git clone https://github.com/microsoft/vscode-remote-try-rust devcontainer up --workspace-folder ``` -------------------------------- ### Dev Container Exec Output Example Source: https://github.com/devcontainers/cli/blob/main/README.md Example output from running 'cargo run' inside the dev container. ```bash [33 ms] dev-containers-cli 0.1.0. Compiling hello_remote_world v0.1.0 (/workspaces/vscode-remote-try-rust) Finished dev [unoptimized + debuginfo] target(s) in 1.06s Running `target/debug/hello_remote_world` Hello, VS Code Remote - Containers! {"outcome":"success"} ``` -------------------------------- ### Install Dev Container CLI with npm Source: https://github.com/devcontainers/cli/blob/main/README.md Installs the Dev Container CLI as a global npm package. Requires Python and C/C++ to be installed for dependency building. ```bash npm install -g @devcontainers/cli ``` -------------------------------- ### Install Dev Container CLI to Custom Directory Source: https://github.com/devcontainers/cli/blob/main/README.md Installs the Dev Container CLI to a custom directory using the install script. ```bash sh install.sh --prefix ~/.local/devcontainers ``` -------------------------------- ### Implement Idempotent Feature Installation Test Source: https://github.com/devcontainers/cli/blob/main/docs/features/test.md Shows how to write a duplicate.sh script to verify that a feature can be installed multiple times with different configurations without conflict. The script uses environment variables to validate the state of both the randomized and default feature installations. ```bash #!/bin/bash set -e source dev-container-features-test-lib if [ -z "${VERSION}" ]; then echo "Version of dotnet to install from randomized Feature not set!" exit 1 fi if [ -z "${VERSION__DEFAULT}" ]; then echo "Version of dotnet to install default Feature not set!" exit 1 fi check "randomized version of dotnet installed" bash -c "dotnet --list-sdks | ${VERSION}" check "default version of dotnet installed" bash -c "dotnet --list-sdks | ${VERSION__DEFAULT}" reportResults ``` -------------------------------- ### Install Specific Dev Container CLI Version Source: https://github.com/devcontainers/cli/blob/main/README.md Installs a specific version of the Dev Container CLI using the install script. ```bash sh install.sh --version 0.82.0 ``` -------------------------------- ### Compile the CLI with Yarn Source: https://github.com/devcontainers/cli/blob/main/README.md Use these commands to install dependencies and compile the CLI using Yarn. ```sh yarn yarn compile ``` -------------------------------- ### Install Dependencies Locally Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Install project dependencies using yarn. Ensure Docker is running as it's required for the integration test suite. ```sh yarn install ``` -------------------------------- ### Start Dev Build Watchers Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Run these commands in separate terminals to start incremental build watchers. The esbuild watcher rebuilds on save, and the tsc watcher reports type errors. ```shell npm run watch ``` ```shell npm run type-check-watch ``` -------------------------------- ### Package CLI for Testing Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Before running tests, package the CLI into a tarball using 'npm run package'. This step is crucial as tests install the CLI from this generated tarball. ```shell npm run package ``` -------------------------------- ### Update Dev Container CLI Source: https://github.com/devcontainers/cli/blob/main/README.md Updates an existing Dev Container CLI installation to the latest version. ```bash sh install.sh --update ``` -------------------------------- ### Implement Feature Test Script Source: https://github.com/devcontainers/cli/blob/main/docs/features/test.md A shell script used to validate the state of a container after a Feature is installed. It utilizes the dev-container-features-test-lib to perform assertions on the environment. ```bash #!/bin/bash set -e # Import test library for `check` command source dev-container-features-test-lib check "Oryx version" oryx --version check "Dotnet is not removed if it is not installed by the Oryx Feature" dotnet --version # Install platforms with oryx build tool check "oryx-install-dotnet-2.1" oryx prep --skip-detection --platforms-and-versions dotnet=2.1.30 check "dotnet-2-installed-by-oryx" ls /opt/dotnet/ | grep 2.1 ``` -------------------------------- ### Verify CLI Help Text Source: https://github.com/devcontainers/cli/blob/main/README.md Run this command to ensure the CLI is executable and to view its help information. ```sh node devcontainer.js --help ``` -------------------------------- ### Run All Tests Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Execute the full test suite using 'npm test'. Consider running subsets of tests during development for faster feedback. ```shell npm test ``` -------------------------------- ### Register QEMU Emulators for Cross-Architecture Builds Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Register QEMU emulators to run tests that build containers for non-native architectures. This command is needed once per boot or WSL session on Windows. Not required on macOS with Docker Desktop. ```sh docker run --privileged --rm tonistiigi/binfmt --install all ``` -------------------------------- ### Apply a Dev Container Template using CLI Source: https://github.com/devcontainers/cli/blob/main/docs/templates/apply.md This command initializes a new project folder and applies the Debian template from the devcontainers registry. It demonstrates the use of the -t flag for the template source, -a for template arguments, and -w for the target workspace directory. ```bash mkdir my-project devcontainer templates apply \ -t 'ghcr.io/devcontainers/templates/debian' \ -a '{"imageVariant": "buster"}' \ -w ./my-project ``` -------------------------------- ### Dev Container CLI Help Command Source: https://github.com/devcontainers/cli/blob/main/README.md Displays the available commands and options for the Dev Container CLI. ```bash devcontainer ``` -------------------------------- ### Configure Scenario Build with Dockerfile Source: https://github.com/devcontainers/cli/blob/main/docs/features/test.md Demonstrates how to include a custom Dockerfile in a Dev Container feature test scenario. By placing the Dockerfile in a folder matching the scenario name within the test directory, the CLI automatically copies it into the intermediate .devcontainer build folder. ```jsonc "frowning_with_a_dockerfile": { "build": { "dockerfile": "Dockerfile" }, "features": { "smile": { "shouldFrown": true } } } ``` -------------------------------- ### One-shot Build and Clean Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Use 'npm run compile' for a single build or 'npm run clean' to remove all build output. ```shell npm run compile ``` ```shell npm run clean ``` -------------------------------- ### Clone the Repository Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Clone the Dev Containers CLI repository to your local machine and navigate into the directory. ```sh git clone https://github.com//cli.git cd cli ``` -------------------------------- ### Pre-commit Validation Checks Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Before committing, run these checks to ensure code quality and consistency. This includes a full type-check, production build and packaging, linting, formatting, and the full test suite. ```shell npm run type-check ``` ```shell npm run package ``` ```shell npm run precommit ``` ```shell npm test ``` -------------------------------- ### Execute Command in Dev Container Source: https://github.com/devcontainers/cli/blob/main/README.md Executes a command (e.g., 'cargo run') within the running dev container. Replace with the actual path. ```bash devcontainer exec --workspace-folder cargo run ``` -------------------------------- ### Define Feature Test Scenarios Source: https://github.com/devcontainers/cli/blob/main/docs/features/test.md A JSON configuration file used to define complex test scenarios. It maps test names to devcontainer.json configurations, allowing for multi-feature testing with specific options. ```json { "install_dotnet_and_oryx": { "image": "ubuntu:focal", "features": { "dotnet": { "version": "6", "installUsingApt": "false" }, "oryx": {} } } } ``` -------------------------------- ### Invoke CLI Directly Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md After building, you can invoke the CLI directly using 'node devcontainer.js' followed by the desired command and arguments. ```shell node devcontainer.js --help ``` ```shell node devcontainer.js up --workspace-folder ``` ```shell node devcontainer.js build --workspace-folder ``` ```shell node devcontainer.js run-user-commands --workspace-folder ``` -------------------------------- ### Run Specific Test Suites Source: https://github.com/devcontainers/cli/blob/main/docs/contributing-code.md Run only the Features tests with 'npm run test-container-features' or only the Templates tests with 'npm run test-container-templates'. ```shell npm run test-container-features ``` ```shell npm run test-container-templates ``` -------------------------------- ### check