From 5553de0fed86a31f9e93603ad68d2168e477e571 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Wed, 12 Feb 2020 18:59:25 -0500 Subject: [PATCH 1/2] fix dependency on github.com/opencontainers/runc --- go.mod | 5 +++++ go.sum | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/go.mod b/go.mod index eec9d49..7d864f8 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,13 @@ require ( github.com/Sirupsen/logrus v0.0.0-00010101000000-000000000000 // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/appc/spec v0.8.11 // indirect + github.com/checkpoint-restore/go-criu v0.0.0-20191125063657-fcdcd07065c5 // indirect github.com/containerd/go-cni v0.0.0-20191121212822-60d125212faf // indirect github.com/containernetworking/plugins v0.8.3 // indirect github.com/coreos/go-iptables v0.4.3 // indirect github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect + github.com/cyphar/filepath-securejoin v0.2.2 // indirect github.com/docker/cli v0.0.0-20191202230238-13fb276442f5 // indirect github.com/docker/docker v1.13.1 // indirect github.com/docker/docker-credential-helpers v0.6.3 // indirect @@ -30,6 +32,9 @@ require ( github.com/hashicorp/nomad/api v0.0.0-20191203164002-b31573ae7206 // indirect github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect github.com/moby/moby v1.13.1 // indirect + github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect + github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 // indirect + github.com/opencontainers/selinux v1.3.1 // indirect github.com/seccomp/libseccomp-golang v0.9.1 // indirect github.com/shirou/gopsutil v2.19.11+incompatible // indirect github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect diff --git a/go.sum b/go.sum index 0968c13..f918df4 100644 --- a/go.sum +++ b/go.sum @@ -66,6 +66,8 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2mtRGSCPsat1kze3CUtvJN3/jTXlp29k= github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= +github.com/checkpoint-restore/go-criu v0.0.0-20191125063657-fcdcd07065c5 h1:950diauOSoCNaQfvLE0WaFadyI/ilKIjb6jEUQnm+hE= +github.com/checkpoint-restore/go-criu v0.0.0-20191125063657-fcdcd07065c5/go.mod h1:TrMrLQfeENAPYPRsJuq3jsqdlRh3lvi6trTZJG8+tho= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible h1:C29Ae4G5GtYyYMm1aztcyj/J5ckgJm2zwdDajFbx1NY= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= @@ -73,6 +75,7 @@ github.com/circonus-labs/circonusllhist v0.1.3 h1:TJH+oke8D16535+jHExHj4nQvzlZrj github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= +github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1 h1:uict5mhHFTzKLUCufdSLym7z/J0CbBJT59lYbP9wtbg= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -98,6 +101,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg= +github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ= github.com/d2g/dhcp4client v1.0.0/go.mod h1:j0hNfjhrt2SxUOw55nL0ATM/z4Yt3t2Kd1mW34z5W5s= github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5/go.mod h1:Eo87+Kg/IX2hfWJfwxMzLyuSZyxSoAug2nGa1G2QAi8= @@ -396,6 +401,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 h1:7InQ7/zrOh6SlFjaXFubv0xX0HsuC9qJsdqm7bNQpYM= +github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618/go.mod h1:x8F1gnqOkIEiO4rqoeEEEqQbo7HjGMTvyoq3gej4iT0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2/go.mod h1:TLb2Sg7HQcgGdloNxkrmtgDNR9uVYF3lfdFIN4Ro6Sk= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= @@ -419,9 +426,13 @@ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= +github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 h1:9fbVzzYArOQ386pgWjIwNmioUTx5RWrSJ7r2NTlQCUE= +github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:eNUVfm/RFLIi1G7flU5/ZRTHvd4kcVuzfRnL6OFlzCI= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= +github.com/opencontainers/selinux v1.3.1 h1:dn2Rc3wTEvTB6iVqoFrKKeMb0uZ38ZheeyMu2h5C1TI= +github.com/opencontainers/selinux v1.3.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g= github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c/go.mod h1:otzZQXgoO96RTzDB/Hycg0qZcXZsWJGJRSXbmEIJ+4M= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -598,6 +609,8 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777 h1:wejkGHRTr38uaKRqECZlsCsJ1/TGxIyFbH32x5zUdu4= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= From 18790a2b82fa3e7cdc04f1d73f566656f7b93b49 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Wed, 12 Feb 2020 21:07:05 -0500 Subject: [PATCH 2/2] improve documentation --- .gitignore | 1 + GNUmakefile | 11 ++++ README.md | 89 ++++++++++++++++++-------- config/client.hcl => example/agent.hcl | 2 +- {config => example}/example.nomad | 0 go.mod | 1 + main.go | 2 + 7 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 GNUmakefile rename config/client.hcl => example/agent.hcl (58%) rename {config => example}/example.nomad (100%) diff --git a/.gitignore b/.gitignore index 9c066b0..dd66f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ nomad-skeleton-driver-plugin +hello-driver diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..6d84e6b --- /dev/null +++ b/GNUmakefile @@ -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} . diff --git a/README.md b/README.md index 7174829..5b87aaa 100644 --- a/README.md +++ b/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 -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:/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// +... +``` + +```diff +// main.go + +package main + +import ( + log "github.com/hashicorp/go-hclog" +- "github.com/hashicorp/nomad-skeleton-driver-plugin/hello" ++ "github.com///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 ``` -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). diff --git a/config/client.hcl b/example/agent.hcl similarity index 58% rename from config/client.hcl rename to example/agent.hcl index 47b0b2d..c9dd670 100644 --- a/config/client.hcl +++ b/example/agent.hcl @@ -1,6 +1,6 @@ log_level = "TRACE" -plugin "nomad-skeleton-driver-plugin" { +plugin "hello-driver" { config { shell = "bash" } diff --git a/config/example.nomad b/example/example.nomad similarity index 100% rename from config/example.nomad rename to example/example.nomad diff --git a/go.mod b/go.mod index 7d864f8..c0cbd07 100644 --- a/go.mod +++ b/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 go 1.12 diff --git a/main.go b/main.go index d8b7641..bf721a6 100644 --- a/main.go +++ b/main.go @@ -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"