dockdock
v1.4.0
Published
Build and deploy your Docker Compose project
Downloads
156
Readme
DockDock
TypeScript CLI to build and deliver your Docker Compose project to remote servers. It can clone from GitHub (with deploy keys) or upload a tar archive, install Docker/Compose on the server when needed, and build in three modes: local, target, or separate builder IP. It also handles optional Git submodules that are meant to be cloned on the server.
Highlights
- Interactive config: Reads
DEPLOY.json/deploy.json; if missing, prompts and writesdeploy.json. - GitHub integration (optional): Generates per-repo SSH keys on the server, updates SSH
config, and adds GitHub deploy keys viagh. - Submodules support: Reads
.gitmodulesfrom GitHub and only initializes submodules markedonServer=true. - Docker/Compose bootstrap: Installs or verifies Docker and Docker Compose on the chosen server via
apt-get. - Flexible build modes:
local,target, andip(separate build server); images can be streamed to the target via SSH.
Requirements
- Node.js 18+
- SSH access to your remote host(s)
- For GitHub flows: GitHub CLI (
gh) authenticated locally (gh auth login) - Remote servers assumed Debian/Ubuntu-based (uses
apt-get)
Install (local dev)
npm install
npm run build
npm link # optional: expose `dockdock` globally during developmentYou can also run without linking:
npx ts-node src/cli.ts --helpConfiguration
On each run, the CLI loads DEPLOY.json (preferred) or deploy.json from the current working directory. If neither exists and you run a command that needs config, it will prompt you and write deploy.json.
Fields:
serverAddress(string): Target/builder server IP/hostnameusername(string): SSH user (defaultroot)password(string): SSH password (optional if using SSH keys)port(number): SSH port (default22)serverDir(string): Project directory on the server (default~/project)githubProject(string, optional):owner/name; enables GitHub clone flowsbuildMode("local" | "target" | "ip"): Build locationbuildServerIp(string, optional): Required ifbuildMode = "ip"connectBuildServerToGithub(boolean, default true): If false, code is sent as a tar archive instead of cloning on the server
Example deploy.json:
{
"serverAddress": "203.0.113.10",
"username": "root",
"password": "your-ssh-password",
"port": 22,
"serverDir": "~/apps/my-app",
"githubProject": "owner/repo",
"buildMode": "target",
"buildServerIp": "198.51.100.5",
"connectBuildServerToGithub": true
}Tip: Prefer SSH keys over passwords for production. Keep deploy.json out of source control.
CLI
dockdock --helpCommands:
init— Initialize or update deployment settings via prompts (writesdeploy.jsonif missing). Prints a summary of loaded config.dockdock initstage-server— Place project files on the target server (ignoresbuildMode).- If
githubProjectis set andconnectBuildServerToGithubis true: sets up SSH and clones on the server (plus submodules withonServer=true). - Otherwise: creates a tar archive of your local project (respects
.gitignore) and uploads/extracts it on the server.
dockdock stage-server- If
stage-builder— Same asstage-serverbut stages on the builder server (useful whenbuildMode=ip).dockdock stage-builderbuild— Build the project according tobuildMode.- Always ensures Docker/Compose exist on the selected server.
local: runsdocker-compose buildlocally, then streams the image to the target (docker save | ssh docker load).target: prepares code on target (clone or archive upload) and runsdocker-compose buildon the target.ip: builds on builder and streams the image to the target.
dockdock builddeploy— Convenience pipeline: stage (clone or archive) on selected server, build, and if not building on target, stream the image to the target.dockdock deploy
Note: The current pipeline builds and (for local/ip) transfers images to the target but does not run docker-compose up -d. Use stage-server to ensure compose files exist on the target, then start services manually on the target, for example:
ssh <user>@<target> "cd <serverDir> && docker-compose up -d"Build Modes
local
- Build runs on your machine (
docker-compose build). - Image is streamed to the target:
docker save | ssh docker load. - Start containers on the target manually.
- Build runs on your machine (
target
- Code is prepared on the target (clone or uploaded archive).
- Target runs
docker-compose build. - Start containers on the target manually.
ip
- Code is prepared on the builder host (
buildServerIp). - Builder runs
docker-compose buildand streams the image to the target. - Start containers on the target manually.
- Code is prepared on the builder host (
Submodules
- Only submodules marked with
onServer=truein.gitmodulesare initialized on the server. - HTTPS GitHub URLs in
.gitmodulesare rewritten to SSH form using per-repo deploy keys.
Project Structure (src)
cli.ts # Commander CLI entry (init, stage-*, build, deploy)
flow/
archiveAndSend.ts # Create tar.gz and upload/extract on server
buildProject.ts # Ensure Docker/Compose, then build (local/remote)
createImageOnTarget.ts# Helper flow (stage + build + send image)
prepareRepository.ts # GitHub keys + clone main repo + submodules
sendImageToTarget.ts # Stream built image to target via SSH
settings.ts # Load config; interactive prompts if missing
utils/
archive.ts # tar plan respecting .gitignore
build.ts # remote build helpers (docker-compose)
docker.ts # Docker/Compose install/verify via apt-get
github.ts # Add deploy keys with `gh`, clone helpers
gitmodules.ts # Rewrite .gitmodules URLs to SSH on server
local.ts # Local shell exec
remote.ts # SSH exec + small FS helpers on server
ssh.ts # Per-repo SSH keys and ssh_config
submodules.ts # Read `.gitmodules` from GitHub via `gh api`
transfer.ts # SFTP put/uploadDirSecurity
- Do not commit
deploy.jsonwith secrets. - Prefer SSH keys to passwords for servers and GitHub.
- Ensure your SSH user has privileges to install packages (
apt-get).
Troubleshooting
- GitHub CLI not authenticated:
gh auth login. - SSH connection errors: verify
serverAddress,port, credentials, firewall. - Docker/Compose missing: rerun
dockdock build(it ensures installation). - Submodules missing: ensure
.gitmoduleshasonServer=truewhere intended.
DockDock ©
