From 0e426ea9af194489e869c5724401e864fcbbdccd Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Thu, 9 May 2019 23:04:44 -0400 Subject: [PATCH 01/13] after a go mod tidy --- go.sum | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/go.sum b/go.sum index 1d6ea4f..440ef27 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,21 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/oracle/oci-go-sdk v5.4.0+incompatible h1:fM4QtmPTmmrzcyvBQP1/deOodn1/zJSszrQmHotAb3Q= github.com/oracle/oci-go-sdk v5.4.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 3a275feee86645205e1ff4b6df66f3383c7fbe76 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Thu, 9 May 2019 23:05:06 -0400 Subject: [PATCH 02/13] clean up some thing for golint and go test --- executor.go | 1 + main.go | 5 +++-- types.go | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 7875c2d..2d87ef2 100644 --- a/executor.go +++ b/executor.go @@ -10,6 +10,7 @@ import ( const defaultShell = "/bin/bash" +// RunScript runs the script that has been fetched as requested func (sm *ScriptManager) RunScript(sn string) error { s := fmt.Sprintf("%s/%s", sm.WorkDir, sn) diff --git a/main.go b/main.go index 9b6009d..8277a46 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ const ( workShell = "/bin/bash" ) +// ScriptManager definition of the manager to handle the script management type ScriptManager struct { Type ScriptType WorkDir string @@ -39,7 +40,7 @@ func main() { st, err := ParseScriptType(scriptType) if err != nil { log.Error("No valid argument specified for script type") - log.Error("%s : %s", err, scriptType) + log.Errorf("%s : %s", err, scriptType) os.Exit(1) } @@ -53,7 +54,7 @@ func main() { defer func() { if !debug { - os.RemoveAll(wd) + _ = os.RemoveAll(wd) } else { log.Debug("not removing work dir : ", wd) } diff --git a/types.go b/types.go index 4da4185..f838951 100644 --- a/types.go +++ b/types.go @@ -2,8 +2,10 @@ package main import "fmt" +// ScriptType of what type of script it is type ScriptType int +// Startup / Shutdown constant for that of a startup script const ( Startup ScriptType = iota + 1 Shutdown @@ -22,6 +24,7 @@ func (t ScriptType) String() string { return types[t-1] } +// ParseScriptType will take the type of script string and map to the ScriptType constant func ParseScriptType(s string) (ScriptType, error) { var ret ScriptType switch s { @@ -42,6 +45,7 @@ func ParseScriptType(s string) (ScriptType, error) { } +// Startup will return true if it's time for a startup script func (t ScriptType) Startup() bool { if t == Startup { return true @@ -49,6 +53,7 @@ func (t ScriptType) Startup() bool { return false } +// Shutdown will return true if it's shutdown script time func (t ScriptType) Shutdown() bool { if t == Shutdown { return true From 5f172eb221eca3e80921417b00b4e486b2efee3a Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Thu, 9 May 2019 23:16:23 -0400 Subject: [PATCH 03/13] first crack at wercker builds --- wercker.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 wercker.yml diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 0000000..05f346d --- /dev/null +++ b/wercker.yml @@ -0,0 +1,13 @@ +box: golang:1.12 +build: + steps: + - wercker/golint@1.4.1: + exclude: vendor + - script: + name: go test + code: | + go test -mod vendor ./... + - script: + name: go build + code: | + go build -mod vendor ./... From 1c927822c2de7a76b5a26f9bd24f7d3557daeee5 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Thu, 9 May 2019 23:19:48 -0400 Subject: [PATCH 04/13] added on wercker build badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef989a4..bc500ca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![wercker status](https://app.wercker.com/status/56107a996689202ef859cc6a49d9fb5f/s/master "wercker status")](https://app.wercker.com/project/byKey/56107a996689202ef859cc6a49d9fb5f) + ### OCI Metadata Script Handler #### Overview From 46e9788a7644921744bd0b8a234696e258b80f94 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 22:08:29 -0400 Subject: [PATCH 05/13] see if package stuff works --- wercker.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/wercker.yml b/wercker.yml index 05f346d..f3919e3 100644 --- a/wercker.yml +++ b/wercker.yml @@ -11,3 +11,38 @@ build: name: go build code: | go build -mod vendor ./... +package: + box: nshttpd/fpm-packager:0a62ec4 + steps: + - script: + name: make directories + code: | + mkdir -p pkg/usr/bin + mkdir -p pkg/etc/systemd/system + mkdir -p pkg/var/lib/oci/scripts + - script: + name: copy files + code: | + cp oci-metadata-scripts pkg/usr/bin/ + cp misc/*.service pkg/etc/systemd/system/ + cp misc/postinst.sh pkg/var/lib/oci/scripts/ + chmod 744 pkg/var/lib/oci/scripts/postinst.sh + - script: + name: fpm rpm builder + code: | + export VERSION=`cat VERSION` + fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p /tmp/build \ + -C /tmp/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p /tmp/build \ + -C /tmp/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ +#deploy: +# steps: +# - script: +# name: install ghr +# code: | +# go get github.com/tcnksm/ghr +# - script: +# name: run ghr +# code: | +# export VERSION=`cat VERSION` +# ghr -delete ${VERSION} pkg/ From 4ea5e23adecc7ee5b3680332f23a0d0804931abc Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 22:16:03 -0400 Subject: [PATCH 06/13] add in deploy??? --- wercker.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/wercker.yml b/wercker.yml index f3919e3..5692147 100644 --- a/wercker.yml +++ b/wercker.yml @@ -31,18 +31,18 @@ package: name: fpm rpm builder code: | export VERSION=`cat VERSION` - fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p /tmp/build \ - -C /tmp/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ - fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p /tmp/build \ - -C /tmp/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ -#deploy: -# steps: -# - script: -# name: install ghr -# code: | -# go get github.com/tcnksm/ghr -# - script: -# name: run ghr -# code: | -# export VERSION=`cat VERSION` -# ghr -delete ${VERSION} pkg/ + fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ + -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ + -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ +deploy: + steps: + - script: + name: install ghr + code: | + go get github.com/tcnksm/ghr + - script: + name: run ghr + code: | + export VERSION=`cat VERSION` + ghr -delete ${VERSION} pkg/build/ From d5f5c908da7035f8c0f674a1a5cc39c68f498c3e Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 22:26:13 -0400 Subject: [PATCH 07/13] maybe after reading the docs --- wercker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wercker.yml b/wercker.yml index 5692147..267a634 100644 --- a/wercker.yml +++ b/wercker.yml @@ -23,7 +23,7 @@ package: - script: name: copy files code: | - cp oci-metadata-scripts pkg/usr/bin/ + cp build/oci-metadata-scripts pkg/usr/bin/ cp misc/*.service pkg/etc/systemd/system/ cp misc/postinst.sh pkg/var/lib/oci/scripts/ chmod 744 pkg/var/lib/oci/scripts/postinst.sh @@ -45,4 +45,4 @@ deploy: name: run ghr code: | export VERSION=`cat VERSION` - ghr -delete ${VERSION} pkg/build/ + ghr -delete ${VERSION} package/pkg/build/ From 38d91664275c684f5b544c0dfc79ae3beb883495 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 22:55:06 -0400 Subject: [PATCH 08/13] and now --- wercker.yml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/wercker.yml b/wercker.yml index 267a634..ae302c2 100644 --- a/wercker.yml +++ b/wercker.yml @@ -10,7 +10,9 @@ build: - script: name: go build code: | - go build -mod vendor ./... + pwd + go build -mod vendor -o oci-metadata-scripts . + ls package: box: nshttpd/fpm-packager:0a62ec4 steps: @@ -23,6 +25,8 @@ package: - script: name: copy files code: | + pwd + ls cp build/oci-metadata-scripts pkg/usr/bin/ cp misc/*.service pkg/etc/systemd/system/ cp misc/postinst.sh pkg/var/lib/oci/scripts/ @@ -35,14 +39,18 @@ package: -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ -deploy: - steps: - - script: - name: install ghr - code: | - go get github.com/tcnksm/ghr - - script: - name: run ghr - code: | - export VERSION=`cat VERSION` - ghr -delete ${VERSION} package/pkg/build/ +#deploy: +# steps: +# - script: +# name: install ghr +# code: | +# go get github.com/tcnksm/ghr +# - tcnksm/ghr: +# name: run ghr +# code: | +# export VERSION=`cat VERSION` +# ghr -delete ${VERSION} package/pkg/build/ +#token: $GITHUB_TOKEN +# input: $WERCKER_SOURCE_DIR/dist +# version: latest +# replace: true \ No newline at end of file From 3ded8e58d227600359c9e46b0b78fb784a7ed149 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 23:01:58 -0400 Subject: [PATCH 09/13] maybe now --- wercker.yml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/wercker.yml b/wercker.yml index ae302c2..f7dc753 100644 --- a/wercker.yml +++ b/wercker.yml @@ -10,9 +10,7 @@ build: - script: name: go build code: | - pwd go build -mod vendor -o oci-metadata-scripts . - ls package: box: nshttpd/fpm-packager:0a62ec4 steps: @@ -25,9 +23,7 @@ package: - script: name: copy files code: | - pwd - ls - cp build/oci-metadata-scripts pkg/usr/bin/ + cp oci-metadata-scripts pkg/usr/bin/ cp misc/*.service pkg/etc/systemd/system/ cp misc/postinst.sh pkg/var/lib/oci/scripts/ chmod 744 pkg/var/lib/oci/scripts/postinst.sh @@ -39,18 +35,14 @@ package: -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ -#deploy: -# steps: -# - script: -# name: install ghr -# code: | -# go get github.com/tcnksm/ghr -# - tcnksm/ghr: -# name: run ghr -# code: | -# export VERSION=`cat VERSION` -# ghr -delete ${VERSION} package/pkg/build/ -#token: $GITHUB_TOKEN -# input: $WERCKER_SOURCE_DIR/dist -# version: latest -# replace: true \ No newline at end of file +deploy: + steps: + - script: + name: set version + code: | + export VERSION=`cat VERSION` + - tcnksm/ghr@0.2.0: + name: run ghr + token: $GITHUB_TOKEN + input: pkg/build + replace: true From c11084df3a7d2fe7b011b162efe69448cbc13a83 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 23:07:37 -0400 Subject: [PATCH 10/13] fix some path stuff --- wercker.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wercker.yml b/wercker.yml index f7dc753..43eabf5 100644 --- a/wercker.yml +++ b/wercker.yml @@ -20,6 +20,7 @@ package: mkdir -p pkg/usr/bin mkdir -p pkg/etc/systemd/system mkdir -p pkg/var/lib/oci/scripts + mkdir -p pkg/build - script: name: copy files code: | @@ -32,9 +33,9 @@ package: code: | export VERSION=`cat VERSION` fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ - -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + -C pkg --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ - -C pkg/build --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + -C pkg --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ deploy: steps: - script: From 451d8474a6b2aaab64f64ec3ab4df1f4ffdf8071 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 23:10:08 -0400 Subject: [PATCH 11/13] OMGWTFBBQ? --- wercker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wercker.yml b/wercker.yml index 43eabf5..2bf3577 100644 --- a/wercker.yml +++ b/wercker.yml @@ -35,7 +35,7 @@ package: fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ -C pkg --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ - -C pkg --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + -C pkg --replaces oci-metadata-scripts --after-install pkg/var/lib/oci/scripts/postinst.sh var/ usr/ etc/ deploy: steps: - script: From 0f988675f5ede7785816e432c3b1ac61eb20fff7 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 23:18:04 -0400 Subject: [PATCH 12/13] packaged on my laptop --- wercker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wercker.yml b/wercker.yml index 2bf3577..c4a3600 100644 --- a/wercker.yml +++ b/wercker.yml @@ -33,7 +33,7 @@ package: code: | export VERSION=`cat VERSION` fpm -s dir -t rpm -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ - -C pkg --replaces oci-metadata-scripts --after-install /var/lib/oci/scripts/postinst.sh var/ usr/ etc/ + -C pkg --replaces oci-metadata-scripts --after-install pkg/var/lib/oci/scripts/postinst.sh var/ usr/ etc/ fpm -s dir -t deb -v ${VERSION} -n oci-metadata-scripts -p pkg/build \ -C pkg --replaces oci-metadata-scripts --after-install pkg/var/lib/oci/scripts/postinst.sh var/ usr/ etc/ deploy: From 753cfa1f62e426773bcf368483faeaa6a1892e60 Mon Sep 17 00:00:00 2001 From: Steve Brunton Date: Wed, 15 May 2019 23:26:23 -0400 Subject: [PATCH 13/13] add version in --- wercker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/wercker.yml b/wercker.yml index c4a3600..3a775a2 100644 --- a/wercker.yml +++ b/wercker.yml @@ -46,4 +46,5 @@ deploy: name: run ghr token: $GITHUB_TOKEN input: pkg/build + version: $VERSION replace: true