mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
added script for making docker-compose files
This commit is contained in:
parent
3b106644e3
commit
f77de0d17d
4 changed files with 162 additions and 0 deletions
Binary file not shown.
Before Width: | Height: | Size: 36 KiB |
107
scripts/create_docker-compose_files/main.go
Normal file
107
scripts/create_docker-compose_files/main.go
Normal file
|
@ -0,0 +1,107 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// generateEnv will generate the env.env file.
|
||||
func generateEnv(templateFile string, brokerAddress string) error {
|
||||
tpl, err := template.ParseFiles(templateFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err)
|
||||
}
|
||||
|
||||
data := struct {
|
||||
BrokerAddressAndPort string
|
||||
}{
|
||||
BrokerAddressAndPort: brokerAddress,
|
||||
}
|
||||
|
||||
fh, err := os.OpenFile("env.env", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: opening env.env for writing: %v, err: %v", templateFile, err)
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
err = tpl.Execute(fh, data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: exeuting template file: %v, err: %v", templateFile, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// generateDockerCompose will generate the docker-compose.yml file.
|
||||
func generateDockerCompose(templateFile string, imageAndVersion string, exposedProfilingPort string, exposedPrometheusPort string, exposedDataFolderPort string, exposedTcpListenerPort string, exposedHttpListenerPort string, nkeySeedFile string, socketFolder string) error {
|
||||
tpl, err := template.ParseFiles(templateFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err)
|
||||
}
|
||||
|
||||
data := struct {
|
||||
ImageAndVersion string
|
||||
ExposedProfilingPort string
|
||||
ExposedPrometheusPort string
|
||||
ExposedDataFolderPort string
|
||||
ExposedTcpListenerPort string
|
||||
ExposedHttpListenerPort string
|
||||
NkeySeedFile string
|
||||
SocketFolder string
|
||||
}{
|
||||
ImageAndVersion: imageAndVersion,
|
||||
ExposedProfilingPort: exposedProfilingPort,
|
||||
ExposedPrometheusPort: exposedPrometheusPort,
|
||||
ExposedDataFolderPort: exposedDataFolderPort,
|
||||
ExposedTcpListenerPort: exposedTcpListenerPort,
|
||||
ExposedHttpListenerPort: exposedHttpListenerPort,
|
||||
NkeySeedFile: nkeySeedFile,
|
||||
SocketFolder: socketFolder,
|
||||
}
|
||||
|
||||
fh, err := os.OpenFile("docker-compose.yml", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: opening docker-compose.yml for writing: %v, err: %v", templateFile, err)
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
err = tpl.Execute(fh, data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: exeuting template file: %v, err: %v", templateFile, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
brokerAddress := flag.String("brokerAddress", "", "the address:port of the broker to connect to")
|
||||
imageAndVersion := flag.String("imageAndVersion", "", "The name:version of the docker image to use")
|
||||
exposedProfilingPort := flag.String("exposedProfilingPort", "6666", "the address:port to expose")
|
||||
exposedPrometheusPort := flag.String("exposedPrometheusPort", "2111", "the address:port to expose")
|
||||
exposedDataFolderPort := flag.String("exposedDataFolderPort", "8090", "the address:port to expose")
|
||||
exposedTcpListenerPort := flag.String("exposedTcpListenerPort", "8091", "the address:port to expose")
|
||||
exposedHttpListenerPort := flag.String("exposedHttpListenerPort", "8092", "the address:port to expose")
|
||||
nkeySeedFile := flag.String("nkeySeedFile", "/tmp/seed.txt", "the complete path of the seed file to mount")
|
||||
socketFolder := flag.String("sockerFolder", "/tmp/tmp/", "the complete path of the socket folder to mount")
|
||||
flag.Parse()
|
||||
|
||||
if *brokerAddress == "" {
|
||||
log.Printf("error: -brokerAddress flag can not be empty\n")
|
||||
return
|
||||
}
|
||||
|
||||
err := generateEnv("template_env.env", *brokerAddress)
|
||||
if err != nil {
|
||||
log.Printf("%v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = generateDockerCompose("template_docker-compose.yml", *imageAndVersion, *exposedProfilingPort, *exposedPrometheusPort, *exposedDataFolderPort, *exposedTcpListenerPort, *exposedHttpListenerPort, *nkeySeedFile, *socketFolder)
|
||||
if err != nil {
|
||||
log.Printf("%v\n", err)
|
||||
return
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
version: "3.1"
|
||||
|
||||
# docker run -it --rm -v '/home/bt/docker/steward/wireguard:/etc/wireguard' --env-file env.env steward:0.1.6
|
||||
|
||||
services:
|
||||
steward:
|
||||
build: .
|
||||
env_file:
|
||||
- env.env
|
||||
secrets:
|
||||
- seed
|
||||
image: {{.ImageAndVersion}}
|
||||
restart: always
|
||||
ports:
|
||||
- "{{.ExposedProfilingPort}}:6666"
|
||||
- "{{.ExposedPrometheusPort}}:2111"
|
||||
- "{{.ExposedDataFolderPort}}:8090"
|
||||
- "{{.ExposedTcpListenerPort}}:8091"
|
||||
- "{{.ExposedHttpListenerPort}}:8092"
|
||||
volumes:
|
||||
# - {{.NkeySeedFile}}:/app/seed.txt
|
||||
- {{.SocketFolder}}:/app/tmp/:rw
|
||||
|
||||
secrets:
|
||||
seed:
|
||||
file: {{.NkeySeedFile}}
|
29
scripts/create_docker-compose_files/template_env.env
Normal file
29
scripts/create_docker-compose_files/template_env.env
Normal file
|
@ -0,0 +1,29 @@
|
|||
CONFIG_FOLDER=./etc
|
||||
SOCKET_FOLDER=./tmp
|
||||
TCP_LISTENER=:8091
|
||||
HTTP_LISTENER=:8092
|
||||
DATABASE_FOLDER=./var/lib
|
||||
NODE_NAME=central
|
||||
BROKER_ADDRESS={{.BrokerAddressAndPort}}
|
||||
PROFILING_PORT=:6666
|
||||
PROM_HOST_AND_PORT=:2111
|
||||
DEFAULT_MESSAGE_TIMEOUT=10
|
||||
DEFAULT_MESSAGE_RETRIES=3
|
||||
ERROR_MESSAGE_RETRIES=10
|
||||
ERROR_MESSAGE_TIMEOUT=3
|
||||
SUBSCRIBERS_DATA_FOLDER=./data/
|
||||
EXPOSE_DATA_FOLDER=:8090
|
||||
CENTRAL_NODE_NAME=central
|
||||
ROOT_CA_PATH=""
|
||||
NKEY_SEED_FILE=/run/secrets/seed
|
||||
START_PUB_REQ_HELLO=60
|
||||
START_SUB_REQ_ERROR_LOG=true
|
||||
START_SUB_REQ_HELLO=true
|
||||
START_SUB_REQ_TO_FILE_APPEND=true
|
||||
START_SUB_REQ_TO_FILE=true
|
||||
START_SUB_REQ_PING=true
|
||||
START_SUB_REQ_PONG=true
|
||||
START_SUB_REQ_CLI_COMMAND=true
|
||||
START_SUB_REQ_TO_CONSOLE=true
|
||||
START_SUB_REQ_HTTP_GET=true
|
||||
START_SUB_REQ_TAIL_FILE=true
|
Loading…
Reference in a new issue