Skip to content

[FEATURE] devc-remote.sh — bash orchestrator for remote devcontainer #152

@gerchowl

Description

@gerchowl

Description

Create scripts/devc-remote.sh — the main bash script that orchestrates starting a devcontainer on a remote host via SSH. This script handles everything except URI construction (which is in the Python helper, sibling sub-issue).

Problem Statement

Part of #70. The remote devcontainer orchestration requires a bash script that handles SSH connectivity, pre-flight checks, container state detection, and compose lifecycle management. This is the core orchestration logic.

Proposed Solution

A single bash script with the following functions:

  • parse_args()<ssh-host> (required), --path <remote-path> (optional, default ~/), --help
  • detect_editor_cli() — prefer cursor, fall back to code
  • check_ssh()ssh -o ConnectTimeout=5 -o BatchMode=yes <host> true
  • remote_preflight() — single SSH heredoc call batching all remote checks: runtime detection (podman > docker), compose availability, repo path exists, .devcontainer/ exists, disk space, OS type. Returns structured key=value output.
  • remote_compose_up() — container state detection (6-state matrix from [FEATURE] Remote devcontainer orchestration via just recipe #70), compose up -d, health poll (30s timeout, 5s interval, log tail on failure)
  • open_editor() — calls Python URI helper (devc_remote_uri.py), then $EDITOR_CLI --folder-uri "$URI"
  • Logging follows scripts/init.sh patterns (log_info, log_success, log_warning, log_error)
  • set -euo pipefail throughout

Container state matrix

State Action
Running, healthy Skip compose up, open editor
Running, unhealthy/restarting compose restart, health poll, open editor
Exited/stopped compose up -d, health poll, open editor
Not found compose up -d, health poll, open editor
Running, config changed compose up -d (detects changes), open editor
Running, image updated compose up -d (detects image change), open editor

Pre-flight checks

Local:

  • cursor or code CLI in PATH
  • SSH host reachable + auth works

Remote (single SSH session):

  • Container runtime exists (podman > docker)
  • Compose plugin available
  • Repo path exists
  • .devcontainer/ directory exists in repo
  • Disk space ≥ 2GB (warn if low)
  • OS detection (warn if macOS)

Files

  • Create: scripts/devc-remote.sh
  • Create: tests/bats/devc-remote.bats

Testing Strategy

BATS unit tests with mocked commands:

  • Argument parsing: missing host, --path handling, --help, unknown flags
  • detect_editor_cli(): cursor found, code found, neither found
  • check_ssh(): success, connection failure, auth failure
  • Remote pre-flight: parse structured output for each check
  • Container state matrix: mock compose ps JSON for each of 6 states
  • Health poll: mock healthy start, mock timeout, mock immediate exit

Verify: npx bats tests/bats/devc-remote.bats

Alternatives Considered

  • Python for the full script: rejected — bash is more natural for SSH/compose orchestration
  • Multiple SSH calls for pre-flight: rejected — single heredoc call avoids connection overhead

Impact

  • New file, no changes to existing behavior
  • Backward compatible
  • Can be worked in parallel with the sibling Python URI sub-issue

Changelog Category

Added

Metadata

Metadata

Assignees

Labels

area:workspaceWorkspace tooling, justfile, templateseffort:medium1-4 hoursfeatureNew feature or requestsemver:minorNew feature, backward-compatible

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions