improve documentation

This commit is contained in:
Luiz Aoqui 2020-02-12 21:07:05 -05:00
parent 5553de0fed
commit 18790a2b82
No known key found for this signature in database
GPG key ID: F1178C891120DF5E
7 changed files with 78 additions and 28 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
nomad-skeleton-driver-plugin
hello-driver

11
GNUmakefile Normal file
View 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} .

View file

@ -1,49 +1,84 @@
nomad-skeleton-driver-plugin
Nomad Skeleton Driver Plugin
==========
This project is a [Hashicorp Nomad](https://www.nomadproject.io/) [task driver
plugin](https://www.nomadproject.io/docs/drivers/index.html) skeleton
implementation. You can clone and modify this to get started writing your own
task driver plugin.
Skeleton project for
[Nomad task driver plugins](https://www.nomadproject.io/docs/drivers/index.html).
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
-------------------
- [Nomad](https://www.nomadproject.io/downloads.html) v0.9.5+
- [Go](https://golang.org/doc/install) v1.12.x (to build the plugin)
- [Nomad](https://www.nomadproject.io/downloads.html) v0.9+
- [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
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.
For more information consult the Nomad documentation on
[plugins](https://www.nomadproject.io/docs/internals/plugins/index.html).
Enter the plugin directory and update the paths in `go.mod` and `main.go` to
match your repository path.
The initial state of the skeleton is a simple task that outputs a greeting. You
can try it out by starting a Nomad server and client and running the job
provided in the `config` folder:
```diff
// go.mod
- 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
go build
nomad agent -dev -config=./config/client.hcl -plugin-dir=$(PWD)
$ make build
```
## 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
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
-------------------
The skeleton driver comes with an in memory task state store (see
`hello/state.go`). This in-memory map is for storing runtime details (like a
process id). The details of what to store is left to the implementation of the
task driver. Fields stored in the base implementation in this skeleton can be
found in the `taskHandle` struct.
Follow the comments marked with a `TODO` tag to implement your driver's logic.
For more information check the
[Nomad documentation on plugins](https://www.nomadproject.io/docs/internals/plugins/index.html).

View file

@ -1,6 +1,6 @@
log_level = "TRACE"
plugin "nomad-skeleton-driver-plugin" {
plugin "hello-driver" {
config {
shell = "bash"
}

1
go.mod
View file

@ -1,3 +1,4 @@
// TODO: update the module path below to match your own repository
module github.com/hashicorp/nomad-skeleton-driver-plugin
go 1.12

View file

@ -2,6 +2,8 @@ package main
import (
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/plugins"