mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-05 20:09:16 +00:00
created wrapper script for nats-server config
This commit is contained in:
parent
cd421106e3
commit
cac0896485
4 changed files with 75 additions and 3 deletions
31
scripts/nats-server/README.md
Normal file
31
scripts/nats-server/README.md
Normal file
|
@ -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 <LetsEncrypt Cert file> <LetsEncrypt Key file> <nats-server listen port>`
|
||||||
|
|
||||||
|
```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 <https://github.com/RaaLabs/certupdater>
|
|
@ -16,7 +16,7 @@ import (
|
||||||
func generateEnv(templateFile string, eData envData) error {
|
func generateEnv(templateFile string, eData envData) 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, 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)
|
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 {
|
func generateDockerCompose(templateFile string, cData composeData) 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, 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)
|
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")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
|
@ -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
|
EOF
|
||||||
|
|
29
scripts/nats-server/wrapper-docker-compose.sh
Executable file
29
scripts/nats-server/wrapper-docker-compose.sh
Executable file
|
@ -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
|
Loading…
Reference in a new issue