Skip to content

epoch8/devcontainer-features

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dev Container Features

This repo hosts a collection of custom dev container Features, published to GitHub Container Registry. It follows the dev container Feature distribution specification and was bootstrapped from the official feature-starter template.

Features

homebrew-packages

Installs a list of Homebrew packages in one shot. A specific version can be pinned per package with @, e.g. wget@1.21.

{
    "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
    "features": {
        "ghcr.io/epoch8/devcontainer-features/homebrew-packages:1": {
            "packages": "jq wget python@3.11"
        }
    }
}
$ jq --version
jq-1.7.1

$ python3.11 --version
Python 3.11.15

See src/homebrew-packages/README.md for the full list of options.

Repo and Feature Structure

Similar to the 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
│   ├── homebrew-packages
│   │   ├── devcontainer-feature.json
│   │   ├── install.sh
│   │   └── README.md
|   ├── ...
│   │   ├── devcontainer-feature.json
│   │   └── install.sh
...

An implementing tool will composite the documented dev container 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.

For example, the homebrew-packages feature provides a packages string option, defaulting to an empty list. If empty, the install script skips installing Homebrew entirely.

{
    // ...
    "options": {
        "packages": {
            "type": "string",
            "default": "",
            "description": "Space-separated list of Homebrew packages to install."
        }
    }
}

Options are exported as Feature-scoped environment variables. The option name is capitalized and sanitized according to option resolution.

#!/bin/bash

echo "Activating feature 'homebrew-packages'"
echo "Packages to install: ${PACKAGES}"

...

Testing

Each Feature has autogenerated and scenario-based tests under test/<feature>/. They run via the devcontainer CLI:

npx @devcontainers/cli features test --skip-scenarios -f homebrew-packages -i mcr.microsoft.com/devcontainers/base:ubuntu .
npx @devcontainers/cli features test -f homebrew-packages --skip-autogenerated --skip-duplicated .

CI runs the same commands via .github/workflows/test.yaml, and .github/workflows/validate.yml validates every devcontainer-feature.json against the spec schema. Both can be exercised locally with act:

act workflow_dispatch -W .github/workflows/validate.yml
act workflow_dispatch -W .github/workflows/test.yaml -j test-autogenerated --container-options "-v /tmp:/tmp"

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.

Publishing

NOTE: The Distribution spec can be found here.

While any registry implementing the OCI Distribution spec can be used, this repo leverages 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 that will publish each Feature to GHCR, triggered manually via workflow_dispatch on main.

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/<feature>/README.md per Feature (which merges any existing src/<feature>/NOTES.md).

By default, each Feature is prefixed with the <owner>/<repo> namespace. For example, the Feature in this repository can be referenced in a devcontainer.json with:

ghcr.io/epoch8/devcontainer-features/homebrew-packages:1

The provided GitHub Action will also publish a third "metadata" package with just the namespace, eg: ghcr.io/epoch8/devcontainer-features. This contains information useful for tools aiding in Feature discovery.

'epoch8/devcontainer-features' 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/<owner>/packages/container/<repo>%2F<featureName>/settings

image

Adding Features to the Index

If you'd like your Features to appear in the public index so that other community members can find them, you can do the following:

This index is from where supporting tools like VS Code Dev Containers and GitHub 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.

{
    "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
    "features": {
     "ghcr.io/epoch8/devcontainer-features/homebrew-packages:1": {
            "packages": "jq"
        }
    },
    "customizations": {
        "codespaces": {
            "repositories": {
                "epoch8/devcontainer-features": {
                    "permissions": {
                        "packages": "read",
                        "contents": "read"
                    }
                }
            }
        }
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages