How jonasprogrammer/docker-machine-driver-hetzner works
Project type and purpose
• This is a Go‑based CLI plugin (a Docker Machine “driver”) that enables users to create and manage Docker hosts on the Hetzner Cloud.
• It integrates into the Docker Machine ecosystem by implementing the driver interface and calls out to the Hetzner Cloud API to provisioning servers, networks, volumes, SSH keys, etc.
File structure
• Top-level:
• main.go – the CLI entrypoint that registers the driver with Docker Machine
• go.mod/go.sum – Go module configuration
• .github/, .gitignore, LICENSE, README.md, goreleaser.yml – repo, build and CI config
• driver/ directory: contains the core driver implementation, subdivided by concern:
• flag_processing.go, flag_failure.go – parse CLI flags via mcnflags and translate into driver options
• driver.go, setup.go, cleanup.go – implement the Create, Remove, GetState, etc. operations of the driver interface
• networking.go, volumes.go, placement_groups.go, ssh_keys.go, instrumentation_impl.go – domain‑specific modules that each wrap corresponding Hetzner Cloud API calls
• instrumentation_stub.go – stubbed implementation for testing
• hetzner_query.go – centralizes API‑client calls (via hcloud-go)
Extract architecture hints from the README
• The driver accepts CLI flags or environment variables (e.g. HETZNER_API_TOKEN)
• Uses the hcloud-go v2 client to call Hetzner Cloud REST endpoints
• Follows Docker Machine’s driver plugin interface – communicates with Docker Machine via RPC/CLI
• Provisions servers, networks, keys, volumes, placement groups in Hetzner Cloud, then configures the host via SSH/cloud‑init
Components
a. Frontend / CLI Layer
• User’s shell
• docker‑machine core (external)
• docker‑machine-driver-hetzner binary
b. Driver internals
• Flag Processor (mcnflags)
• Driver Controller (implements Create(), Remove(), ... )
• Domain Services:
• Server Provisioner (setup.go, cleanup.go)
• Networking Manager (networking.go)
• Volume Attacher (volumes.go)
• Placement Group Manager (placement_groups.go)
• SSH Key Manager (ssh_keys.go)
• Instrumentation & Logging (instrumentation_impl.go)
• hcloud-go API Client
c. External Dependencies
• Hetzner Cloud API (REST endpoints: Servers, Images, SSH Keys, Networks, Volumes, Placement Groups)
• Target VM via SSH / cloud‑init (for provisioning Docker Engine)
• Local File System (for storing machine‑state JSON, SSH keys)
Relationships & Data Flows
• User types “docker-machine create --driver hetzner …” → docker‑machine core invokes the driver binary
• CLI Layer → Flag Processor → Driver Controller
• Driver Controller coordinates Domain Services, each of which calls out over HTTPS to Hetzner Cloud API via the hcloud-go client
• Hetzner Cloud returns JSON responses → Domain Services interpret results → Driver Controller waits for server to reach “running” state
• Driver Controller uses SSH Key Manager + Local File System → writes private key and machine state files
• Driver Controller (or cloud-init) SSHs into the new server to install Docker Engine, then returns control back to docker‑machine core
• docker‑machine core persists machine metadata and reports success
Architectural patterns & design principles
• Separation of Concerns: each cloud‑resource type has its own module
• Plug‑in based architecture: implements Docker Machine’s driver interface
• Dependency Injection / Stubbing: instrumentation_stub.go allows testing without real API calls
• Use of a third‑party client library (hcloud-go) to encapsulate REST calls