Commit 69339277 authored by lukasburgey's avatar lukasburgey
Browse files

Merge branch 'dev'

parents 32b4d8aa cbc6008c
Pipeline #85139 passed with stages
in 2 minutes and 24 seconds
...@@ -3,3 +3,4 @@ deploy ...@@ -3,3 +3,4 @@ deploy
example example
configs configs
builds builds
feudalClient
...@@ -20,8 +20,11 @@ build: ...@@ -20,8 +20,11 @@ build:
paths: paths:
- feudalClient - feudalClient
# this needs a volume mounted to the docker runner like so:
# volumes = ["/path/to/binaries:/deployDestination:rw"]
deploy-dev: deploy-dev:
image: netroby/alpine-rsync
stage: deploy stage: deploy
only: only:
- dev - dev
...@@ -30,27 +33,6 @@ deploy-dev: ...@@ -30,27 +33,6 @@ deploy-dev:
dependencies: dependencies:
- build - build
script: script:
- eval $(ssh-agent -s) - ls /deployDestination
- echo "$SSH_PRIVATE_KEY" | ssh-add - - cp feudalClient /deployDestination
- mkdir -p ~/.ssh - date -Iseconds > /deployDestination/lastCIDeploy
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- rsync -v feudalClient $DEV_USER@$DEV_HOST:bin/feudalClientDev
- ssh $DEV_USER@$DEV_HOST -- systemctl --user restart devClient@0 devClient@1 devClient@2
deploy-master:
image: netroby/alpine-rsync
stage: deploy
only:
- master
environment:
name: master
dependencies:
- build
script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- rsync -v feudalClient $DEV_USER@$DEV_HOST:bin/feudalClient
...@@ -2,6 +2,9 @@ PROJECT_NAME := "feudalClient" ...@@ -2,6 +2,9 @@ PROJECT_NAME := "feudalClient"
PKG := "git.scc.kit.edu/feudal/$(PROJECT_NAME)" PKG := "git.scc.kit.edu/feudal/$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/) PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go) GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
VERSION := $(shell git describe --tags)
SCRIPT_VERSION := $(shell cat go.mod | grep feudalScripts | awk '{print $$2}')
LDFLAGS := "-X 'main.version=$(VERSION)' -X 'main.scriptsVersion=$(SCRIPT_VERSION)'"
.PHONY: all dep build clean test lint .PHONY: all dep build clean test lint
...@@ -18,12 +21,12 @@ test: ## Run unittests ...@@ -18,12 +21,12 @@ test: ## Run unittests
@go test -short ${PKG_LIST} @go test -short ${PKG_LIST}
# link dynamically # link dynamically
build: dep ## Build the binary file build: dep go.mod ## Build the binary file
@go build -i -v $(PKG) go build -i -v -ldflags=$(LDFLAGS) $(PKG)
# link statically # link statically
build-static: dep ## Build the binary file build-static: dep go.mod ## Build the binary file
@CGO_ENABLED=0 GOOS=linux go build -v -ldflags '-extldflags "-static"' $(PKG) @CGO_ENABLED=0 GOOS=linux go build -v -ldflags='$(LDFLAGS) -extldflags -static' $(PKG)
clean: ## Remove previous build clean: ## Remove previous build
@rm -f $(PROJECT_NAME) @rm -f $(PROJECT_NAME)
......
package indent
import (
"bytes"
"encoding/json"
)
var (
prefix = ""
indent = " "
)
// Indent indents a json string if possible
// if unsuccessful it just returns src
func Indent(src []byte) (ds []byte) {
buf := new(bytes.Buffer)
err := json.Indent(buf, src, prefix, indent)
if err != nil {
return src
}
ds = buf.Bytes()
return
}
...@@ -20,14 +20,17 @@ import ( ...@@ -20,14 +20,17 @@ import (
) )
var ( var (
// version and scriptsVersion are set via: go build -ldflags '-X main.version=foobar -X main.scriptsVersion=foobar
version = ""
scriptsVersion = ""
app = kingpin.New( app = kingpin.New(
"FEUDAL Client", "FEUDAL Client",
"Client for the Federated User Credential Deployment Portal (FEUDAL)", "Client for the Federated User Credential Deployment Portal (FEUDAL)",
).Author( ).Author(
"Lukas Burgey", "Lukas Burgey",
).Version( ).Version(fmt.Sprintf("feudalClient: %s\nfeudalScripts: %s", version, scriptsVersion))
"v2.3.0",
)
cmdStart = app.Command("start", "Starts the client in its normal operation mode.").Default() cmdStart = app.Command("start", "Starts the client in its normal operation mode.").Default()
cmdDeregister = app.Command("deregister", "Before disabling the client: Use deregister to inform the backend that the client ceases operation.") cmdDeregister = app.Command("deregister", "Before disabling the client: Use deregister to inform the backend that the client ceases operation.")
cmdSchema = app.Command("schema", "Can be used to generate a JSON schema (Draft 4, see json-schema.org) for the validation of script inputs, outputs and the config of this client.") cmdSchema = app.Command("schema", "Can be used to generate a JSON schema (Draft 4, see json-schema.org) for the validation of script inputs, outputs and the config of this client.")
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config" "git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments" deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
scripts "git.scc.kit.edu/feudal/feudalScripts/v2" scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
) )
...@@ -121,43 +122,44 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) { ...@@ -121,43 +122,44 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
stdin.Write(iBytes) stdin.Write(iBytes)
stdin.Close() stdin.Close()
// decode json output // read stdout / stderr
var outputBytes, logOutputBytes []byte var stdoutBytes, stderrBytes []byte
outputBytes, err = ioutil.ReadAll(stdout)
if err != nil {
return
}
logOutputBytes, err = ioutil.ReadAll(stderr) stdoutBytes, err = ioutil.ReadAll(stdout)
if err != nil { if err != nil {
return return
} }
if sink.Config.Debug.Scripts {
if len(logOutputBytes) > 0 { stderrBytes, _ = ioutil.ReadAll(stderr)
dep.Log("Logs:\n%s", logOutputBytes) if sink.Config.Debug.Scripts && len(stderrBytes) > 0 {
dep.Log("End of Logs") dep.Log("Logs:\n%s", stderrBytes)
} dep.Log("End of Logs")
} }
err = cmd.Wait() // execute the script with timeout
if err != nil { done := make(chan error)
go func() { done <- cmd.Wait() }()
// TODO put in config
timeoutDuration := 2 * time.Second
timeout := time.After(timeoutDuration)
select {
case <-timeout:
cmd.Process.Kill()
err = fmt.Errorf("Execution of '%s' timed out after %s", dep.Service.Command, timeoutDuration)
return return
} case err = <-done:
if sink.Config.Debug.Scripts {
var indented = new(bytes.Buffer)
err = json.Indent(indented, outputBytes, " ", " ")
if err != nil { if err != nil {
dep.Log("Output (unable to indent: %s):\n%s", err, outputBytes) return
} else {
dep.Log("Output:\n%s", indented.String())
} }
} }
err = json.Unmarshal(outputBytes, &output) if sink.Config.Debug.Scripts {
dep.Log("Output: %s", indent.Indent(stdoutBytes))
}
err = json.Unmarshal(stdoutBytes, &output)
if err != nil { if err != nil {
if len(outputBytes) > 0 {
dep.Log("Raw output: %s", outputBytes)
}
return return
} }
......
package amqp package amqp
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
...@@ -9,6 +8,7 @@ import ( ...@@ -9,6 +8,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config" "git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments" deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
"github.com/streadway/amqp" "github.com/streadway/amqp"
) )
...@@ -119,12 +119,7 @@ func (src *Source) connect() (deliveries <-chan amqp.Delivery, closed <-chan *am ...@@ -119,12 +119,7 @@ func (src *Source) connect() (deliveries <-chan amqp.Delivery, closed <-chan *am
func (src *Source) consume(sink chan<- deps.Dep, deliveries <-chan amqp.Delivery) { func (src *Source) consume(sink chan<- deps.Dep, deliveries <-chan amqp.Delivery) {
consumeWrapper := func(del amqp.Delivery) { consumeWrapper := func(del amqp.Delivery) {
if src.Config.Debug.Backend { if src.Config.Debug.Backend {
indented := new(bytes.Buffer) log.Printf("[AMQP] Received: %s", indent.Indent(del.Body))
if err := json.Indent(indented, del.Body, " ", " "); err != nil {
log.Printf("[AMQP] Received (unable to indent: %v):\n%s", err, del.Body)
} else {
log.Printf("[AMQP] Received:\n%s", indented)
}
} }
var newDep deps.Dep var newDep deps.Dep
......
package rest package rest
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -11,6 +10,7 @@ import ( ...@@ -11,6 +10,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config" "git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments" deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
) )
type ( type (
...@@ -70,13 +70,7 @@ func (src Source) fetchDeps(sink chan<- deps.Dep) (err error) { ...@@ -70,13 +70,7 @@ func (src Source) fetchDeps(sink chan<- deps.Dep) (err error) {
} }
if src.Config.Debug.Backend { if src.Config.Debug.Backend {
indented := new(bytes.Buffer) log.Printf("[HTTP] Fetched: %s", indent.Indent(body))
indentErr := json.Indent(indented, body, "", " ")
if indentErr != nil {
log.Printf("[HTTP] Fetched (unable to indent: %v):\n%s", err, body)
} else {
log.Printf("[HTTP] Fetched:\n%s", indented)
}
} }
go func() { go func() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment