diff --git a/deploy/vagrant/two-machine/package.json b/deploy/vagrant/two-machine/package.json new file mode 100644 index 000000000..67281a69c --- /dev/null +++ b/deploy/vagrant/two-machine/package.json @@ -0,0 +1,8 @@ +{ + "type": "module", + "dependencies": { + "chalk": "^5.3.0", + "execa": "^8.0.1", + "js-yaml": "^4.1.0" + } +} diff --git a/deploy/vagrant/two-machine/services.js b/deploy/vagrant/two-machine/services.js new file mode 100755 index 000000000..a4284bcd4 --- /dev/null +++ b/deploy/vagrant/two-machine/services.js @@ -0,0 +1,118 @@ +#!/usr/bin/node +/* Install the optional platform services for DTaaS */ +import {$} from 'execa'; +import chalk from 'chalk'; +import fs from 'fs'; +import yaml from 'js-yaml'; + +const $$ = $({stdio: 'inherit'}); +const log = console.log; +let config; + +const sleep = (ms) => + new Promise((r) => { + setTimeout(r, ms); + }); + + try { + console.log(chalk.blue("Load services configuration")); + config = await yaml.load(fs.readFileSync('services.yml', 'utf8')); + log(chalk.green("configuration loading is successful and config is a valid yaml file")); +} catch (e) { + log(chalk.red("configuration is invalid. Please rectify services.yml file")); + process.exit(1); +} + +//--------------- +log(chalk.blue("Start InfluxDB server")); +const influxdbConfig = config.services.influxdb; + +try { + log(chalk.green("Attempt to delete any existing InfluxDB server docker container")); + await $$`docker stop influxdb`; + await $$`docker rm influxdb`; +} catch (e) { +} + +log(chalk.green("Start new InfluxDB server docker container")); +await $$`docker run -d -p ${influxdbConfig.port}:8086 \ +--name influxdb \ +-v ${influxdbConfig.datapath}/data:/var/lib/influxdb2 \ +-v ${influxdbConfig.datapath}/config:/etc/influxdb2 \ +-e DOCKER_INFLUXDB_INIT_MODE=setup \ +-e DOCKER_INFLUXDB_INIT_USERNAME=${influxdbConfig.username} \ +-e DOCKER_INFLUXDB_INIT_PASSWORD=${influxdbConfig.password} \ +-e DOCKER_INFLUXDB_INIT_ORG=dtaas \ +-e DOCKER_INFLUXDB_INIT_BUCKET=dtaas \ +influxdb:2.7`; +log(chalk.green("InfluxDB server docker container started successfully")); + + +//--------------- +log(chalk.blue("Start Grafana server")); +const grafanaConfig = config.services.grafana; + +try { + log(chalk.green("Attempt to delete any existing Grafana server docker container")); + await $$`docker stop grafana`; + await $$`docker rm grafana`; +} catch (e) { +} +log(chalk.green("Start new Grafana server docker container")); +await $$`docker run -d \ + -p ${grafanaConfig.port}:3000 \ + --name=grafana \ + -e "GF_SERVER_SERVE_FROM_SUB_PATH=true" \ + -e "GF_SERVER_DOMAIN=${grafanaConfig.hostname}" \ + -e "GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s:%(http_port)s" \ + -e "GF_AUTH_BASIC_ENABLED=false" \ + -e "GF_AUTH_PROXY_ENABLED=false" \ + -e "GF_SECURITY_ALLOW_EMBEDDING=true" \ + -e "GF_SECURITY_ALLOW_EMBEDDING=true" \ + -e "GF_AUTH_ANONYMOUS_ENABLED=true" \ + -e "GF_AUTH_ANONYMOUS_ORG_NAME=Main" \ + -e "GF_AUTH_ANONYMOUS_ORG_ROLE=Editor" \ + -e "GF_USERS_ALLOW_SIGN_UP=false" \ + -e "GF_FEATURE_TOGGLES_ENABLE=publicDashboards" \ + -e "GF_PATHS_CONFIG=/etc/grafana/grafana.ini" \ + -e "GF_PATHS_DATA=/var/lib/grafana" \ + -e "GF_PATHS_HOME=/usr/share/grafana" \ + -e "GF_PATHS_LOGS=/var/log/grafana" \ + -e "GF_PATHS_PLUGINS=/var/lib/grafana/plugins" \ + -e "GF_PATHS_PROVISIONING=/etc/grafana/provisioning" \ + -e "HOME=/home/grafana" \ + grafana/grafana:10.1.4`; +log(chalk.green("Grafana server docker container started successfully")); + +console.log(chalk.blue("Wait one minute for Grafana server to bootstrap")); +await sleep(60000); //60 seconds + +await $$`docker exec grafana grafana-cli admin reset-admin-password ${grafanaConfig.password}`; +log(chalk.redBright("Credentials: username=admin, password=")); +//log(chalk.redBright("Remember to change the default password for admin\n")); + + +//--------------- +log(chalk.blue("Start RabbitMQ server")); +const rabbitmqConfig = config.services.rabbitmq; + +try { + log(chalk.green("Attempt to delete existing RabbitMQ server docker container")); + await $$`docker stop rabbitmq-server`; + await $$`docker rm rabbitmq-server`; +} catch (e) { +} +//await $$`docker run -d --name rabbitmq-server -p 5672:5672 -p 15672:15672 rabbitmq:3-management`; +log(chalk.green("Start RabbitMQ server docker container")); +await $$`docker run -d --name rabbitmq-server \ + -p ${rabbitmqConfig.ports.main}:5672 \ + -p ${rabbitmqConfig.ports.management}:15672 rabbitmq:3-management`; +log(chalk.green("RabbitMQ server docker container started successfully\n")); + +console.log(chalk.blue("Wait 2 minutes for RabbitMQ server to bootstrap")); +await sleep(120000); //120 seconds + +let args = [rabbitmqConfig.username, rabbitmqConfig.password]; +//console.log(chalk.blue("Add ${rabbitmqConfig.username} user and give permission to ${rabbitmqConfig.vhost} vhost")); +await $$`docker exec rabbitmq-server rabbitmqctl add_user ${args}`; +await $$`docker exec rabbitmq-server rabbitmqctl set_permissions -p ${rabbitmqConfig.vhost} ${rabbitmqConfig.username} ".*" ".*" ".*"`; diff --git a/deploy/vagrant/two-machine/services.sh b/deploy/vagrant/two-machine/services.sh deleted file mode 100755 index c68546e9c..000000000 --- a/deploy/vagrant/two-machine/services.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -#start RabbitMQ server -docker run -d \ - --name rabbitmq-server \ - -p 15672:15672 -p 5672:5672 \ - rabbitmq:3-management - -printf "Waiting for 2 minutes for rabbitmq server to come up..." -sleep 120 - -# setup users and permissions from within the rabbitmq container -docker exec rabbitmq-server rabbitmqctl add_user incubator incubator -docker exec rabbitmq-server rabbitmqctl set_permissions -p "/" incubator ".*" ".*" ".*" - -#start Grafana server -docker run -d \ - -p 3000:3000 \ - --name=grafana \ - -e "GF_SERVER_SERVE_FROM_SUB_PATH=true" \ - -e "GF_SERVER_DOMAIN=localhost" \ - -e "GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s:%(http_port)s" \ - -e "GF_AUTH_BASIC_ENABLED=false" \ - -e "GF_AUTH_PROXY_ENABLED=false" \ - -e "GF_SECURITY_ADMIN_PASSWORD=DTaaSGrafana" \ - -e "GF_SECURITY_ALLOW_EMBEDDING=true" \ - -e "GF_SECURITY_ALLOW_EMBEDDING=true" \ - -e "GF_AUTH_ANONYMOUS_ENABLED=true" \ - -e "GF_AUTH_ANONYMOUS_ORG_NAME=Main" \ - -e "GF_AUTH_ANONYMOUS_ORG_ROLE=Editor" \ - -e "GF_USERS_ALLOW_SIGN_UP=false" \ - -e "GF_FEATURE_TOGGLES_ENABLE=publicDashboards" \ - -e "GF_PATHS_CONFIG=/etc/grafana/grafana.ini" \ - -e "GF_PATHS_DATA=/var/lib/grafana" \ - -e "GF_PATHS_HOME=/usr/share/grafana" \ - -e "GF_PATHS_LOGS=/var/log/grafana" \ - -e "GF_PATHS_PLUGINS=/var/lib/grafana/plugins" \ - -e "GF_PATHS_PROVISIONING=/etc/grafana/provisioning" \ - -e "HOME=/home/grafana" \ - grafana/grafana -printf "Complete the setup from GUI" - -#------------- -printf "\n\n start the InfluxDB server" -printf ".........................." -# note: InfluxDB doesn't work on /vagrant shared folder -INFLUXDB_DATA="${PWD}/data/influxdb2" -mkdir -p "$INFLUXDB_DATA" - -# Remember to change the settings -# src: https://hub.docker.com/_/influxdb/ -docker run -d -p 80:8086 \ - --name influxdb24 \ - -v "$INFLUXDB_DATA/data":/var/lib/influxdb2 \ - -v "$INFLUXDB_DATA/config":/etc/influxdb2 \ - -e DOCKER_INFLUXDB_INIT_MODE=setup \ - -e DOCKER_INFLUXDB_INIT_USERNAME=dtaas \ - -e DOCKER_INFLUXDB_INIT_PASSWORD=dtaas1357 \ - -e DOCKER_INFLUXDB_INIT_ORG=dtaas \ - -e DOCKER_INFLUXDB_INIT_BUCKET=dtaas \ - influxdb:2.4 - diff --git a/deploy/vagrant/two-machine/services.yml b/deploy/vagrant/two-machine/services.yml new file mode 100644 index 000000000..89fa3d3d6 --- /dev/null +++ b/deploy/vagrant/two-machine/services.yml @@ -0,0 +1,19 @@ +kind: deployment +services: + rabbitmq: + username: "dtaas" + password: "dtaas" + vhost: "/" + ports: + main: 5672 + management: 15672 + grafana: + hostname: "localhost" + username: "admin" # do not change + password: "dtaas" + port: 3000 + influxdb: + username: "dtaas" + password: "dtaas1357" # need to have letters and numbers + datapath: "/home/prasad/git/prasadtalasila/DTaaS/deploy/vagrant/two-machine/influx" #no spaces in the path + port: 80 diff --git a/deploy/vagrant/two-machine/yarn.lock b/deploy/vagrant/two-machine/yarn.lock new file mode 100644 index 000000000..ca01118a4 --- /dev/null +++ b/deploy/vagrant/two-machine/yarn.lock @@ -0,0 +1,127 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +argparse@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" + integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== + +chalk@^5.3.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385" + integrity sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w== + +cross-spawn@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + +execa@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/execa/-/execa-8.0.1.tgz#51f6a5943b580f963c3ca9c6321796db8cc39b8c" + integrity sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg== + dependencies: + cross-spawn "^7.0.3" + get-stream "^8.0.1" + human-signals "^5.0.0" + is-stream "^3.0.0" + merge-stream "^2.0.0" + npm-run-path "^5.1.0" + onetime "^6.0.0" + signal-exit "^4.1.0" + strip-final-newline "^3.0.0" + +get-stream@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-8.0.1.tgz#def9dfd71742cd7754a7761ed43749a27d02eca2" + integrity sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA== + +human-signals@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-5.0.0.tgz#42665a284f9ae0dade3ba41ebc37eb4b852f3a28" + integrity sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ== + +is-stream@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac" + integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA== + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== + +js-yaml@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1" + +merge-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" + integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== + +mimic-fn@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc" + integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw== + +npm-run-path@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-5.1.0.tgz#bc62f7f3f6952d9894bd08944ba011a6ee7b7e00" + integrity sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q== + dependencies: + path-key "^4.0.0" + +onetime@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-6.0.0.tgz#7c24c18ed1fd2e9bca4bd26806a33613c77d34b4" + integrity sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ== + dependencies: + mimic-fn "^4.0.0" + +path-key@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" + integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== + +path-key@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-4.0.0.tgz#295588dc3aee64154f877adb9d780b81c554bf18" + integrity sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ== + +shebang-command@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" + integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== + dependencies: + shebang-regex "^3.0.0" + +shebang-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" + integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== + +signal-exit@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" + integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== + +strip-final-newline@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-3.0.0.tgz#52894c313fbff318835280aed60ff71ebf12b8fd" + integrity sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw== + +which@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== + dependencies: + isexe "^2.0.0"