Wharf CLI plugins
By using the Hashicorp Go Plugin System over RPC1 each build target environment needs only to be included in the $PATH
.
Sample interface
This is not final!
type Flag struct {
Name string
ShortName string
Description string
IsArgument bool
IsRequired bool
DefaultValue string
// Type Type // some enum of types, ex file, existingFile, etc.
// // just for potential future autocompletion
}
type Arguments = map[string]string // flag name: argument value
type Build struct {
BuildID int
Step wharf.Step
Definition wharf.Definition
}
// Builder is the interface for the wharf command to talk to the builder plugin
type Builder interface {
CanBuild(build Build, args Arguments) bool
Build(build Build, args Arguments)
Flags() []Flag
Version() string
}
Sample use case: --help
$ wharf build kubernetes --help
Usage: wharf build kubernetes
Wharf flags:
-h, --help Show this help.
--version Show the version of the 'kubernetes' plugin.
--build Set the build ID.
-v, --verbose Enable verbose logging.
Plugin flags (kubernetes):
--kubeconfig="~/.kube/config" Path to the kubeconfig to use.
In the background, the Wharf CLI did this:
- Spin up the
kubernetes
plugin, for example namedwharf-build-kubernetes
- Connect to it via RPC
- Ask for its flags via
Builder.Flags()
- Combine with some Wharf flags, such as the
--help
and--version
flags - Print output.
- Exit.
Sample use case: Building
$ wharf build kubernetes --build 2355
I0302 13:57.215113 wharf build.go:23] Starting build: 2355
I0302 13:57.215113 wharf build.go:23] Running step: build/web
I0302 13:57.215113 wharf-build-kubernetes main.go:23] Checking connection with Kubernetes cluster...
I0302 13:57.215113 wharf-build-kubernetes main.go:23] Creating pod 'wharf-docker-2355'
I0302 13:57.215113 wharf-build-kubernetes main.go:23] Waiting for pod to initialize...
In the background, the Wharf CLI did this:
- Read
.wharf-ci.yml
- Log
Starting build: 2355
- Log
Running step: build/web
- Spin up the
kubernetes
plugin, for example namedwharf-build-kubernetes
- Connect to it via RPC
- Pass it the
build/web
step to build viaBuilder.Build(...)
- Wait for it to complete
- Continue to the next step…
Hashicorp, Go Plugin System over RPC, https://github.com/hashicorp/go-plugin
↩︎