mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
created filenaming func, updated dockerfile
This commit is contained in:
parent
804e714eaf
commit
4dcedfbe14
3 changed files with 59 additions and 86 deletions
32
Dockerfile
32
Dockerfile
|
@ -1,25 +1,35 @@
|
||||||
# build stage
|
# build stage
|
||||||
FROM golang:alpine AS build-env
|
FROM golang:1.17.0-alpine AS build-env
|
||||||
RUN apk --no-cache add build-base git gcc
|
RUN apk --no-cache add build-base git gcc
|
||||||
RUN git clone https://github.com/RaaLabs/steward.git
|
|
||||||
WORKDIR /go/steward/cmd
|
RUN mkdir -p /build
|
||||||
|
COPY ./steward /build/
|
||||||
|
|
||||||
|
WORKDIR /build/cmd/steward/
|
||||||
|
RUN go version
|
||||||
RUN go build -o steward
|
RUN go build -o steward
|
||||||
|
|
||||||
# final stage
|
# final stage
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk update && apk add curl && apk add nmap
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build-env /go/steward/cmd/steward /app/
|
COPY --from=build-env /build/cmd/steward/steward /app/
|
||||||
|
|
||||||
ENV CONFIG_FOLDER "./etc"
|
ENV CONFIG_FOLDER "./etc"
|
||||||
ENV SOCKET_FOLDER "./tmp"
|
ENV SOCKET_FOLDER "./tmp"
|
||||||
|
ENV TCP_LISTENER ""
|
||||||
ENV DATABASE_FOLDER "./var/lib"
|
ENV DATABASE_FOLDER "./var/lib"
|
||||||
ENV NODE_NAME ""
|
ENV NODE_NAME ""
|
||||||
ENV BROKER_ADDRESS "127.0.0.1:4222"
|
ENV BROKER_ADDRESS "127.0.0.1:4222"
|
||||||
|
ENV NATS_CONNECT_RETRY_INTERVAL "10"
|
||||||
ENV PROFILING_PORT ""
|
ENV PROFILING_PORT ""
|
||||||
ENV PROM_HOST_AND_PORT ""
|
ENV PROM_HOST_AND_PORT "127.0.0.1:2111"
|
||||||
ENV DEFAULT_MESSAGE_TIMEOUT 10
|
ENV DEFAULT_MESSAGE_TIMEOUT 10
|
||||||
ENV DEFAULT_MESSAGE_RETRIES 3
|
ENV DEFAULT_MESSAGE_RETRIES 3
|
||||||
ENV SUBSCRIBERS_DATA_FOLDER "./var"
|
ENV SUBSCRIBERS_DATA_FOLDER "./var"
|
||||||
|
ENV EXPOSE_DATA_FOLDER "127.0.0.1:8090"
|
||||||
ENV CENTRAL_NODE_NAME ""
|
ENV CENTRAL_NODE_NAME ""
|
||||||
ENV ROOT_CA_PATH ""
|
ENV ROOT_CA_PATH ""
|
||||||
ENV NKEY_SEED_FILE ""
|
ENV NKEY_SEED_FILE ""
|
||||||
|
@ -37,24 +47,25 @@ ENV START_SUB_REQN_CLI_COMMAND ""
|
||||||
ENV START_SUB_REQ_TO_CONSOLE ""
|
ENV START_SUB_REQ_TO_CONSOLE ""
|
||||||
ENV START_SUB_REQ_HTTP_GET ""
|
ENV START_SUB_REQ_HTTP_GET ""
|
||||||
ENV START_SUB_REQ_TAIL_FILE ""
|
ENV START_SUB_REQ_TAIL_FILE ""
|
||||||
|
ENV START_SUB_REQ_N_CLI_COMMAND_CONT ""
|
||||||
|
|
||||||
CMD ["ash","-c","/app/steward\
|
CMD ["ash","-c","env CONFIGFOLDER=./etc/ /app/steward\
|
||||||
-configFolder=$CONFIG_FOLDER\
|
|
||||||
-socketFolder=$SOCKET_FOLDER\
|
-socketFolder=$SOCKET_FOLDER\
|
||||||
|
-tcpListener=$TCP_LISTENER\
|
||||||
-databaseFolder=$DATABASE_FOLDER\
|
-databaseFolder=$DATABASE_FOLDER\
|
||||||
-nodeName=$NODE_NAME\
|
-nodeName=$NODE_NAME\
|
||||||
-brokerAddress=$BROKER_ADDRESS\
|
-brokerAddress=$BROKER_ADDRESS\
|
||||||
|
-natsConnectRetryInterval=$NATS_CONNECT_RETRY_INTERVAL\
|
||||||
-profilingPort=$PROFILING_PORT\
|
-profilingPort=$PROFILING_PORT\
|
||||||
-promHostAndPort=$PROM_HOST_AND_PORT\
|
-promHostAndPort=$PROM_HOST_AND_PORT\
|
||||||
-defaultMessageTimeout=$DEFAULT_MESSAGE_TIMEOUT\
|
-defaultMessageTimeout=$DEFAULT_MESSAGE_TIMEOUT\
|
||||||
-defaultMessageRetries=$DEFAULT_MESSAGE_RETRIES\
|
-defaultMessageRetries=$DEFAULT_MESSAGE_RETRIES\
|
||||||
-subscribersDataFolder=SUBSCRIBERS_DATA_FOLDER\
|
-subscribersDataFolder=$SUBSCRIBERS_DATA_FOLDER\
|
||||||
|
-exposeDataFolder=$EXPOSE_DATA_FOLDER\
|
||||||
-centralNodeName=$CENTRAL_NODE_NAME\
|
-centralNodeName=$CENTRAL_NODE_NAME\
|
||||||
-rootCAPath=$ROOT_CA_PATH\
|
-rootCAPath=$ROOT_CA_PATH\
|
||||||
-nkeySeedFile=$NKEY_SEED_FILE\
|
-nkeySeedFile=$NKEY_SEED_FILE\
|
||||||
|
|
||||||
-startPubREQHello=$START_PUB_REQ_HELLO\
|
-startPubREQHello=$START_PUB_REQ_HELLO\
|
||||||
|
|
||||||
-startSubREQErrorLog=$START_SUB_REQ_ERROR_LOG\
|
-startSubREQErrorLog=$START_SUB_REQ_ERROR_LOG\
|
||||||
-startSubREQHello=$START_SUB_REQ_HELLO\
|
-startSubREQHello=$START_SUB_REQ_HELLO\
|
||||||
-startSubREQToFileAppend=$START_SUB_REQ_TO_FILE_APPEND\
|
-startSubREQToFileAppend=$START_SUB_REQ_TO_FILE_APPEND\
|
||||||
|
@ -66,4 +77,5 @@ CMD ["ash","-c","/app/steward\
|
||||||
-startSubREQToConsole=$START_SUB_REQ_TO_CONSOLE\
|
-startSubREQToConsole=$START_SUB_REQ_TO_CONSOLE\
|
||||||
-startSubREQHttpGet=$START_SUB_REQ_HTTP_GET\
|
-startSubREQHttpGet=$START_SUB_REQ_HTTP_GET\
|
||||||
-startSubREQTailFile=$START_SUB_REQ_TAIL_FILE\
|
-startSubREQTailFile=$START_SUB_REQ_TAIL_FILE\
|
||||||
|
-startSubREQnCliCommandCont=$START_SUB_REQ_N_CLI_COMMAND_CONT\
|
||||||
"]
|
"]
|
|
@ -650,6 +650,12 @@ For CliCommand message to a node named "ship1" of type Command and it wants an A
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
Put in a limit on error messages if the central for some reason have not started errorLog, since you will be spammed with this..
|
||||||
|
|
||||||
|
2021/09/04 05:56:00 <--- publisher: received ACK from:errorCentral, for: REQErrorLog, data: not allowed from central
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
Services at startup of Steward. Could be implemented by having a local folder of messages to go through at startup. What is needed:
|
Services at startup of Steward. Could be implemented by having a local folder of messages to go through at startup. What is needed:
|
||||||
|
|
||||||
- A Handler that writes to this folder.
|
- A Handler that writes to this folder.
|
||||||
|
|
|
@ -291,6 +291,31 @@ func newReplyMessage(proc process, message Message, outData []byte) {
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
proc.toRingbufferCh <- []subjectAndMessage{sam}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selectFileNaming will figure out the correct naming of the file
|
||||||
|
// structure to use for the reply data.
|
||||||
|
// It will return the filename, and the tree structure for the folders
|
||||||
|
// to create.
|
||||||
|
func selectFileNaming(message Message, proc process) (string, string) {
|
||||||
|
var fileName string
|
||||||
|
var folderTree string
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case message.PreviousMessage == nil:
|
||||||
|
// If this was a direct request there are no previous message to take
|
||||||
|
// information from, so we use the one that are in the current mesage.
|
||||||
|
fileName = message.FileName
|
||||||
|
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode))
|
||||||
|
case message.PreviousMessage.ToNode != "":
|
||||||
|
fileName = message.PreviousMessage.FileName
|
||||||
|
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
|
||||||
|
case message.PreviousMessage.ToNode == "":
|
||||||
|
fileName = message.PreviousMessage.FileName
|
||||||
|
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName, folderTree
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// Subscriber method handlers
|
// Subscriber method handlers
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
@ -490,21 +515,7 @@ func (m methodREQToFileAppend) handler(proc process, message Message, node strin
|
||||||
|
|
||||||
// If it was a request type message we want to check what the initial messages
|
// If it was a request type message we want to check what the initial messages
|
||||||
// method, so we can use that in creating the file name to store the data.
|
// method, so we can use that in creating the file name to store the data.
|
||||||
var fileName string
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
var folderTree string
|
|
||||||
switch {
|
|
||||||
case message.PreviousMessage == nil:
|
|
||||||
// If this was a direct request there are no previous message to take
|
|
||||||
// information from, so we use the one that are in the current mesage.
|
|
||||||
fileName = message.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode), string(message.Method))
|
|
||||||
case message.PreviousMessage.ToNode != "":
|
|
||||||
fileName = message.PreviousMessage.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode), string(message.PreviousMessage.Method))
|
|
||||||
case message.PreviousMessage.ToNode == "":
|
|
||||||
fileName = message.PreviousMessage.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode), string(message.Method))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
@ -559,21 +570,7 @@ func (m methodREQToFile) handler(proc process, message Message, node string) ([]
|
||||||
|
|
||||||
// If it was a request type message we want to check what the initial messages
|
// If it was a request type message we want to check what the initial messages
|
||||||
// method, so we can use that in creating the file name to store the data.
|
// method, so we can use that in creating the file name to store the data.
|
||||||
var fileName string
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
var folderTree string
|
|
||||||
switch {
|
|
||||||
case message.PreviousMessage == nil:
|
|
||||||
// If this was a direct request there are no previous message to take
|
|
||||||
// information from, so we use the one that are in the current mesage.
|
|
||||||
fileName = message.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode), string(message.Method))
|
|
||||||
case message.PreviousMessage.ToNode != "":
|
|
||||||
fileName = message.PreviousMessage.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode), string(message.PreviousMessage.Method))
|
|
||||||
case message.PreviousMessage.ToNode == "":
|
|
||||||
fileName = message.PreviousMessage.FileName
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode), string(message.Method))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
@ -682,21 +679,7 @@ func (m methodREQErrorLog) handler(proc process, message Message, node string) (
|
||||||
|
|
||||||
// If it was a request type message we want to check what the initial messages
|
// If it was a request type message we want to check what the initial messages
|
||||||
// method, so we can use that in creating the file name to store the data.
|
// method, so we can use that in creating the file name to store the data.
|
||||||
var fileName string
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
var folderTree string
|
|
||||||
switch {
|
|
||||||
case message.PreviousMessage == nil:
|
|
||||||
// If this was a direct request there are no previous message to take
|
|
||||||
// information from, so we use the one that are in the current mesage.
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode), string(message.Method))
|
|
||||||
case message.PreviousMessage.ToNode != "":
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode), string(message.PreviousMessage.Method))
|
|
||||||
case message.PreviousMessage.ToNode == "":
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode), string(message.Method))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
@ -745,21 +728,7 @@ func (m methodREQPing) handler(proc process, message Message, node string) ([]by
|
||||||
|
|
||||||
// If it was a request type message we want to check what the initial messages
|
// If it was a request type message we want to check what the initial messages
|
||||||
// method, so we can use that in creating the file name to store the data.
|
// method, so we can use that in creating the file name to store the data.
|
||||||
var fileName string
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
var folderTree string
|
|
||||||
switch {
|
|
||||||
case message.PreviousMessage == nil:
|
|
||||||
// If this was a direct request there are no previous message to take
|
|
||||||
// information from, so we use the one that are in the current mesage.
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode), string(message.Method))
|
|
||||||
case message.PreviousMessage.ToNode != "":
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode), string(message.PreviousMessage.Method))
|
|
||||||
case message.PreviousMessage.ToNode == "":
|
|
||||||
fileName = fmt.Sprintf("%v-%v", string(message.FromNode), message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode), string(message.Method))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
@ -823,21 +792,7 @@ func (m methodREQPong) handler(proc process, message Message, node string) ([]by
|
||||||
|
|
||||||
// If it was a request type message we want to check what the initial messages
|
// If it was a request type message we want to check what the initial messages
|
||||||
// method, so we can use that in creating the file name to store the data.
|
// method, so we can use that in creating the file name to store the data.
|
||||||
var fileName string
|
fileName, folderTree := selectFileNaming(message, proc)
|
||||||
var folderTree string
|
|
||||||
switch {
|
|
||||||
case message.PreviousMessage == nil:
|
|
||||||
// If this was a direct request there are no previous message to take
|
|
||||||
// information from, so we use the one that are in the current mesage.
|
|
||||||
fileName = fmt.Sprintf("%v", message.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode), string(message.Method))
|
|
||||||
case message.PreviousMessage.ToNode != "":
|
|
||||||
fileName = fmt.Sprintf("%v", message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode), string(message.PreviousMessage.Method))
|
|
||||||
case message.PreviousMessage.ToNode == "":
|
|
||||||
fileName = fmt.Sprintf("%v", message.PreviousMessage.FileName)
|
|
||||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode), string(message.Method))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if folder structure exist, if not create it.
|
// Check if folder structure exist, if not create it.
|
||||||
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
if _, err := os.Stat(folderTree); os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in a new issue