diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml new file mode 100644 index 000000000..7ddc9675f --- /dev/null +++ b/.github/workflows/npm.yml @@ -0,0 +1,100 @@ +name: npm + +on: + release: + types: [published] + workflow_dispatch: + inputs: + release_tag: + description: "Release tag to publish (e.g., v1.34.0)" + required: true + type: string + dry_run: + description: "Dry run (do not publish to npm)" + required: false + type: boolean + default: false + +permissions: + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 + + - name: Set up Node.js + uses: actions/setup-node@49933ea5288caeca8642195f882660b323136e12 # v4.4.0 + with: + node-version: "20" + registry-url: "https://registry.npmjs.org" + + - name: Determine version + id: version + run: | + TAG="${{ inputs.release_tag || github.event.release.tag_name }}" + VERSION="${TAG#v}" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Cross-compile binaries + run: | + docker buildx build \ + --target=cross \ + --build-arg GIT_TAG="${{ steps.version.outputs.tag }}" \ + --build-arg GIT_COMMIT="${{ github.sha }}" \ + --platform linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64,windows/arm64 \ + --output=./dist \ + . + + - name: Package npm packages + run: | + chmod +x npm/scripts/package.sh + ./npm/scripts/package.sh "${{ steps.version.outputs.version }}" + + - name: Verify packages + run: | + echo "=== Main package ===" + cat npm/docker-agent/package.json + echo "" + echo "=== Platform packages ===" + for pkg in npm/docker-agent-*/; do + echo "--- $(basename "$pkg") ---" + cat "$pkg/package.json" + ls -lh "$pkg/" + echo "" + done + + - name: Publish platform packages + if: ${{ !inputs.dry_run }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + for pkg in npm/docker-agent-*/; do + echo "Publishing $(basename "$pkg")..." + (cd "$pkg" && npm publish --access public) + done + + - name: Publish main package + if: ${{ !inputs.dry_run }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + echo "Publishing @docker/docker-agent..." + cd npm/docker-agent && npm publish --access public + + - name: Dry run - show what would be published + if: ${{ inputs.dry_run }} + run: | + for pkg in npm/docker-agent-*/; do + echo "=== Would publish $(basename "$pkg") ===" + (cd "$pkg" && npm pack --dry-run) + echo "" + done + echo "=== Would publish @docker/docker-agent ===" + (cd npm/docker-agent && npm pack --dry-run) diff --git a/.gitignore b/.gitignore index f30628c37..ed2a2719f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,9 @@ vendor /cagent /cagent-* /docker-mcp-* + +# npm platform binaries (copied in by npm/scripts/package.sh) +npm/docker-agent-*/docker-agent +npm/docker-agent-*/docker-agent.exe +npm/docker-agent/LICENSE +npm/docker-agent/README.md diff --git a/README.md b/README.md index 1ce2f4a66..2c3babdb9 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ docker agent run agent.yaml **Homebrew** — `brew install docker-agent`. Run `docker-agent` directly or symlink the binary to `~/.docker/cli-plugins/docker-agent` and run `docker agent`. +**npm** — `npx -y @docker/docker-agent` to run directly, or `npm install -g @docker/docker-agent` to install globally. + **Binary releases** — Download from [GitHub Releases](https://github.com/docker/docker-agent/releases). Symlink the `docker-agent` binary to `~/.docker/cli-plugins/docker-agent` to be able to use `docker agent`, or use `docker-agent` directly. Set at least one API key (or use [Docker Model Runner](https://docs.docker.com/ai/model-runner/) for local models): diff --git a/npm/docker-agent-darwin-arm64/README.md b/npm/docker-agent-darwin-arm64/README.md new file mode 100644 index 000000000..564d6078f --- /dev/null +++ b/npm/docker-agent-darwin-arm64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-darwin-arm64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-darwin-arm64/package.json b/npm/docker-agent-darwin-arm64/package.json new file mode 100644 index 000000000..449d41938 --- /dev/null +++ b/npm/docker-agent-darwin-arm64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-darwin-arm64", + "version": "0.0.0", + "description": "Docker Agent binary for macOS ARM64 (Apple Silicon)", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["darwin"], + "cpu": ["arm64"], + "files": [ + "docker-agent" + ] +} diff --git a/npm/docker-agent-darwin-x64/README.md b/npm/docker-agent-darwin-x64/README.md new file mode 100644 index 000000000..9493682f4 --- /dev/null +++ b/npm/docker-agent-darwin-x64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-darwin-x64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-darwin-x64/package.json b/npm/docker-agent-darwin-x64/package.json new file mode 100644 index 000000000..0d0b507f6 --- /dev/null +++ b/npm/docker-agent-darwin-x64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-darwin-x64", + "version": "0.0.0", + "description": "Docker Agent binary for macOS x64 (Intel)", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["darwin"], + "cpu": ["x64"], + "files": [ + "docker-agent" + ] +} diff --git a/npm/docker-agent-linux-arm64/README.md b/npm/docker-agent-linux-arm64/README.md new file mode 100644 index 000000000..7adcf08ad --- /dev/null +++ b/npm/docker-agent-linux-arm64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-linux-arm64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-linux-arm64/package.json b/npm/docker-agent-linux-arm64/package.json new file mode 100644 index 000000000..2cbe99179 --- /dev/null +++ b/npm/docker-agent-linux-arm64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-linux-arm64", + "version": "0.0.0", + "description": "Docker Agent binary for Linux ARM64", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["linux"], + "cpu": ["arm64"], + "files": [ + "docker-agent" + ] +} diff --git a/npm/docker-agent-linux-x64/README.md b/npm/docker-agent-linux-x64/README.md new file mode 100644 index 000000000..3003c8546 --- /dev/null +++ b/npm/docker-agent-linux-x64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-linux-x64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-linux-x64/package.json b/npm/docker-agent-linux-x64/package.json new file mode 100644 index 000000000..d4c88d703 --- /dev/null +++ b/npm/docker-agent-linux-x64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-linux-x64", + "version": "0.0.0", + "description": "Docker Agent binary for Linux x64", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["linux"], + "cpu": ["x64"], + "files": [ + "docker-agent" + ] +} diff --git a/npm/docker-agent-win32-arm64/README.md b/npm/docker-agent-win32-arm64/README.md new file mode 100644 index 000000000..e80b0c534 --- /dev/null +++ b/npm/docker-agent-win32-arm64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-win32-arm64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-win32-arm64/package.json b/npm/docker-agent-win32-arm64/package.json new file mode 100644 index 000000000..aaf6e1b5d --- /dev/null +++ b/npm/docker-agent-win32-arm64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-win32-arm64", + "version": "0.0.0", + "description": "Docker Agent binary for Windows ARM64", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["win32"], + "cpu": ["arm64"], + "files": [ + "docker-agent.exe" + ] +} diff --git a/npm/docker-agent-win32-x64/README.md b/npm/docker-agent-win32-x64/README.md new file mode 100644 index 000000000..759785e5f --- /dev/null +++ b/npm/docker-agent-win32-x64/README.md @@ -0,0 +1,9 @@ +# @docker/docker-agent-win32-x64 + +Platform-specific binary package for [Docker Agent](https://github.com/docker/docker-agent). + +This package is installed automatically by `@docker/docker-agent` — you don't need to install it directly. + +```sh +npx -y @docker/docker-agent +``` diff --git a/npm/docker-agent-win32-x64/package.json b/npm/docker-agent-win32-x64/package.json new file mode 100644 index 000000000..67836f0e0 --- /dev/null +++ b/npm/docker-agent-win32-x64/package.json @@ -0,0 +1,15 @@ +{ + "name": "@docker/docker-agent-win32-x64", + "version": "0.0.0", + "description": "Docker Agent binary for Windows x64", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "os": ["win32"], + "cpu": ["x64"], + "files": [ + "docker-agent.exe" + ] +} diff --git a/npm/docker-agent/package.json b/npm/docker-agent/package.json new file mode 100644 index 000000000..400c135ae --- /dev/null +++ b/npm/docker-agent/package.json @@ -0,0 +1,36 @@ +{ + "name": "@docker/docker-agent", + "version": "0.0.0", + "description": "Docker Agent - Build, run, and share AI agents", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/docker/docker-agent.git" + }, + "homepage": "https://docker.github.io/docker-agent/", + "bugs": "https://github.com/docker/docker-agent/issues", + "bin": { + "docker-agent": "bin/cli.js" + }, + "files": [ + "bin/cli.js", + "README.md", + "LICENSE" + ], + "optionalDependencies": { + "@docker/docker-agent-darwin-arm64": "0.0.0", + "@docker/docker-agent-darwin-x64": "0.0.0", + "@docker/docker-agent-linux-arm64": "0.0.0", + "@docker/docker-agent-linux-x64": "0.0.0", + "@docker/docker-agent-win32-arm64": "0.0.0", + "@docker/docker-agent-win32-x64": "0.0.0" + }, + "keywords": [ + "docker", + "agent", + "ai", + "coding-agent", + "cli", + "mcp" + ] +} diff --git a/npm/scripts/package.sh b/npm/scripts/package.sh new file mode 100755 index 000000000..edd8d275f --- /dev/null +++ b/npm/scripts/package.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# +# npm/scripts/package.sh +# +# Prepares npm packages for publishing by: +# 1. Copying cross-compiled binaries from dist/ into the platform packages +# 2. Stamping all package.json files with the given version +# 3. Copying LICENSE and README into the main package +# +# Usage: ./npm/scripts/package.sh +# +# Expects the dist/ directory to contain cross-compiled binaries produced +# by `task cross` (docker buildx --output=./dist), with the structure: +# dist/_/docker-agent-- (unix) +# dist/_/docker-agent--.exe (windows) + +set -euo pipefail + +VERSION="${1:?Usage: $0 }" +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +NPM_DIR="$ROOT_DIR/npm" +DIST_DIR="$ROOT_DIR/dist" + +# Mapping: npm-platform-arch -> dist-subdir/binary-name -> npm-binary-name +# key: npm platform suffix (e.g., darwin-arm64) +# value: "/|" +declare -A PLATFORM_MAP=( + ["darwin-arm64"]="darwin_arm64/docker-agent-darwin-arm64|docker-agent" + ["darwin-x64"]="darwin_amd64/docker-agent-darwin-amd64|docker-agent" + ["linux-arm64"]="linux_arm64/docker-agent-linux-arm64|docker-agent" + ["linux-x64"]="linux_amd64/docker-agent-linux-amd64|docker-agent" + ["win32-arm64"]="windows_arm64/docker-agent-windows-arm64.exe|docker-agent.exe" + ["win32-x64"]="windows_amd64/docker-agent-windows-amd64.exe|docker-agent.exe" +) + +echo "Packaging npm packages for version ${VERSION}..." + +# --- Step 1: Copy binaries into platform packages --- +for npm_platform in "${!PLATFORM_MAP[@]}"; do + mapping="${PLATFORM_MAP[$npm_platform]}" + src_rel="${mapping%%|*}" + dest_name="${mapping##*|}" + src="${DIST_DIR}/${src_rel}" + pkg_dir="${NPM_DIR}/docker-agent-${npm_platform}" + + if [ ! -f "$src" ]; then + echo "ERROR: Binary not found: $src" + echo " Run 'task cross' first to build all platform binaries." + exit 1 + fi + + echo " Copying $src -> $pkg_dir/$dest_name" + cp "$src" "$pkg_dir/$dest_name" + chmod +x "$pkg_dir/$dest_name" +done + +# --- Step 2: Stamp version in all package.json files --- +echo " Setting version to ${VERSION} in all package.json files..." +for pkg_json in "$NPM_DIR"/*/package.json; do + sed -i.bak "s/\"0.0.0\"/\"${VERSION}\"/g" "$pkg_json" + rm -f "${pkg_json}.bak" +done + +# --- Step 3: Copy LICENSE and README into main package --- +cp "$ROOT_DIR/LICENSE" "$NPM_DIR/docker-agent/LICENSE" +cp "$ROOT_DIR/README.md" "$NPM_DIR/docker-agent/README.md" + +echo "" +echo "Done. Packages ready in ${NPM_DIR}/" +echo "" +echo "To publish (platform packages first, then main package):" +echo " cd ${NPM_DIR}" +echo " for pkg in docker-agent-*/; do (cd \"\$pkg\" && npm publish --access public); done" +echo " cd docker-agent && npm publish --access public"