From 335f829ada70d17b22f5a2f24530a935108bbd82 Mon Sep 17 00:00:00 2001 From: realSergiy Date: Wed, 20 Mar 2024 01:50:13 +1100 Subject: [PATCH] feat: git-subtree * feat(git-subtree): add a feature for the git module --- .github/workflows/release.yaml | 4 +- .github/workflows/test.yaml | 18 +- .github/workflows/validate.yml | 2 +- README.md | 190 +---------------- lib/library_scripts.sh | 198 ++++++++++++++++++ src/color/devcontainer-feature.json | 21 -- src/color/install.sh | 26 --- src/{color => git-subtree}/README.md | 0 src/git-subtree/devcontainer-feature.json | 7 + src/git-subtree/install.sh | 62 ++++++ src/hello/README.md | 26 --- src/hello/devcontainer-feature.json | 22 -- src/hello/install.sh | 29 --- .../{color_and_hello.sh => git-subtree.sh} | 10 +- test/_global/scenarios.json | 9 +- test/color/green.sh | 17 -- test/color/my_favorite_color_is_green.sh | 31 --- test/color/scenarios.json | 33 --- test/{hello => git-subtree}/scenarios.json | 8 +- .../successfully-installed.sh} | 2 +- test/{color => git-subtree}/test.sh | 6 +- test/hello/hello.sh | 17 -- test/hello/test.sh | 47 ----- 23 files changed, 297 insertions(+), 488 deletions(-) create mode 100644 lib/library_scripts.sh delete mode 100644 src/color/devcontainer-feature.json delete mode 100644 src/color/install.sh rename src/{color => git-subtree}/README.md (100%) create mode 100644 src/git-subtree/devcontainer-feature.json create mode 100644 src/git-subtree/install.sh delete mode 100644 src/hello/README.md delete mode 100644 src/hello/devcontainer-feature.json delete mode 100644 src/hello/install.sh rename test/_global/{color_and_hello.sh => git-subtree.sh} (75%) 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 rename test/{hello => git-subtree}/scenarios.json (53%) rename test/{color/gold.sh => git-subtree/successfully-installed.sh} (84%) rename test/{color => git-subtree}/test.sh (90%) delete mode 100644 test/hello/hello.sh delete mode 100644 test/hello/test.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9ba1e62..d6c0484 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: "Release dev container features & Generate Documentation" +name: "Release - Feature and Documentation" on: workflow_dispatch: @@ -11,7 +11,7 @@ jobs: pull-requests: write packages: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "Publish Features" uses: devcontainers/action@v1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9a32de6..e5fca57 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: "CI - Test Features" +name: "Test Features" on: push: branches: @@ -13,14 +13,13 @@ jobs: strategy: matrix: features: - - color - - hello + - git-subtree baseImage: - - debian:latest - - ubuntu:latest + # - debian:latest + # - ubuntu:latest - mcr.microsoft.com/devcontainers/base:ubuntu steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "Install latest devcontainer CLI" run: npm install -g @devcontainers/cli @@ -34,10 +33,9 @@ jobs: strategy: matrix: features: - - color - - hello + - git-subtree steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "Install latest devcontainer CLI" run: npm install -g @devcontainers/cli @@ -49,7 +47,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "Install latest devcontainer CLI" run: npm install -g @devcontainers/cli diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5dcc21b..863418e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -7,7 +7,7 @@ jobs: validate: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "Validate devcontainer-feature.json files" uses: devcontainers/action@v1 diff --git a/README.md b/README.md index 1a1cea8..694ff35 100644 --- a/README.md +++ b/README.md @@ -1,188 +1,10 @@ -# Dev Container Features: Self Authoring Template +# Dev Container Features by @realSergiy -> 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). +This repo contains a _collection_ of custom [Dev Container Features](https://containers.dev/implementors/features/) and is based on the [starter template](https://github.com/devcontainers/feature-starter) -## Example Contents +## Contents -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. +### [`git subtree`](https://manpages.debian.org/testing/git-man/git-subtree.1.en.html) -### `hello` - -Running `hello` inside the built container will print the greeting provided to it via its `greeting` option. - -```jsonc -{ - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "ghcr.io/devcontainers/feature-starter/hello:1": { - "greeting": "Hello" - } - } -} -``` - -```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 -│ │ ├── devcontainer-feature.json -│ │ └── install.sh -| ├── ... -│ │ ├── devcontainer-feature.json -│ │ └── 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" - } - } - } - } - } -} -``` +Allows to drag, modify and merge replicas of a git repository that has been dragged into the main repository. +[Read more...](https://gist.github.com/SKempin/b7857a6ff6bddb05717cc17a44091202) diff --git a/lib/library_scripts.sh b/lib/library_scripts.sh new file mode 100644 index 0000000..a974eef --- /dev/null +++ b/lib/library_scripts.sh @@ -0,0 +1,198 @@ +#!/bin/bash -i + +# MIT License +# +# Copyright (c) 2022 devcontainers-contrib +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +clean_download() { + # The purpose of this function is to download a file with minimal impact on contaier 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="" + + function _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 + } + + function _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 + } + + function _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 + } + + function _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 + # normalize version + if ! [[ $required_version == v* ]]; then + required_version=v$required_version + fi + + 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 == v* ]]; then + current_version=v$current_version + fi + + 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 + declare -g ${variable_name}=$nanolayer_location + +} \ No newline at end of file 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/color/README.md b/src/git-subtree/README.md similarity index 100% rename from src/color/README.md rename to src/git-subtree/README.md diff --git a/src/git-subtree/devcontainer-feature.json b/src/git-subtree/devcontainer-feature.json new file mode 100644 index 0000000..a711480 --- /dev/null +++ b/src/git-subtree/devcontainer-feature.json @@ -0,0 +1,7 @@ +{ + "name": "git subtree (for Debian/Ubuntu)", + "documentationURL": "https://manpages.debian.org/testing/git-man/git-subtree.1.en.html", + "id": "git-subtree", + "version": "0.0.1", + "description": "Installs 'git subtree' on Ubuntu" +} diff --git a/src/git-subtree/install.sh b/src/git-subtree/install.sh new file mode 100644 index 0000000..36bbf84 --- /dev/null +++ b/src/git-subtree/install.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# 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'" + +set -e + +echo "Activating feature 'git-subtree'..." + +# Store the initial directory +INITIAL_DIR=$(pwd) + +# Get the git executable directory +GIT_EXEC_PATH=$(git --exec-path) +echo "Git found in $GIT_EXEC_PATH" + +# Clone git source into /tmp for temporary use +echo "Cloning git source into /tmp..." +cd /tmp +git clone https://github.com/git/git.git + +# Navigate to the contrib/subtree directory +cd git/contrib/subtree + +# Prepare subtree +echo "Preparing git-subtree..." +make + +# Install git-subtree to the correct location +echo "Installing git-subtree to $GIT_EXEC_PATH..." +install -m 755 git-subtree "$GIT_EXEC_PATH" + +# Clean up +echo "Removing temporary git source..." +rm -rf /tmp/git + +# Source the appropriate profile to update PATH +if [[ -f ~/.bashrc ]]; then + source ~/.bashrc +elif [[ -f ~/.profile ]]; then + source ~/.profile +fi + +cd $INITIAL_DIR + +# Verification +echo "Verifying git subtree installation..." +if git subtree --help >/dev/null 2>&1; then + echo "Git subtree installation successful!" +else + echo "Git subtree installation may have failed. Error output:" + git subtree help # No redirection here for error visibility +fi 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/test/_global/color_and_hello.sh b/test/_global/git-subtree.sh similarity index 75% rename from test/_global/color_and_hello.sh rename to test/_global/git-subtree.sh index 9a08758..496398c 100644 --- a/test/_global/color_and_hello.sh +++ b/test/_global/git-subtree.sh @@ -16,16 +16,14 @@ 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 "The result of the \"'git subtree | grep 'git subtree'\" command will be:\n" +git subtree | grep 'git subtree' 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)'" +# 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 diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index b046998..b36501e 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -1,13 +1,8 @@ { - "color_and_hello": { + "git-subtree": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { - "color": { - "favorite": "purple" - }, - "hello": { - "greeting": "Greetings" - } + "git-subtree": {} } } } \ No newline at end of file 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/hello/scenarios.json b/test/git-subtree/scenarios.json similarity index 53% rename from test/hello/scenarios.json rename to test/git-subtree/scenarios.json index 3ebe7a1..b172d51 100644 --- a/test/hello/scenarios.json +++ b/test/git-subtree/scenarios.json @@ -1,10 +1,8 @@ { - "hello": { + "successfully-installed": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { - "hello": { - "greeting": "hello" - } + "git-subtree": {} } } -} +} \ No newline at end of file diff --git a/test/color/gold.sh b/test/git-subtree/successfully-installed.sh similarity index 84% rename from test/color/gold.sh rename to test/git-subtree/successfully-installed.sh index 1aaa9aa..e7bfe57 100644 --- a/test/color/gold.sh +++ b/test/git-subtree/successfully-installed.sh @@ -10,7 +10,7 @@ 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'" +check "execute command" bash -c "git subtree add --help | grep 'usage: git subtree add'" # Report result # If any of the checks above exited with a non-zero exit code, the test will fail. diff --git a/test/color/test.sh b/test/git-subtree/test.sh similarity index 90% rename from test/color/test.sh rename to test/git-subtree/test.sh index bab0fa3..671ed11 100644 --- a/test/color/test.sh +++ b/test/git-subtree/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # This test file will be executed against an auto-generated devcontainer.json that -# includes the 'color' Feature with no options. +# includes the 'git-subtree' Feature with no options. # # For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md # @@ -9,7 +9,7 @@ # { # "image": "<..some-base-image...>", # "features": { -# "color": {} +# "git-subtree": {} # }, # "remoteUser": "root" # } @@ -40,7 +40,7 @@ source dev-container-features-test-lib # Feature-specific tests # The 'check' command comes from the dev-container-features-test-lib. Syntax is... # check