docker

package module
v0.0.0-...-57d14be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

Docker plugin

An xcl plugin that creates real Docker networks and containers. It is the external plugin the plugin example loads, and it is laid out in the standard xcl plugin layout, the same shape the plugin template uses. The layout design (plugin-layout.md) is the shared reference for both.

It provides two block types:

  • docker "network" "<name>": a Docker bridge network named after the block, with an optional subnet. The plugin computes docker_id.
  • docker "container" "<name>": a Docker container named after the block, with image, optional command, environment and init_script, and one nested network block per network it joins. The plugin computes docker_id and ip_address.

The plugin is a Go module of its own, github.com/jumppad-labs/xcl/example/plugin/plugins/docker.

Layout

plugins/docker/
  plugin.go                       the Plugin type: Init builds the clients once and registers both types
  cmd/docker/main.go              serves the Plugin as a separate program
  entities/
    network.go                    the docker "network" block type
    container.go                  the docker "container" block type, with its nested network block
  providers/
    network.go                    the network provider
    container.go                  the container provider
    attachments.go                previous network attachments and network addresses, used by the container provider
    labels.go                     the labels every Docker object the plugin creates carries
    *_test.go                     strict-double unit tests; docker_test.go runs against a real engine
  client/
    docker/docker.go              the narrow interface over the Docker Engine SDK, with New and Ping
    docker/mocks/                 its Mockery-generated double
    containers/containers.go      the container task layer the providers use, built on client/docker
    containers/mocks/             its Mockery-generated double
  examples/basic/main.xcl         a sample configuration: a network and a container on it
  e2e/                            end-to-end tests: apply the sample, plan with no changes, destroy
  .mockery.yml
  Makefile
  README.md
  go.mod
  • entities/ holds the block types only. They import nothing but xcl's types, so a program that only reads what it applied imports entities alone, as the plugin example does.
  • providers/ holds the providers. Each is built by a constructor that takes the container task layer, so the unit tests build it the same way with a double. No provider imports a Docker library.
  • client/ is the only place the Docker libraries are imported. client/docker mirrors the SDK calls the plugin makes, and client/containers turns what the providers want done into those calls, in its own types.

Commands

Run each from this directory:

Command What it does
make build builds the plugin binary, build/docker-plugin
make test runs the unit, real-engine and end-to-end tests
make generate regenerates the Mockery doubles in client/*/mocks
make clean removes build/

The real-engine tests in providers/docker_test.go and the end-to-end tests in e2e/ need a Docker engine, reached through DOCKER_HOST or the default socket. They skip when none is reachable, so make test passes without one.

Registering the plugin

The Plugin type lives in the module's root package, so a host can register it in two ways.

In-process, compiled into the host:

import (
	"github.com/jumppad-labs/xcl"
	"github.com/jumppad-labs/xcl/example/plugin/plugins/docker"
	"github.com/jumppad-labs/xcl/registry"
)

local := registry.NewLocal()
local.RegisterPlugin(&docker.Plugin{})

c, err := xcl.NewConfig(xcl.WithRegistry(local))

As a separate program, the binary make build produces, which xcl starts and talks to over gRPC. This is how the plugin example uses it:

local := registry.NewLocal()
local.RegisterExternalPlugin("plugins/docker/build/docker-plugin")

c, err := xcl.NewConfig(xcl.WithRegistry(local))

Reading state

A program that only reads the blocks it applied imports entities, and none of the providers or Docker libraries:

import "github.com/jumppad-labs/xcl/example/plugin/plugins/docker/entities"

containers, err := xcl.FindByType[entities.Container](c, "docker", "container")

Documentation

Overview

Package docker is the Docker plugin, which provides the block types docker "network" and docker "container" and creates them as real Docker networks and containers.

Plugin is importable: a host registers it in-process with registry.Local.RegisterPlugin(&docker.Plugin{}), and cmd/docker serves the same type as a separate program. The block types live in entities, the providers in providers and the Docker client layer in client. A program that only reads the blocks it applied imports entities alone.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	plugins.PluginBase
}

Plugin provides the block types docker "network" and docker "container". cmd/docker serves it as an external plugin.

func (*Plugin) Init

func (p *Plugin) Init(logger logger.Logger, state plugins.State) error

Init builds the Docker client from the environment, and the container task layer over it once, then registers both block types, each with a provider sharing that task layer. Building them does not contact Docker, the providers do when they are called.

logger is plugin scoped, for messages written outside a provider call like this one. xcl adds provider=<block subtype> to what each provider's Init logs. During a call the providers log through plugins.Logger(ctx) instead, which xcl binds to the resource and step being worked on.

Directories

Path Synopsis
client
containers
Package containers is the Docker plugin's container task layer, the one place the plugin turns what its providers want done into Docker Engine SDK calls: creating and removing networks, pulling images, creating, starting and removing containers, and moving containers between networks.
Package containers is the Docker plugin's container task layer, the one place the plugin turns what its providers want done into Docker Engine SDK calls: creating and removing networks, pulling images, creating, starting and removing containers, and moving containers between networks.
docker
Package docker is the Docker Engine client the Docker plugin's container task layer, client/containers, uses to create real networks and containers.
Package docker is the Docker Engine client the Docker plugin's container task layer, client/containers, uses to create real networks and containers.
cmd
docker command
Command docker serves the Docker plugin, an external xcl plugin that creates real Docker networks and containers.
Command docker serves the Docker plugin, an external xcl plugin that creates real Docker networks and containers.
Package entities holds the Docker plugin's block types, docker "network" and docker "container", and nothing else: no providers, no Docker client and no Docker libraries.
Package entities holds the Docker plugin's block types, docker "network" and docker "container", and nothing else: no providers, no Docker client and no Docker libraries.
Package providers holds the Docker plugin's resource providers, which create docker "network" and docker "container" blocks as real Docker networks and containers.
Package providers holds the Docker plugin's resource providers, which create docker "network" and docker "container" blocks as real Docker networks and containers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL