diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index d200207..07b30b8 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -15,6 +15,8 @@ permissions: jobs: publish: runs-on: ubuntu-latest + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d69548a..89f3949 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,6 +9,8 @@ on: jobs: test-global: runs-on: ubuntu-latest + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 863418e..692c030 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -6,6 +6,8 @@ on: jobs: validate: runs-on: ubuntu-latest + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 72de202..353c62d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This repository contains the following DevContainer Features: - **[apptainer](#apptainer)** - Install Apptainer for HPC containerization - **[cmdstan](#cmdstan)** - Install CmdStan (Stan probabilistic programming system) +- **[build-info](#build-info)** - Bakes build-time release version and date metadata directly into a system-wide command - **[renv-cache](#renv-cache)** - Configure R with renv cache - **[fit-sne](#fit-sne)** - Install FIt-SNE for dimensionality reduction - **[mermaid](#mermaid)** - Install Mermaid CLI for diagram generation @@ -85,6 +86,40 @@ The feature downloads the official CmdStan release tarball, pre-compiles the Sta --- +## build-info + +Bakes build-time release version and date metadata directly into a system-wide command `container-info`. + +### Example + +To pass host environment variables (like `IMAGE_VERSION` and `IMAGE_BUILD_DATE` exported in a GitHub Action step) to the container at build time, you can map them in your project's `devcontainer.json` using the `${localEnv:VAR_NAME}` syntax: + +```json +{ + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/MiguelRodo/DevContainerFeatures/build-info:1": { + "version": "${localEnv:IMAGE_VERSION}", + "buildDate": "${localEnv:IMAGE_BUILD_DATE}" + } + } +} +``` + +### Options + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `version` | string | `"development"` | The automated version number injected from the runner host environment. | +| `buildDate` | string | `"unknown"` | The build timestamp injected from the runner host environment. | + +### Notes + +- Creates a secure static metadata file at `/usr/local/etc/container_metadata/build_info.txt`. +- Generates a globally executable command `/usr/local/bin/container-info`. + +--- + ## renv-cache Configures R for development in VS Code, including library paths, GitHub tokens, and package restoration with renv cache. diff --git a/src/build-info/devcontainer-feature.json b/src/build-info/devcontainer-feature.json new file mode 100644 index 0000000..f3d9841 --- /dev/null +++ b/src/build-info/devcontainer-feature.json @@ -0,0 +1,21 @@ +{ + "name": "Container Metadata Injector", + "id": "build-info", + "version": "1.0.0", + "description": "Bakes build-time release version and date metadata from GHA directly into a system-wide command.", + "options": { + "version": { + "type": "string", + "default": "development", + "description": "The automated version number injected from the runner host environment." + }, + "buildDate": { + "type": "string", + "default": "unknown", + "description": "The build timestamp injected from the runner host environment." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} \ No newline at end of file diff --git a/src/build-info/install.sh b/src/build-info/install.sh new file mode 100755 index 0000000..cb04ca1 --- /dev/null +++ b/src/build-info/install.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -e + +VERSION="${VERSION:-"development"}" +BUILD_DATE="${BUILDDATE:-"unknown"}" + +DATA_DIR="/usr/local/etc/container_metadata" +mkdir -p "$DATA_DIR" + +cat << EOF > "${DATA_DIR}/build_info.txt" +CONTAINER_VERSION="${VERSION}" +BUILD_DATE="${BUILD_DATE}" +EOF + +COMMAND_PATH="/usr/local/bin/container-info" +cat << 'EOF' > "$COMMAND_PATH" +#!/usr/bin/env bash +DATA_FILE="/usr/local/etc/container_metadata/build_info.txt" +if [ ! -f "$DATA_FILE" ]; then + echo "[ERROR] Container release metadata log file is missing." >&2 + exit 1 +fi + +echo "--------------------------------------------------" +echo "🚀 DevContainer Release Information" +echo "--------------------------------------------------" +cat "$DATA_FILE" | grep "^CONTAINER_VERSION=" | sed 's/^CONTAINER_VERSION="/ Version : /' | sed 's/"$//' +cat "$DATA_FILE" | grep "^BUILD_DATE=" | sed 's/^BUILD_DATE="/ Built On: /' | sed 's/"$//' +echo "--------------------------------------------------" +EOF + +chmod +x "$COMMAND_PATH" +echo "Metadata injection and system command generation complete!" \ No newline at end of file diff --git a/test/_global/build_info_default.sh b/test/_global/build_info_default.sh new file mode 100755 index 0000000..a74c588 --- /dev/null +++ b/test/_global/build_info_default.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +check "container-info script exists and is executable" test -x /usr/local/bin/container-info +check "build_info.txt exists" test -f /usr/local/etc/container_metadata/build_info.txt + +# Run the command and check output +check "container-info outputs correct version" bash -c "container-info | grep 'Version : 1.2.3'" +check "container-info outputs correct date" bash -c "container-info | grep 'Built On: 2023-10-27T10:00:00Z'" + +# Report result +reportResults \ No newline at end of file diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index 35c1290..b3f928f 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -211,5 +211,14 @@ "features": { "cmdstan": {} } + }, + "build_info_default": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "build-info": { + "version": "1.2.3", + "buildDate": "2023-10-27T10:00:00Z" + } + } } }