The current Dev Container Feature Options Schema lacks support for array and object types. This limitation hinders the ability to configure features that require lists of values (e.g., dependencies, ports) or key-value mappings (e.g., environment variables, custom settings). Addressing this limitation will enhance the flexibility and usability of the schema.
This proposal aims to address Issue #567.
Extend the Dev Container Feature Options Schema by introducing array and object as valid types for feature options. These new types will enable developers to create more complex and customizable features.
-
Array Type:
- Represents a list of values (e.g., strings, numbers, booleans, or objects).
- Supports optional constraints such as allowed item types and default values.
-
Object Type:
- Represents a mapping of key-value pairs.
- Allows nested structures and supports default values for specific keys.
Below are two examples of how array and object types can be used in feature configurations.
Feature Definition (example-feature/devcontainer-feature.json):
{
"name": "example-feature",
"id": "example",
"description": "A feature that demonstrates the use of array and object types.",
"options": {
"dependencies": {
"type": "array",
"description": "List of software packages to install",
"default": ["git", "curl", "nodejs"]
},
"envVariables": {
"type": "object",
"description": "Environment variables for the container",
"default": {
"NODE_ENV": "development",
"APP_PORT": "3000"
}
}
},
"install": {
"script": "./install.sh",
"args": []
}
}Installation Script (example-feature/install.sh):
#!/bin/bash
# Install dependencies
echo "Installing dependencies..."
for package in "${DEPENDENCIES[@]}"; do
sudo apt-get install -y "$package"
done
# Configure environment variables
echo "Setting up environment variables..."
for key in "${!ENVVARIABLES[@]}"; do
export "$key=${ENVVARIABLES[$key]}"
done
echo "Feature setup complete."Feature Definition (example-feature/devcontainer-feature.json):
{
"name": "example-feature",
"id": "example-http",
"description": "A feature that demonstrates the use of HTTP headers in a configuration.",
"options": {
"httpHeaders": {
"type": "object",
"description": "Custom HTTP headers for the development environment",
"default": {
"Authorization": "Bearer example-token",
"Content-Type": "application/json",
"X-Custom-Header": "DevContainerFeature"
}
}
},
"install": {
"script": "./install-http.sh",
"args": []
}
}Installation Script (example-feature/install-http.sh):
#!/bin/bash
# Apply HTTP headers
echo "Setting up HTTP headers..."
for key in "${!HTTPHEADERS[@]}"; do
echo "Header: $key -> Value: ${HTTPHEADERS[$key]}"
# Example usage: Write headers to a configuration file
echo "$key: ${HTTPHEADERS[$key]}" >> ./http-headers-config.txt
done
echo "Feature setup complete."Below is an example of how a user can configure these features in their devcontainer.json file:
{
"features": {
"ghcr.io/devcontainers/features/example:1": {
"dependencies": ["python3", "pip", "make"],
"envVariables": {
"NODE_ENV": "production",
"APP_PORT": "8080",
"DEBUG": "true"
}
},
"ghcr.io/devcontainers/features/example-http:1": {
"httpHeaders": {
"Authorization": "Bearer user-provided-token",
"X-Custom-Header": "CustomValue",
"Accept-Language": "en-US"
}
}
}
}- Modify the JSON schema to support the
arrayandobjecttypes for feature options. - Add validation logic to ensure proper usage of the new types.
- Update documentation to include guidance on defining and using
arrayandobjecttypes. - Test and validate the functionality with various feature configurations.
- Enhances the flexibility of feature configurations, enabling developers to define richer and more powerful features.
- Simplifies user workflows by reducing the need for workarounds involving concatenated strings, triple escaping quotes or other hacks.
- Increased complexity in validation logic for feature options.
- Potential learning curve for users unfamiliar with JSON schema concepts.
arrayandobjecttypes are supported in the Feature Options Schema.- Example features using these types are implemented and published.
- Comprehensive tests and documentation are provided for the new functionality.