Use this method if your base image already includes Node.js (16 or later).
Dockerfile
Copy
Ask AI
FROM node:20-slim# Pin the CLI version for reproducible buildsARG CPLN_CLI_VERSION=3.7.5# Install the Control Plane CLIRUN npm install -g @controlplane/cli@${CPLN_CLI_VERSION} && \ cpln --versionWORKDIR /app# Keep container running for testing (remove in production)CMD ["tail", "-f", "/dev/null"]
Build and run:
bash
Copy
Ask AI
# Build the imagedocker build -t cpln-test .# Run in a containerdocker run -d --name cpln-test \ -e CPLN_TOKEN="$CPLN_TOKEN" \ -e CPLN_ORG="my-org" \ -e CPLN_GVC="my-gvc" \ cpln-test
Exec into the container:
bash
Copy
Ask AI
docker exec -it cpln-test bash
Test the CLI:
bash
Copy
Ask AI
# List all workloadscpln workload get
Cleanup:
bash
Copy
Ask AI
docker stop cpln-test && docker rm cpln-test
Use this method for minimal images without Node.js.
Dockerfile
Copy
Ask AI
# Stage 1: Download and extract the CLIFROM debian:bookworm-slim AS cpln-downloader# Pin the CLI version for reproducible buildsARG CPLN_BINARY_URL=https://storage.googleapis.com/artifacts.cpln-build.appspot.com/binaries/cpln/2207036925-5a785bdf/cpln-linux.tgz# Download and extract cpln binaryRUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && \ curl -fsSL "${CPLN_BINARY_URL}" -o /tmp/cpln.tgz && \ tar -xzf /tmp/cpln.tgz -C /usr/local/bin && \ rm -rf /var/lib/apt/lists/*# Stage 2: Runtime imageFROM debian:bookworm-slim# Copy binaries from downloader stageCOPY --from=cpln-downloader /usr/local/bin/cpln /usr/local/bin/cplnCOPY --from=cpln-downloader /usr/local/bin/docker-credential-cpln /usr/local/bin/docker-credential-cpln# Verify installationRUN cpln --versionWORKDIR /work# Keep container running for testing (remove in production)CMD ["tail", "-f", "/dev/null"]
Build and run:
bash
Copy
Ask AI
# Build the image (use --platform for Apple Silicon Macs)docker build --platform linux/amd64 -t cpln-test .# Run in a containerdocker run -d --name cpln-test \ -e CPLN_TOKEN="$CPLN_TOKEN" \ -e CPLN_ORG="my-org" \ -e CPLN_GVC="my-gvc" \ cpln-test
The --platform linux/amd64 flag is required on Apple Silicon Macs because the CLI binary is compiled for x86_64. On Intel Macs and Linux, you can omit this flag.
Exec into the container:
bash
Copy
Ask AI
docker exec -it cpln-test bash
Test the CLI:
bash
Copy
Ask AI
# List all workloadscpln workload get
Cleanup:
bash
Copy
Ask AI
docker stop cpln-test && docker rm cpln-test
Multi-stage builds keep the final image small by excluding download tools.
#!/usr/bin/env bashset -euo pipefail# Ensure required environment variables are setfor var in CPLN_TOKEN CPLN_ORG CPLN_GVC; do if [ -z "${!var:-}" ]; then echo "Error: $var is not set" exit 1 fidone# Create profilecpln profile create ci --default# Run commandscpln workload get