compose-cat
v0.1.8
Published
ComposeCat: a small CLI that generates and runs Docker/Podman Compose commands
Readme
ComposeCat
ComposeCat is a lightweight CLI that builds and runs Docker or Podman Compose commands from your terminal.
Use it exactly like your usual compose binary—just start with compose-cat instead of docker compose, podman compose, docker-compose, or podman-compose.
Highlights
- Compose binary auto-detection – Probes
docker compose,podman compose,docker-compose, andpodman-compose(override or reorder via--cmp-binorCMPCAT_COMPOSE_BIN). - Dotenv layering & profiles – Always loads
.env,.env.local, and, when profiles are provided,.env.<PROFILE>/.env.<PROFILE>.localunless--disable-profile-based-dotenvis supplied. - COMPOSE_* priming – Values detected in dotenv files automatically populate
COMPOSE_*variables (e.g.,COMPOSE_PROJECT_NAME,COMPOSE_FILE,COMPOSE_PROFILES) before the compose command runs. - Cleanup helpers –
cmp-clean,cmp-clean-i-local, andcmp-clean-i-allencapsulate common teardown flows. - Pluggable hooks – Run pre/post scripts with per-command, per-platform, and per-binary variants to enforce custom workflows.
Quick Start
Install globally with npm:
npm install -g compose-catAdd as a devDependency inside a project:
npm install --save-dev compose-catRun ad-hoc with npx:
npx compose-cat <COMPOSE_COMMAND> [ARGS]Examples:
compose-cat <COMPOSE_COMMAND> [ARGS]
compose-cat up -d
compose-cat downCLI Options
--cmp-hook <value...>: Hook names to run (pre and post). Example:--cmp-hook upruns matchingcmp.pre.up.*andcmp.post.up.*hooks.--cmp-bin <value...>: Provide compose binary candidates in priority order.- Example:
--cmp-bin "podman compose" --cmp-bin "docker compose". - Also configurable via
CMPCAT_COMPOSE_BIN.
- Example:
--cmp-prefix <value>: Set the ComposeCat environment variable prefix (default:CMPCAT_).- Also configurable via
CMPCAT_ARG_PREFIX.
- Also configurable via
--cmp-dotenv-prefix <value>: Set the dotenv file prefix to detect (default:.env).- Also configurable via
CMPCAT_ARG_DOTENV_PREFIX.
- Also configurable via
-p, --project-name <value>: Compose project name (overridesCOMPOSE_PROJECT_NAME).--profile <value...>: Profiles to use (comma-separated or repeat the flag), e.g.,--profile devor--profile dev,test.--disable-profile-based-dotenv: Skip loading.env.<PROFILE>and.env.<PROFILE>.localfiles even when profiles are provided.
Commands
cmp-clean: Convenience cleanup. Removes containers and networks/volumes.${CMPCAT_DETECTED_COMPOSE_BIN} rm -fsv${CMPCAT_DETECTED_COMPOSE_BIN} down --volumes
cmp-clean-i-local: Likecmp-clean, but also removes images referenced by services that do not have a custom tag.${CMPCAT_DETECTED_COMPOSE_BIN} rm -fsv${CMPCAT_DETECTED_COMPOSE_BIN} down --rmi local --volumes
cmp-clean-i-all: Likecmp-clean, but also removes every image referenced by the services.${CMPCAT_DETECTED_COMPOSE_BIN} rm -fsv${CMPCAT_DETECTED_COMPOSE_BIN} down --rmi all --volumes
Caution:
Pass ComposeCat options (such as --profile or -p) immediately after the built-in command. For example: compose-cat cmp-clean --profile main -p my-project.
How It Works
- Read CLI options, including profiles, project name, prefix overrides, and dotenv preferences.
- Determine the environment variable prefix from
--cmp-prefixorCMPCAT_ARG_PREFIX(default:CMPCAT_). - Determine the dotenv prefix from
--cmp-dotenv-prefixorCMPCAT_ARG_DOTENV_PREFIX(default:.env). - Load base dotenv files (
.env,.env.local). If profile-based detection is enabled, also load.env.<PROFILE>and.env.<PROFILE>.localfor each CLI profile. - Detect the compose binary from
CMPCAT_COMPOSE_BIN(if set) or probe defaults; override the order with--cmp-bin. - Prime
COMPOSE_*environment variables with any values discovered in dotenv files. - Build the compose command: add
--env-fileflags,--profileflags, and-p/--project-namewhen provided. - Run matching pre-hooks.
- Execute the compose command and capture its exit code.
- Run matching post-hooks and exit with the final status code.
Special Flow for Cleanup Commands
Cleanup commands follow the general flow, but expand to multiple compose commands executed in sequence (see “Commands” above for exact arguments).
ComposeCat Environment Variables (Consumed at Startup)
Configure these environment variables to control detection and defaults.
CMPCAT_ARG_PREFIX
- Sets the prefix for all ComposeCat-related environment variables.
- Default:
CMPCAT_ - Example:
CMPCAT_ARG_PREFIX=MyPrefix_yields variables likeMyPrefix_COMPOSE_BINinstead ofCMPCAT_COMPOSE_BIN.
CMPCAT_ARG_DOTENV_PREFIX
- Sets the dotenv file prefix used for detection.
- Default:
.env
ComposeCat Environment Variables (Applied During Execution)
All variables in this section use the active prefix (default CMPCAT_).
CMPCAT_COMPOSE_BIN
- Comma-separated list of compose binaries to probe, in order.
- If unset, ComposeCat probes in this order:
docker compose,podman compose,docker-compose,podman-compose. - Examples:
CMPCAT_COMPOSE_BIN=docker composeCMPCAT_COMPOSE_BIN=podman composeCMPCAT_COMPOSE_BIN=podman compose,docker compose
Environment Variables Set by ComposeCat
Set by ComposeCat for runtime configuration and profile management.
CMPCAT_DETECTED_COMPOSE_BIN
- The compose binary selected at runtime.
CMPCAT_PROFILES
- The list of active profiles joined by commas, e.g.,
main,sub_1. - Empty when no profile is selected via CLI options.
CMPCAT_PROFILE_<N>
- The active profile at index N (1-based), e.g.,
CMPCAT_PROFILE_1=main. - Cleared when no profiles are active so stale values do not persist between runs.
Dotenv Auto-Detection
ComposeCat discovers dotenv files at startup and adds them to the compose command as --env-file flags.
The following files are considered when present:
Base files:
.env.env.local
Profile files (each
<PROFILE>comes from--profile, unless--disable-profile-based-dotenvis used):.env.<PROFILE>.env.<PROFILE>.local
The dotenv file prefix is configurable via --cmp-dotenv-prefix or CMPCAT_ARG_DOTENV_PREFIX.
Hooks
Hook scripts can run before and after the compose command. ComposeCat searches for hook files in the current working directory and supports per-command, per-platform, and per-binary variants.
File name patterns (where stage is pre or post):
- Base:
cmp.<stage>.<EXT> - Platform:
cmp.<stage>.<PLATFORM>.<EXT> - Binary:
cmp.<stage>.+<BINARY>.<EXT> - Platform + Binary:
cmp.<stage>.<PLATFORM>+<BINARY>.<EXT> - Hook name:
cmp.<stage>.<HOOK>.<EXT> - Hook name + Platform/Binary:
cmp.<stage>.<HOOK>.<PLATFORM>+<BINARY>.<EXT>
Where:
HOOK: Name provided via the--cmp-hookargument (e.g.,up).PLATFORM: Target platform. Usewin32orwindowsfor Windows,darwinormacosfor macOS, andlinuxfor Linux.BINARY: Executable used to run the script (e.g.,bash,sh,pwsh,node). If omitted, the file itself is executed. Ensure it is executable or includes a shebang.EXT: File extension (e.g.,sh,ps1,js).
Examples when running with --cmp-hook=up (if present, these may execute):
cmp.pre.shcmp.pre.linux.shcmp.pre.darwin.shcmp.pre.win32.ps1cmp.pre.win32+pwsh.ps1cmp.pre.+node.jscmp.pre.up.shcmp.pre.up.linux.shcmp.pre.up.darwin.shcmp.pre.up.win32.ps1cmp.pre.up.win32+pwsh.ps1cmp.pre.up.+node.jscmp.post.shcmp.post.linux.shcmp.post.darwin.shcmp.post.win32.ps1cmp.post.win32+pwsh.ps1cmp.post.+node.jscmp.post.up.shcmp.post.up.linux.shcmp.post.up.darwin.shcmp.post.up.win32.ps1cmp.post.up.win32+pwsh.ps1cmp.post.up.+node.js
Environment variables exposed to hooks:
CMPCAT_HOOK_EVENT: Stage (preorpost).CMPCAT_HOOK_COMMAND: Hook name when--cmp-hookis provided; otherwise empty.CMPCAT_HOOK_PLATFORM: Matched platform string, if any.CMPCAT_HOOK_BINARY: Matched binary string, if any.CMPCAT_HOOK_FILE: Absolute path of the hook file being executed.
Notes
- You don’t need
--to pass through arguments; the CLI forwards unknown options and positional arguments to the underlying compose command.
