diff --git a/scripts/nats-server/README.md b/scripts/nats-server/README.md new file mode 100644 index 0000000..cab399b --- /dev/null +++ b/scripts/nats-server/README.md @@ -0,0 +1,31 @@ +# nats-server configuration + +This folder contains several scripts to help out setting up the nats-server configuration. + +You can run each script individually, or you can use one of the wrapper scripts. + +## 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 +``` + +Execute the wrapper script with the following arguments: + +`./steward/scripts/nats-server/wrapper.sh ` + +```bash +./steward/scripts/nats-server/wrapper.sh ../some/dir/le.crt ../some/dir/le.key 50222 +``` + +This will create all files needed, but you need to add user configuration to the **nats.conf** file manually. + +A template for the central steward instance are added by default, but **you need** to edit the file and replace the **`FILL-IN...`** fields with your central user key, and **organization name** according to the naming you want to use as node names. **Read more about the naming in the main README.md.** + +**NB**: LetsEncrypt certificate can be generated by using \ No newline at end of file diff --git a/scripts/nats-server/create-docker-compose-files/main.go b/scripts/nats-server/create-docker-compose-files/main.go index 5cdcbae..b9d8ac1 100644 --- a/scripts/nats-server/create-docker-compose-files/main.go +++ b/scripts/nats-server/create-docker-compose-files/main.go @@ -16,7 +16,7 @@ import ( func generateEnv(templateFile string, eData envData) error { tpl, err := template.ParseFiles(templateFile) if err != nil { - return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err) + return fmt.Errorf("error: parsing template file, check that the templateDir flag is set to the correct path: %v, err: %v", templateFile, err) } fh, err := os.OpenFile("env.env", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755) @@ -37,7 +37,7 @@ func generateEnv(templateFile string, eData envData) error { func generateDockerCompose(templateFile string, cData composeData) error { tpl, err := template.ParseFiles(templateFile) if err != nil { - return fmt.Errorf("error: parsing template file: %v, err: %v", templateFile, err) + return fmt.Errorf("error: parsing template file, check that the templateDir flag is set to the correct path: %v, err: %v", templateFile, err) } fh, err := os.OpenFile("docker-compose.yml", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755) @@ -76,7 +76,7 @@ func main() { flags := flag.String("Flags", "-d", "flags to start nats-server with") - templateDir := flag.String("templateDir", "./", "the directory path to where the template files are located") + templateDir := flag.String("templateDir", "./steward/scripts/nats-server/create-docker-compose-files/", "the directory path to where the template files are located") flag.Parse() diff --git a/scripts/nats-server/generate-nats-conf/generate-nats-conf.sh b/scripts/nats-server/generate-nats-conf/generate-nats-conf.sh index 6ebbc6d..850b2e8 100755 --- a/scripts/nats-server/generate-nats-conf/generate-nats-conf.sh +++ b/scripts/nats-server/generate-nats-conf/generate-nats-conf.sh @@ -12,6 +12,18 @@ authorization: { { } + { + # central + nkey: FILL-IN-CENTRAL-USER-KEY-HERE + permissions: { + publish: { + allow: ["FILL-IN-ORGANISATION-HERE.>","errorCentral.>","central.>"] + } + subscribe: { + allow: ["FILL-IN-ORGANISATION-HERE.>","errorCentral.>","central.>"] + } + } + } ] } EOF diff --git a/scripts/nats-server/wrapper-docker-compose.sh b/scripts/nats-server/wrapper-docker-compose.sh new file mode 100755 index 0000000..e482adb --- /dev/null +++ b/scripts/nats-server/wrapper-docker-compose.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# TO USE: +# ./wrapper ./le.crt ./le.key 50222 + +LE_CRT=$1 +LE_KEY=$2 +EXPOSED_NATS_PORT=$3 + +if go run ./steward/scripts/nats-server/generate-nkeys/main.go; then + echo " * succesfully generated nkeys" +else + echo " * failed to generate nkeys" + exit 1 +fi + +if go run ./steward/scripts/nats-server/create-docker-compose-files/main.go -imageAndVersion=nats-server:2.5.0 -natsConfPath=./nats.conf -leCertPath="$LE_CRT" -leKeyPath="$LE_KEY" -exposedNatsPort="$EXPOSED_NATS_PORT" -templateDir=./steward/scripts/nats-server/create-docker-compose-files/; then + echo " * succesfully generated docker-compose and env.env file" +else + echo " * failed to generate docker-compse and env.env file" + exit 1 +fi + +if ./steward/scripts/nats-server/generate-nats-conf/generate-nats-conf.sh; then + echo " * succesfully generated nats.conf" +else + echo " * failed to generate nats-conf" + exit 1 +fi