From 557b1e18c98ff4d54808300585e1ce629dc4ef33 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Sat, 20 Apr 2024 22:03:29 +0700 Subject: [PATCH 1/6] feat: add otelcol --- .github/workflows/test.yaml | 6 +- .idea/.gitignore | 8 ++ README.md | 165 +--------------------- src/color/README.md | 26 ---- src/color/devcontainer-feature.json | 21 --- src/color/install.sh | 26 ---- src/hello/README.md | 26 ---- src/hello/devcontainer-feature.json | 22 --- src/hello/install.sh | 29 ---- src/otelcol/README.md | 20 +++ src/otelcol/devcontainer-feature.json | 20 +++ src/otelcol/install.sh | 23 +++ src/otelcol/library_scripts.sh | 172 +++++++++++++++++++++++ test/_global/color_and_hello.sh | 33 ----- test/_global/scenarios.json | 13 -- test/color/gold.sh | 17 --- test/color/green.sh | 17 --- test/color/my_favorite_color_is_green.sh | 31 ---- test/color/scenarios.json | 33 ----- test/color/test.sh | 47 ------- test/hello/hello.sh | 17 --- test/hello/scenarios.json | 10 -- test/hello/test.sh | 47 ------- test/otelcol/scenarios.json | 8 ++ test/otelcol/test_defaults_debian.sh | 9 ++ 25 files changed, 267 insertions(+), 579 deletions(-) create mode 100644 .idea/.gitignore delete mode 100644 src/color/README.md delete mode 100644 src/color/devcontainer-feature.json delete mode 100644 src/color/install.sh delete mode 100644 src/hello/README.md delete mode 100644 src/hello/devcontainer-feature.json delete mode 100644 src/hello/install.sh create mode 100644 src/otelcol/README.md create mode 100644 src/otelcol/devcontainer-feature.json create mode 100755 src/otelcol/install.sh create mode 100644 src/otelcol/library_scripts.sh delete mode 100644 test/_global/color_and_hello.sh delete mode 100644 test/_global/scenarios.json delete mode 100644 test/color/gold.sh delete mode 100644 test/color/green.sh delete mode 100644 test/color/my_favorite_color_is_green.sh delete mode 100644 test/color/scenarios.json delete mode 100644 test/color/test.sh delete mode 100644 test/hello/hello.sh delete mode 100644 test/hello/scenarios.json delete mode 100644 test/hello/test.sh create mode 100644 test/otelcol/scenarios.json create mode 100755 test/otelcol/test_defaults_debian.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9a32de6..1bb403f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,8 +13,7 @@ jobs: strategy: matrix: features: - - color - - hello + - otelcol baseImage: - debian:latest - ubuntu:latest @@ -34,8 +33,7 @@ jobs: strategy: matrix: features: - - color - - hello + - otelcol steps: - uses: actions/checkout@v3 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/README.md b/README.md index 1a1cea8..4aa0e1d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ -# Dev Container Features: Self Authoring Template +# Dev Container Features - OpenTelemetry Toolkit -> This repo provides a starting point and example for creating your own custom [dev container Features](https://containers.dev/implementors/features/), hosted for free on GitHub Container Registry. The example in this repository follows the [dev container Feature distribution specification](https://containers.dev/implementors/features-distribution/). -> -> To provide feedback to the specification, please leave a comment [on spec issue #70](https://github.com/devcontainers/spec/issues/70). For more broad feedback regarding dev container Features, please see [spec issue #61](https://github.com/devcontainers/spec/issues/61). +## Contents -## Example Contents +This repository contains a features: `otelcol` -This repository contains a _collection_ of two Features - `hello` and `color`. These Features serve as simple feature implementations. Each sub-section below shows a sample `devcontainer.json` alongside example usage of the Feature. - -### `hello` - -Running `hello` inside the built container will print the greeting provided to it via its `greeting` option. +### `otelcol` ```jsonc { @@ -23,43 +17,13 @@ Running `hello` inside the built container will print the greeting provided to i } ``` -```bash -$ hello - -Hello, user. -``` - -### `color` - -Running `color` inside the built container will print your favorite color to standard out. - -```jsonc -{ - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "ghcr.io/devcontainers/feature-starter/color:1": { - "favorite": "green" - } - } -} -``` - -```bash -$ color - -my favorite color is green -``` - ## Repo and Feature Structure Similar to the [`devcontainers/features`](https://github.com/devcontainers/features) repo, this repository has a `src` folder. Each Feature has its own sub-folder, containing at least a `devcontainer-feature.json` and an entrypoint script `install.sh`. ``` ├── src -│ ├── hello -│ │ ├── devcontainer-feature.json -│ │ └── install.sh -│ ├── color +│ ├── otelcol │ │ ├── devcontainer-feature.json │ │ └── install.sh | ├── ... @@ -67,122 +31,3 @@ Similar to the [`devcontainers/features`](https://github.com/devcontainers/featu │ │ └── install.sh ... ``` - -An [implementing tool](https://containers.dev/supporting#tools) will composite [the documented dev container properties](https://containers.dev/implementors/features/#devcontainer-feature-json-properties) from the feature's `devcontainer-feature.json` file, and execute in the `install.sh` entrypoint script in the container during build time. Implementing tools are also free to process attributes under the `customizations` property as desired. - -### Options - -All available options for a Feature should be declared in the `devcontainer-feature.json`. The syntax for the `options` property can be found in the [devcontainer Feature json properties reference](https://containers.dev/implementors/features/#devcontainer-feature-json-properties). - -For example, the `color` feature provides an enum of three possible options (`red`, `gold`, `green`). If no option is provided in a user's `devcontainer.json`, the value is set to "red". - -```jsonc -{ - // ... - "options": { - "favorite": { - "type": "string", - "enum": [ - "red", - "gold", - "green" - ], - "default": "red", - "description": "Choose your favorite color." - } - } -} -``` - -Options are exported as Feature-scoped environment variables. The option name is captialized and sanitized according to [option resolution](https://containers.dev/implementors/features/#option-resolution). - -```bash -#!/bin/bash - -echo "Activating feature 'color'" -echo "The provided favorite color is: ${FAVORITE}" - -... -``` - -## Distributing Features - -### Versioning - -Features are individually versioned by the `version` attribute in a Feature's `devcontainer-feature.json`. Features are versioned according to the semver specification. More details can be found in [the dev container Feature specification](https://containers.dev/implementors/features/#versioning). - -### Publishing - -> NOTE: The Distribution spec can be [found here](https://containers.dev/implementors/features-distribution/). -> -> While any registry [implementing the OCI Distribution spec](https://github.com/opencontainers/distribution-spec) can be used, this template will leverage GHCR (GitHub Container Registry) as the backing registry. - -Features are meant to be easily sharable units of dev container configuration and installation code. - -This repo contains a **GitHub Action** [workflow](.github/workflows/release.yaml) that will publish each Feature to GHCR. - -*Allow GitHub Actions to create and approve pull requests* should be enabled in the repository's `Settings > Actions > General > Workflow permissions` for auto generation of `src//README.md` per Feature (which merges any existing `src//NOTES.md`). - -By default, each Feature will be prefixed with the `` namespace. For example, the two Features in this repository can be referenced in a `devcontainer.json` with: - -``` -ghcr.io/devcontainers/feature-starter/color:1 -ghcr.io/devcontainers/feature-starter/hello:1 -``` - -The provided GitHub Action will also publish a third "metadata" package with just the namespace, eg: `ghcr.io/devcontainers/feature-starter`. This contains information useful for tools aiding in Feature discovery. - -'`devcontainers/feature-starter`' is known as the feature collection namespace. - -### Marking Feature Public - -Note that by default, GHCR packages are marked as `private`. To stay within the free tier, Features need to be marked as `public`. - -This can be done by navigating to the Feature's "package settings" page in GHCR, and setting the visibility to 'public`. The URL may look something like: - -``` -https://github.com/users//packages/container/%2F/settings -``` - -image - -### Adding Features to the Index - -If you'd like your Features to appear in our [public index](https://containers.dev/features) so that other community members can find them, you can do the following: - -* Go to [github.com/devcontainers/devcontainers.github.io](https://github.com/devcontainers/devcontainers.github.io) - * This is the GitHub repo backing the [containers.dev](https://containers.dev/) spec site -* Open a PR to modify the [collection-index.yml](https://github.com/devcontainers/devcontainers.github.io/blob/gh-pages/_data/collection-index.yml) file - -This index is from where [supporting tools](https://containers.dev/supporting) like [VS Code Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) and [GitHub Codespaces](https://github.com/features/codespaces) surface Features for their dev container creation UI. - -#### Using private Features in Codespaces - -For any Features hosted in GHCR that are kept private, the `GITHUB_TOKEN` access token in your environment will need to have `package:read` and `contents:read` for the associated repository. - -Many implementing tools use a broadly scoped access token and will work automatically. GitHub Codespaces uses repo-scoped tokens, and therefore you'll need to add the permissions in `devcontainer.json` - -An example `devcontainer.json` can be found below. - -```jsonc -{ - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "ghcr.io/my-org/private-features/hello:1": { - "greeting": "Hello" - } - }, - "customizations": { - "codespaces": { - "repositories": { - "my-org/private-features": { - "permissions": { - "packages": "read", - "contents": "read" - } - } - } - } - } -} -``` diff --git a/src/color/README.md b/src/color/README.md deleted file mode 100644 index a1e7d1b..0000000 --- a/src/color/README.md +++ /dev/null @@ -1,26 +0,0 @@ - -# My Favorite Color (color) - -A feature to remind you of your favorite color - -## Example Usage - -```json -"features": { - "ghcr.io/devcontainers/feature-starter/color:1": { - "version": "latest" - } -} -``` - -## Options - -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| favorite | Choose your favorite color. | string | red | - - - ---- - -_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/feature-starter/blob/main/src/color/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/color/devcontainer-feature.json b/src/color/devcontainer-feature.json deleted file mode 100644 index e14e7e7..0000000 --- a/src/color/devcontainer-feature.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "My Favorite Color", - "id": "color", - "version": "1.0.3", - "description": "A feature to remind you of your favorite color", - "options": { - "favorite": { - "type": "string", - "enum": [ - "red", - "gold", - "green" - ], - "default": "red", - "description": "Choose your favorite color." - } - }, - "installsAfter": [ - "ghcr.io/devcontainers/features/common-utils" - ] -} diff --git a/src/color/install.sh b/src/color/install.sh deleted file mode 100644 index 883c25d..0000000 --- a/src/color/install.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -set -e - -echo "Activating feature 'color'" -echo "The provided favorite color is: ${FAVORITE}" - - -# The 'install.sh' entrypoint script is always executed as the root user. -# -# These following environment variables are passed in by the dev container CLI. -# These may be useful in instances where the context of the final -# remoteUser or containerUser is useful. -# For more details, see https://containers.dev/implementors/features#user-env-var -echo "The effective dev container remoteUser is '$_REMOTE_USER'" -echo "The effective dev container remoteUser's home directory is '$_REMOTE_USER_HOME'" - -echo "The effective dev container containerUser is '$_CONTAINER_USER'" -echo "The effective dev container containerUser's home directory is '$_CONTAINER_USER_HOME'" - -cat > /usr/local/bin/color \ -<< EOF -#!/bin/sh -echo "my favorite color is ${FAVORITE}" -EOF - -chmod +x /usr/local/bin/color diff --git a/src/hello/README.md b/src/hello/README.md deleted file mode 100644 index 142e101..0000000 --- a/src/hello/README.md +++ /dev/null @@ -1,26 +0,0 @@ - -# Hello, World! (hello) - -A hello world feature - -## Example Usage - -```json -"features": { - "ghcr.io/devcontainers/feature-starter/hello:1": { - "version": "latest" - } -} -``` - -## Options - -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| greeting | Select a pre-made greeting, or enter your own | string | hey | - - - ---- - -_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/feature-starter/blob/main/src/hello/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/hello/devcontainer-feature.json b/src/hello/devcontainer-feature.json deleted file mode 100644 index e2a3178..0000000 --- a/src/hello/devcontainer-feature.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "Hello, World!", - "id": "hello", - "version": "1.0.2", - "description": "A hello world feature", - "options": { - "greeting": { - "type": "string", - "proposals": [ - "hey", - "hello", - "hi", - "howdy" - ], - "default": "hey", - "description": "Select a pre-made greeting, or enter your own" - } - }, - "installsAfter": [ - "ghcr.io/devcontainers/features/common-utils" - ] -} diff --git a/src/hello/install.sh b/src/hello/install.sh deleted file mode 100644 index 480e262..0000000 --- a/src/hello/install.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -set -e - -echo "Activating feature 'hello'" - -GREETING=${GREETING:-undefined} -echo "The provided greeting is: $GREETING" - -# The 'install.sh' entrypoint script is always executed as the root user. -# -# These following environment variables are passed in by the dev container CLI. -# These may be useful in instances where the context of the final -# remoteUser or containerUser is useful. -# For more details, see https://containers.dev/implementors/features#user-env-var -echo "The effective dev container remoteUser is '$_REMOTE_USER'" -echo "The effective dev container remoteUser's home directory is '$_REMOTE_USER_HOME'" - -echo "The effective dev container containerUser is '$_CONTAINER_USER'" -echo "The effective dev container containerUser's home directory is '$_CONTAINER_USER_HOME'" - -cat > /usr/local/bin/hello \ -<< EOF -#!/bin/sh -RED='\033[0;91m' -NC='\033[0m' # No Color -echo "\${RED}${GREETING}, \$(whoami)!\${NC}" -EOF - -chmod +x /usr/local/bin/hello \ No newline at end of file diff --git a/src/otelcol/README.md b/src/otelcol/README.md new file mode 100644 index 0000000..c57abc5 --- /dev/null +++ b/src/otelcol/README.md @@ -0,0 +1,20 @@ + +# otelcol (via Github Releases) (otelcol) + +OpenTelemetry Collector Core Distro. + +## Example DevContainer Usage + +```json +"features": { + "ghcr.io/tranngoclam/otel-devcontainer-features/otelcol:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select the version to install. | string | latest | + + diff --git a/src/otelcol/devcontainer-feature.json b/src/otelcol/devcontainer-feature.json new file mode 100644 index 0000000..fa6a49e --- /dev/null +++ b/src/otelcol/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "id": "otelcol", + "version": "1.0.0", + "name": "otelcol (via Github Releases)", + "documentationURL": "http://github.com/tranngoclam/otel-devcontainer-features/tree/main/src/otelcol", + "description": "OpenTelemetry Collector Core Distro.", + "options": { + "version": { + "default": "latest", + "description": "Select the version to install.", + "proposals": [ + "latest" + ], + "type": "string" + } + }, + "installsAfter": [ + "ghcr.io/devcontainers-contrib/features/gh-release" + ] +} \ No newline at end of file diff --git a/src/otelcol/install.sh b/src/otelcol/install.sh new file mode 100755 index 0000000..19d92eb --- /dev/null +++ b/src/otelcol/install.sh @@ -0,0 +1,23 @@ + +set -e + +. ./library_scripts.sh + +# nanolayer is a cli utility which keeps container layers as small as possible +# source code: https://github.com/devcontainers-contrib/nanolayer +# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations, +# and if missing - will download a temporary copy that automatically get deleted at the end +# of the script +ensure_nanolayer nanolayer_location "v0.5.6" + + +$nanolayer_location \ + install \ + devcontainer-feature \ + "ghcr.io/devcontainers-contrib/features/gh-release:1.0.23" \ + --option repo='open-telemetry/opentelemetry-collector-releases' --option binaryNames='otelcol' --option version="$VERSION" + + + +echo 'Done!' + diff --git a/src/otelcol/library_scripts.sh b/src/otelcol/library_scripts.sh new file mode 100644 index 0000000..0d7f34d --- /dev/null +++ b/src/otelcol/library_scripts.sh @@ -0,0 +1,172 @@ + + +clean_download() { + # The purpose of this function is to download a file with minimal impact on container layer size + # this means if no valid downloader is found (curl or wget) then we install a downloader (currently wget) in a + # temporary manner, and making sure to + # 1. uninstall the downloader at the return of the function + # 2. revert back any changes to the package installer database/cache (for example apt-get lists) + # The above steps will minimize the leftovers being created while installing the downloader + # Supported distros: + # debian/ubuntu/alpine + + url=$1 + output_location=$2 + tempdir=$(mktemp -d) + downloader_installed="" + + _apt_get_install() { + tempdir=$1 + + # copy current state of apt list - in order to revert back later (minimize contianer layer size) + cp -p -R /var/lib/apt/lists $tempdir + apt-get update -y + apt-get -y install --no-install-recommends wget ca-certificates + } + + _apt_get_cleanup() { + tempdir=$1 + + echo "removing wget" + apt-get -y purge wget --auto-remove + + echo "revert back apt lists" + rm -rf /var/lib/apt/lists/* + rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists + } + + _apk_install() { + tempdir=$1 + # copy current state of apk cache - in order to revert back later (minimize contianer layer size) + cp -p -R /var/cache/apk $tempdir + + apk add --no-cache wget + } + + _apk_cleanup() { + tempdir=$1 + + echo "removing wget" + apk del wget + } + # try to use either wget or curl if one of them already installer + if type curl >/dev/null 2>&1; then + downloader=curl + elif type wget >/dev/null 2>&1; then + downloader=wget + else + downloader="" + fi + + # in case none of them is installed, install wget temporarly + if [ -z $downloader ] ; then + if [ -x "/usr/bin/apt-get" ] ; then + _apt_get_install $tempdir + elif [ -x "/sbin/apk" ] ; then + _apk_install $tempdir + else + echo "distro not supported" + exit 1 + fi + downloader="wget" + downloader_installed="true" + fi + + if [ $downloader = "wget" ] ; then + wget -q $url -O $output_location + else + curl -sfL $url -o $output_location + fi + + # NOTE: the cleanup procedure was not implemented using `trap X RETURN` only because + # alpine lack bash, and RETURN is not a valid signal under sh shell + if ! [ -z $downloader_installed ] ; then + if [ -x "/usr/bin/apt-get" ] ; then + _apt_get_cleanup $tempdir + elif [ -x "/sbin/apk" ] ; then + _apk_cleanup $tempdir + else + echo "distro not supported" + exit 1 + fi + fi + +} + + +ensure_nanolayer() { + # Ensure existance of the nanolayer cli program + local variable_name=$1 + + local required_version=$2 + + local __nanolayer_location="" + + # If possible - try to use an already installed nanolayer + if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then + if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then + if type nanolayer >/dev/null 2>&1; then + echo "Found a pre-existing nanolayer in PATH" + __nanolayer_location=nanolayer + fi + elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then + __nanolayer_location=${NANOLAYER_CLI_LOCATION} + echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location" + fi + + # make sure its of the required version + if ! [ -z "${__nanolayer_location}" ]; then + local current_version + current_version=$($__nanolayer_location --version) + + + if ! [ $current_version == $required_version ]; then + echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)" + __nanolayer_location="" + fi + fi + + fi + + # If not previuse installation found, download it temporarly and delete at the end of the script + if [ -z "${__nanolayer_location}" ]; then + + if [ "$(uname -sm)" = 'Linux x86_64' ] || [ "$(uname -sm)" = "Linux aarch64" ]; then + tmp_dir=$(mktemp -d -t nanolayer-XXXXXXXXXX) + + clean_up () { + ARG=$? + rm -rf $tmp_dir + exit $ARG + } + trap clean_up EXIT + + + if [ -x "/sbin/apk" ] ; then + clib_type=musl + else + clib_type=gnu + fi + + tar_filename=nanolayer-"$(uname -m)"-unknown-linux-$clib_type.tgz + + # clean download will minimize leftover in case a downloaderlike wget or curl need to be installed + clean_download https://github.com/devcontainers-contrib/cli/releases/download/$required_version/$tar_filename $tmp_dir/$tar_filename + + tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir" + chmod a+x $tmp_dir/nanolayer + __nanolayer_location=$tmp_dir/nanolayer + + + else + echo "No binaries compiled for non-x86-linux architectures yet: $(uname -m)" + exit 1 + fi + fi + + # Expose outside the resolved location + export ${variable_name}=$__nanolayer_location + +} + + diff --git a/test/_global/color_and_hello.sh b/test/_global/color_and_hello.sh deleted file mode 100644 index 9a08758..0000000 --- a/test/_global/color_and_hello.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# The 'test/_global' folder is a special test folder that is not tied to a single feature. -# -# This test file is executed against a running container constructed -# from the value of 'color_and_hello' in the tests/_global/scenarios.json file. -# -# The value of a scenarios element is any properties available in the 'devcontainer.json'. -# Scenarios are useful for testing specific options in a feature, or to test a combination of features. -# -# This test can be run with the following command (from the root of this repo) -# devcontainer features test --global-scenarios-only . - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -source dev-container-features-test-lib - -echo -e "The result of the 'color' command will be:\n" -color -echo -e "The result of the 'hello' command will be:\n" -hello -echo -e "\n" - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. -check "check purple is my favorite color" bash -c "color | grep 'my favorite color is purple'" -check "check I am greeting with 'Greetings'" bash -c "hello | grep 'Greetings, $(whoami)'" - - -# Report result -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json deleted file mode 100644 index b046998..0000000 --- a/test/_global/scenarios.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "color_and_hello": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "color": { - "favorite": "purple" - }, - "hello": { - "greeting": "Greetings" - } - } - } -} \ No newline at end of file diff --git a/test/color/gold.sh b/test/color/gold.sh deleted file mode 100644 index 1aaa9aa..0000000 --- a/test/color/gold.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# This test file will be executed against one of the scenarios devcontainer.json test that -# includes the 'color' feature with "favorite": "gold" option. - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -source dev-container-features-test-lib - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. -check "execute command" bash -c "color | grep 'my favorite color is gold'" - -# Report result -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/color/green.sh b/test/color/green.sh deleted file mode 100644 index 5b55388..0000000 --- a/test/color/green.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# This test file will be executed against one of the scenarios devcontainer.json test that -# includes the 'color' feature with "favorite": "green" option. - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -source dev-container-features-test-lib - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. -check "execute command" bash -c "color | grep 'my favorite color is green'" - -# Report result -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/color/my_favorite_color_is_green.sh b/test/color/my_favorite_color_is_green.sh deleted file mode 100644 index 94e6295..0000000 --- a/test/color/my_favorite_color_is_green.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# This test file will be executed against after building a container with the -# 'my_favorite_color_is_green' scenario in 'test/test/color/scenarios.json'. -# -# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md -# -# This scenario first uses the 'common-utils' Features to add a new user 'octocat'. -# It then installs the 'color' Feature with the FAVORITE option set to 'green' (the default FAVORITE value if none provided is 'red'). -# -# -# This test (as well as any of the other scenarios in 'scenarios.json') can be run with the following command: -# -# devcontainer features test \ -# --features color \ -# --skip-autogenerated \ -# /path/to/this/repo - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -# Provides the 'check' and 'reportResults' commands. -source dev-container-features-test-lib - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. -check "validate favorite color" color | grep 'my favorite color is green' - -# Report result -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/color/scenarios.json b/test/color/scenarios.json deleted file mode 100644 index bfd7952..0000000 --- a/test/color/scenarios.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "my_favorite_color_is_green": { - "image": "mcr.microsoft.com/devcontainers/base:focal", - "features": { - "ghcr.io/devcontainers/features/common-utils:1": { - "installZsh": false, - "installOhMyZsh": false, - "upgradePackages": false, - "username": "octocat" - }, - "color": { - "favorite": "green" - } - }, - "remoteUser": "octocat" - }, - "gold": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "color": { - "favorite": "gold" - } - } - }, - "green": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "color": { - "favorite": "green" - } - } - } -} diff --git a/test/color/test.sh b/test/color/test.sh deleted file mode 100644 index bab0fa3..0000000 --- a/test/color/test.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# This test file will be executed against an auto-generated devcontainer.json that -# includes the 'color' Feature with no options. -# -# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md -# -# Eg: -# { -# "image": "<..some-base-image...>", -# "features": { -# "color": {} -# }, -# "remoteUser": "root" -# } -# -# Thus, the value of all options will fall back to the default value in the -# Feature's 'devcontainer-feature.json'. -# For the 'color' feature, that means the default favorite color is 'red'. -# -# These scripts are run as 'root' by default. Although that can be changed -# with the '--remote-user' flag. -# -# This test can be run with the following command: -# -# devcontainer features test \ -# --features color \ -# --remote-user root \ -# --skip-scenarios \ -# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ -# /path/to/this/repo - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib -# Provides the 'check' and 'reportResults' commands. -source dev-container-features-test-lib - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. Syntax is... -# check