mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
more scripting compose files
This commit is contained in:
parent
cac0896485
commit
a9308b2706
3 changed files with 104 additions and 15 deletions
3
scripts/method-helpers/README.md
Normal file
3
scripts/method-helpers/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Method helpers
|
||||||
|
|
||||||
|
A collection of various scripts to be called via method args.
|
23
scripts/steward/create-docker-compose-files/README.md
Normal file
23
scripts/steward/create-docker-compose-files/README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Create docker compose file for Steward
|
||||||
|
|
||||||
|
## docker-compose
|
||||||
|
|
||||||
|
Create a directory where you want your docker compose files, and enter that directory
|
||||||
|
|
||||||
|
Clone the steward repository:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir my_dir
|
||||||
|
cd my_dir
|
||||||
|
git clone https://github.com/RaaLabs/steward.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create the public and private nkey's by running:
|
||||||
|
|
||||||
|
`go run ./steward/scripts/nats-server/generate-nkeys/main.go`
|
||||||
|
|
||||||
|
To create the docker-compose and env.env run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go run main.go -brokerAddress=127.0.0.1:4223 -nkeySeedFile=./seed.txt
|
||||||
|
```
|
|
@ -4,19 +4,71 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func generateNkeys(fileDir string) error {
|
||||||
|
cmd := exec.Command("nk", "-gen", "user", "-pubout")
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error: check if the nk tool is installed on the system: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%v\n", string(out))
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(bytes.NewReader(out))
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
text := scanner.Text()
|
||||||
|
fmt.Println("scanning line : ", text)
|
||||||
|
|
||||||
|
if strings.HasPrefix(text, "S") {
|
||||||
|
fmt.Println("found S")
|
||||||
|
p := path.Join(fileDir, "seed.txt")
|
||||||
|
err := writekey(p, []byte(text))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(text, "U") {
|
||||||
|
fmt.Println("found U")
|
||||||
|
p := path.Join(fileDir, "user.txt")
|
||||||
|
err := writekey(p, []byte(text))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writekey(fileName string, b []byte) error {
|
||||||
|
fh, err := os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error: failed to open create/open file for writing: %v", err)
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
|
||||||
|
_, err = fh.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error: failed to write file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// generateEnv will generate the env.env file.
|
// generateEnv will generate the env.env file.
|
||||||
func generateEnv(templateFile string, brokerAddress string) error {
|
func generateEnv(fileDir string, templateDir string, brokerAddress string) error {
|
||||||
|
templateFile := path.Join(templateDir, "template_env.env")
|
||||||
tpl, err := template.ParseFiles(templateFile)
|
tpl, err := template.ParseFiles(templateFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err)
|
return fmt.Errorf("error: parsing template file, you might need to set the -templateDir path: %v, err: %v", templateFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -25,7 +77,8 @@ func generateEnv(templateFile string, brokerAddress string) error {
|
||||||
BrokerAddressAndPort: brokerAddress,
|
BrokerAddressAndPort: brokerAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
fh, err := os.OpenFile("env.env", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
p := path.Join(fileDir, "env.env")
|
||||||
|
fh, err := os.OpenFile(p, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error: opening env.env for writing: %v, err: %v", templateFile, err)
|
return fmt.Errorf("error: opening env.env for writing: %v, err: %v", templateFile, err)
|
||||||
}
|
}
|
||||||
|
@ -40,10 +93,10 @@ func generateEnv(templateFile string, brokerAddress string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateDockerCompose will generate the docker-compose.yml file.
|
// 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 {
|
func generateDockerCompose(fileDir string, templateFile string, imageAndVersion string, exposedProfilingPort string, exposedPrometheusPort string, exposedDataFolderPort string, exposedTcpListenerPort string, exposedHttpListenerPort string, nkeySeedFile string, socketFolder string) error {
|
||||||
tpl, err := template.ParseFiles(templateFile)
|
tpl, err := template.ParseFiles(templateFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err)
|
return fmt.Errorf("error: parsing template file, you might need to set the -templateDir flag : %v, err: %v", templateFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -66,9 +119,10 @@ func generateDockerCompose(templateFile string, imageAndVersion string, exposedP
|
||||||
SocketFolder: socketFolder,
|
SocketFolder: socketFolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
fh, err := os.OpenFile("docker-compose.yml", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
p := path.Join(fileDir, "docker-compose.yml")
|
||||||
|
fh, err := os.OpenFile(p, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error: opening docker-compose.yml for writing: %v, err: %v", templateFile, err)
|
return fmt.Errorf("error: opening docker-compose.yml for writing: %v, err: %v", p, err)
|
||||||
}
|
}
|
||||||
defer fh.Close()
|
defer fh.Close()
|
||||||
|
|
||||||
|
@ -81,6 +135,8 @@ func generateDockerCompose(templateFile string, imageAndVersion string, exposedP
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fileDir := flag.String("fileDir", "./", "the directory path for where to store the files")
|
||||||
|
|
||||||
brokerAddress := flag.String("brokerAddress", "", "the address:port of the broker to connect to")
|
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")
|
imageAndVersion := flag.String("imageAndVersion", "", "The name:version of the docker image to use")
|
||||||
exposedProfilingPort := flag.String("exposedProfilingPort", "6666", "the address:port to expose")
|
exposedProfilingPort := flag.String("exposedProfilingPort", "6666", "the address:port to expose")
|
||||||
|
@ -88,10 +144,11 @@ func main() {
|
||||||
exposedDataFolderPort := flag.String("exposedDataFolderPort", "8090", "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")
|
exposedTcpListenerPort := flag.String("exposedTcpListenerPort", "8091", "the address:port to expose")
|
||||||
exposedHttpListenerPort := flag.String("exposedHttpListenerPort", "8092", "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")
|
nkeySeedFile := flag.String("nkeySeedFile", "./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")
|
socketFolder := flag.String("socketFolder", "./tmp/", "the complete path of the socket folder to mount")
|
||||||
|
|
||||||
|
templateDir := flag.String("templateDir", "./steward/scripts/steward/create-docker-compose-files/", "the directory path to where the template files are located")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
templateDir := flag.String("templateDir", "./", "the directory path to where the template files are located")
|
|
||||||
|
|
||||||
if *brokerAddress == "" {
|
if *brokerAddress == "" {
|
||||||
log.Printf("error: -brokerAddress flag can not be empty\n")
|
log.Printf("error: -brokerAddress flag can not be empty\n")
|
||||||
|
@ -99,9 +156,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
p := path.Join(*templateDir, "template_env.env")
|
err := generateNkeys(*fileDir)
|
||||||
|
|
||||||
err := generateEnv(p, *brokerAddress)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v\n", err)
|
log.Printf("%v\n", err)
|
||||||
return
|
return
|
||||||
|
@ -109,8 +164,16 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
p := path.Join(*templateDir, "template_docker-compose.yml")
|
err := generateEnv(*fileDir, *templateDir, *brokerAddress)
|
||||||
err := generateDockerCompose(p, *imageAndVersion, *exposedProfilingPort, *exposedPrometheusPort, *exposedDataFolderPort, *exposedTcpListenerPort, *exposedHttpListenerPort, *nkeySeedFile, *socketFolder)
|
if err != nil {
|
||||||
|
log.Printf("%v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
template := path.Join(*templateDir, "template_docker-compose.yml")
|
||||||
|
err := generateDockerCompose(*fileDir, template, *imageAndVersion, *exposedProfilingPort, *exposedPrometheusPort, *exposedDataFolderPort, *exposedTcpListenerPort, *exposedHttpListenerPort, *nkeySeedFile, *socketFolder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v\n", err)
|
log.Printf("%v\n", err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue