simple check option
This commit is contained in:
@@ -4,7 +4,8 @@ WORKDIR /tmp/nomad-resource
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN go build -o dist/out out/main.go && \
|
RUN go build -o dist/out out/main.go && \
|
||||||
go build -o dist/in in/main.go
|
go build -o dist/in in/main.go && \
|
||||||
|
go build -o dist/check check/main.go
|
||||||
|
|
||||||
FROM alpine:edge
|
FROM alpine:edge
|
||||||
|
|
||||||
|
38
check/main.go
Normal file
38
check/main.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
resource "github.com/cioplenu/concourse-nomad-resource"
|
||||||
|
"github.com/cioplenu/concourse-nomad-resource/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
Source resource.Source `json:"source"`
|
||||||
|
Version resource.Version `json:"version,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var request Request
|
||||||
|
err := json.NewDecoder(os.Stdin).Decode(&request)
|
||||||
|
common.Check(err, "Error parsing request")
|
||||||
|
|
||||||
|
lastVersion := request.Version.Version
|
||||||
|
|
||||||
|
history := common.GetHistory(request.Source)
|
||||||
|
versions := make([]resource.Version, 0)
|
||||||
|
|
||||||
|
for _, jobVersion := range history {
|
||||||
|
if lastVersion != 0 && lastVersion > jobVersion.Version {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
versions = append(versions, resource.Version{jobVersion.Version})
|
||||||
|
if lastVersion == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
json.NewEncoder(os.Stdout).Encode(versions)
|
||||||
|
|
||||||
|
}
|
@@ -1,8 +1,13 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
resource "github.com/cioplenu/concourse-nomad-resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Check(err error, msg string) {
|
func Check(err error, msg string) {
|
||||||
@@ -11,3 +16,24 @@ func Check(err error, msg string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetHistory(source resource.Source) []resource.JobVersion {
|
||||||
|
cmd := exec.Command(
|
||||||
|
"nomad",
|
||||||
|
"job",
|
||||||
|
"history",
|
||||||
|
"-json",
|
||||||
|
"-address="+source.URL,
|
||||||
|
"-token="+source.Token,
|
||||||
|
source.Name,
|
||||||
|
)
|
||||||
|
var histResp bytes.Buffer
|
||||||
|
cmd.Stdout = &histResp
|
||||||
|
err := cmd.Run()
|
||||||
|
Check(err, "Error checking versions")
|
||||||
|
|
||||||
|
var history []resource.JobVersion
|
||||||
|
json.Unmarshal(histResp.Bytes(), &history)
|
||||||
|
|
||||||
|
return history
|
||||||
|
}
|
||||||
|
17
out/main.go
17
out/main.go
@@ -86,22 +86,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Fprint(os.Stderr, out.String())
|
fmt.Fprint(os.Stderr, out.String())
|
||||||
|
|
||||||
cmd = exec.Command(
|
history := common.GetHistory(config.Source)
|
||||||
"nomad",
|
|
||||||
"job",
|
|
||||||
"history",
|
|
||||||
"-json",
|
|
||||||
"-address="+config.Source.URL,
|
|
||||||
"-token="+config.Source.Token,
|
|
||||||
config.Source.Name,
|
|
||||||
)
|
|
||||||
var histResp bytes.Buffer
|
|
||||||
cmd.Stdout = &histResp
|
|
||||||
err = cmd.Run()
|
|
||||||
common.Check(err, "Error checking versions")
|
|
||||||
|
|
||||||
var history []resource.JobVersion
|
|
||||||
json.Unmarshal(histResp.Bytes(), &history)
|
|
||||||
|
|
||||||
response := Response{
|
response := Response{
|
||||||
Version: resource.Version{
|
Version: resource.Version{
|
||||||
|
Reference in New Issue
Block a user