improve documentation
This commit is contained in:
parent
5553de0fed
commit
18790a2b82
7 changed files with 78 additions and 28 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
nomad-skeleton-driver-plugin
|
nomad-skeleton-driver-plugin
|
||||||
|
hello-driver
|
||||||
|
|
11
GNUmakefile
Normal file
11
GNUmakefile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
PLUGIN_BINARY=hello-driver
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
|
default: build
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean: ## Remove build artifacts
|
||||||
|
rm -rf ${PLUGIN_BINARY}
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build -o ${PLUGIN_BINARY} .
|
89
README.md
89
README.md
|
@ -1,49 +1,84 @@
|
||||||
nomad-skeleton-driver-plugin
|
Nomad Skeleton Driver Plugin
|
||||||
==========
|
==========
|
||||||
|
|
||||||
This project is a [Hashicorp Nomad](https://www.nomadproject.io/) [task driver
|
Skeleton project for
|
||||||
plugin](https://www.nomadproject.io/docs/drivers/index.html) skeleton
|
[Nomad task driver plugins](https://www.nomadproject.io/docs/drivers/index.html).
|
||||||
implementation. You can clone and modify this to get started writing your own
|
|
||||||
task driver plugin.
|
This project is intended for bootstrapping development of a new task driver
|
||||||
|
plugin.
|
||||||
|
|
||||||
|
- Website: [https://www.nomadproject.io](https://www.nomadproject.io)
|
||||||
|
- Mailing list: [Google Groups](http://groups.google.com/group/nomad-tool)
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
- [Nomad](https://www.nomadproject.io/downloads.html) v0.9.5+
|
- [Nomad](https://www.nomadproject.io/downloads.html) v0.9+
|
||||||
- [Go](https://golang.org/doc/install) v1.12.x (to build the plugin)
|
- [Go](https://golang.org/doc/install) v1.11 or later (to build the plugin)
|
||||||
|
|
||||||
Get Started
|
Building the Skeleton Plugin
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
Download the project module:
|
[Generate](https://github.com/hashicorp/nomad-skeleton-driver-plugin/generate)
|
||||||
|
a new repository in your account from this template by clicking the `Use this
|
||||||
|
template` button above.
|
||||||
|
|
||||||
|
Clone the repository somewhere in your computer. This project uses
|
||||||
|
[Go modules](https://blog.golang.org/using-go-modules) so you will need to set
|
||||||
|
the environment variable `GO111MODULE=on` or work outside your `GOPATH` if it
|
||||||
|
is set to `auto` or not declared.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get github.com/hashicorp/nomad-skeleton-driver-plugin
|
$ git clone git@github.com:<ORG>/<REPO>git
|
||||||
```
|
```
|
||||||
|
|
||||||
Follow the comments marked with a `TODO` tag to implement your driver's logic.
|
Enter the plugin directory and update the paths in `go.mod` and `main.go` to
|
||||||
For more information consult the Nomad documentation on
|
match your repository path.
|
||||||
[plugins](https://www.nomadproject.io/docs/internals/plugins/index.html).
|
|
||||||
|
|
||||||
The initial state of the skeleton is a simple task that outputs a greeting. You
|
```diff
|
||||||
can try it out by starting a Nomad server and client and running the job
|
// go.mod
|
||||||
provided in the `config` folder:
|
|
||||||
|
- module github.com/hashicorp/nomad-skeleton-driver-plugin
|
||||||
|
+ module github.com/<ORG>/<REPO>
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
// main.go
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/hashicorp/go-hclog"
|
||||||
|
- "github.com/hashicorp/nomad-skeleton-driver-plugin/hello"
|
||||||
|
+ "github.com/<REPO>/<ORG>/hello"
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Build the skeleton plugin.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go build
|
$ make build
|
||||||
nomad agent -dev -config=./config/client.hcl -plugin-dir=$(PWD)
|
```
|
||||||
|
|
||||||
|
## Deploying Driver Plugins in Nomad
|
||||||
|
|
||||||
|
The initial version of the skeleton is a simple task that outputs a greeting.
|
||||||
|
You can try it out by starting a Nomad agent and running the job provided in
|
||||||
|
the `example` folder:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ make build
|
||||||
|
$ nomad agent -dev -config=./example/agent.hcl -plugin-dir=$(pwd)
|
||||||
|
|
||||||
# in another shell
|
# in another shell
|
||||||
nomad run ./config/example.nomad
|
$ nomad run ./example/example.nomad
|
||||||
|
$ nomad logs <ALLOCATION ID>
|
||||||
```
|
```
|
||||||
|
|
||||||
You should rename the project's root folder and the `hello` module to fit your
|
|
||||||
own driver.
|
|
||||||
|
|
||||||
Code Organization
|
Code Organization
|
||||||
-------------------
|
-------------------
|
||||||
The skeleton driver comes with an in memory task state store (see
|
Follow the comments marked with a `TODO` tag to implement your driver's logic.
|
||||||
`hello/state.go`). This in-memory map is for storing runtime details (like a
|
For more information check the
|
||||||
process id). The details of what to store is left to the implementation of the
|
[Nomad documentation on plugins](https://www.nomadproject.io/docs/internals/plugins/index.html).
|
||||||
task driver. Fields stored in the base implementation in this skeleton can be
|
|
||||||
found in the `taskHandle` struct.
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
log_level = "TRACE"
|
log_level = "TRACE"
|
||||||
|
|
||||||
plugin "nomad-skeleton-driver-plugin" {
|
plugin "hello-driver" {
|
||||||
config {
|
config {
|
||||||
shell = "bash"
|
shell = "bash"
|
||||||
}
|
}
|
1
go.mod
1
go.mod
|
@ -1,3 +1,4 @@
|
||||||
|
// TODO: update the module path below to match your own repository
|
||||||
module github.com/hashicorp/nomad-skeleton-driver-plugin
|
module github.com/hashicorp/nomad-skeleton-driver-plugin
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
2
main.go
2
main.go
|
@ -2,6 +2,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/hashicorp/go-hclog"
|
log "github.com/hashicorp/go-hclog"
|
||||||
|
|
||||||
|
// TODO: update the path below to match your own repository
|
||||||
"github.com/hashicorp/nomad-skeleton-driver-plugin/hello"
|
"github.com/hashicorp/nomad-skeleton-driver-plugin/hello"
|
||||||
|
|
||||||
"github.com/hashicorp/nomad/plugins"
|
"github.com/hashicorp/nomad/plugins"
|
||||||
|
|
Loading…
Reference in a new issue