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
example
configs
builds
feudalClient
......@@ -20,8 +20,11 @@ build:
paths:
- feudalClient
# this needs a volume mounted to the docker runner like so:
# volumes = ["/path/to/binaries:/deployDestination:rw"]
deploy-dev:
image: netroby/alpine-rsync
stage: deploy
only:
- dev
......@@ -30,27 +33,6 @@ deploy-dev:
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/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
- ls /deployDestination
- cp feudalClient /deployDestination
- date -Iseconds > /deployDestination/lastCIDeploy
......@@ -2,6 +2,9 @@ PROJECT_NAME := "feudalClient"
PKG := "git.scc.kit.edu/feudal/$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
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
......@@ -18,12 +21,12 @@ test: ## Run unittests
@go test -short ${PKG_LIST}
# link dynamically
build: dep ## Build the binary file
@go build -i -v $(PKG)
build: dep go.mod ## Build the binary file
go build -i -v -ldflags=$(LDFLAGS) $(PKG)
# link statically
build-static: dep ## Build the binary file
@CGO_ENABLED=0 GOOS=linux go build -v -ldflags '-extldflags "-static"' $(PKG)
build-static: dep go.mod ## Build the binary file
@CGO_ENABLED=0 GOOS=linux go build -v -ldflags='$(LDFLAGS) -extldflags -static' $(PKG)
clean: ## Remove previous build
@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 (
)
var (
// version and scriptsVersion are set via: go build -ldflags '-X main.version=foobar -X main.scriptsVersion=foobar
version = ""
scriptsVersion = ""
app = kingpin.New(
"FEUDAL Client",
"Client for the Federated User Credential Deployment Portal (FEUDAL)",
).Author(
"Lukas Burgey",
).Version(
"v2.3.0",
)
).Version(fmt.Sprintf("feudalClient: %s\nfeudalScripts: %s", version, scriptsVersion))
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.")
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 (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
)
......@@ -121,43 +122,44 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
stdin.Write(iBytes)
stdin.Close()
// decode json output
var outputBytes, logOutputBytes []byte
outputBytes, err = ioutil.ReadAll(stdout)
if err != nil {
return
}
// read stdout / stderr
var stdoutBytes, stderrBytes []byte
logOutputBytes, err = ioutil.ReadAll(stderr)
stdoutBytes, err = ioutil.ReadAll(stdout)
if err != nil {
return
}
if sink.Config.Debug.Scripts {
if len(logOutputBytes) > 0 {
dep.Log("Logs:\n%s", logOutputBytes)
dep.Log("End of Logs")
}
stderrBytes, _ = ioutil.ReadAll(stderr)
if sink.Config.Debug.Scripts && len(stderrBytes) > 0 {
dep.Log("Logs:\n%s", stderrBytes)
dep.Log("End of Logs")
}
err = cmd.Wait()
if err != nil {
// execute the script with timeout
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
}
if sink.Config.Debug.Scripts {
var indented = new(bytes.Buffer)
err = json.Indent(indented, outputBytes, " ", " ")
case err = <-done:
if err != nil {
dep.Log("Output (unable to indent: %s):\n%s", err, outputBytes)
} else {
dep.Log("Output:\n%s", indented.String())
return
}
}
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 len(outputBytes) > 0 {
dep.Log("Raw output: %s", outputBytes)
}
return
}
......
package amqp
import (
"bytes"
"encoding/json"
"fmt"
"log"
......@@ -9,6 +8,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
"github.com/streadway/amqp"
)
......@@ -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) {
consumeWrapper := func(del amqp.Delivery) {
if src.Config.Debug.Backend {
indented := new(bytes.Buffer)
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)
}
log.Printf("[AMQP] Received: %s", indent.Indent(del.Body))
}
var newDep deps.Dep
......
package rest
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
......@@ -11,6 +10,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
)
type (
......@@ -70,13 +70,7 @@ func (src Source) fetchDeps(sink chan<- deps.Dep) (err error) {
}
if src.Config.Debug.Backend {
indented := new(bytes.Buffer)
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)
}
log.Printf("[HTTP] Fetched: %s", indent.Indent(body))
}
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