From a2e00f992a7cde3e4e83add54e7c8064c7792632 Mon Sep 17 00:00:00 2001 From: frikky Date: Sat, 1 Jan 2022 23:17:35 +0100 Subject: [PATCH] Added swarm auto setup to orborus --- docker-compose.yml | 4 +- frontend/package.json | 1 + frontend/src/views/Admin.jsx | 8 +- frontend/src/views/Workflows.jsx | 113 +++++++++++++++++++++++++++- functions/onprem/orborus/orborus.go | 41 ++++++++++ 5 files changed, 161 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a7bd17b2..063f5669 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: frontend: - #build: ./frontend + build: ./frontend image: ghcr.io/frikky/shuffle-frontend:nightly container_name: shuffle-frontend hostname: shuffle-frontend @@ -16,7 +16,7 @@ services: depends_on: - backend backend: - #build: ./backend + build: ./backend image: ghcr.io/frikky/shuffle-backend:nightly container_name: shuffle-backend hostname: ${BACKEND_HOSTNAME} diff --git a/frontend/package.json b/frontend/package.json index acc20550..93f03993 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -64,6 +64,7 @@ "react-router": "^4.3.1", "react-router-dom": "^4.3.1", "react-scripts": "^4.0.1", + "react-shepherd": "^3.3.6", "reactstrap": "^7.1.0", "shellwords": "^0.1.1", "simplebar": "^4.2.3", diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index b8c73e3a..03f3a72d 100644 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -560,11 +560,15 @@ const Admin = (props) => { if (responseJson.reason !== undefined) { alert.error(responseJson.reason); } else { - alert.error("Failed creating suborg"); + alert.error("Failed creating suborg. Please try again"); } } else { - alert.success("Successfully created suborg!"); + alert.success("Successfully created suborg. Reloading in 3 seconds!"); setSelectedUserModalOpen(false); + + setTimeout(() => { + window.location.reload() + }, 2500); } setOrgName(""); diff --git a/frontend/src/views/Workflows.jsx b/frontend/src/views/Workflows.jsx index 73df94dd..e9ec15d0 100644 --- a/frontend/src/views/Workflows.jsx +++ b/frontend/src/views/Workflows.jsx @@ -1,8 +1,10 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useContext } from "react"; import { makeStyles } from "@material-ui/core/styles"; import { useTheme } from "@material-ui/core/styles"; import SecurityFramework from '../components/SecurityFramework.jsx'; +import { ShepherdTour, ShepherdTourContext } from 'react-shepherd' + import { Badge, @@ -2439,7 +2441,104 @@ const Workflows = (props) => { ); + const tourOptions = { + defaultStepOptions: { + classes: "shadow-md bg-purple-dark", + scrollTo: true + }, + useModalOverlay: true, + tourName: workflows, + exitOnEsc: true, + } + + //classes: "custom-class-name-1 custom-class-name-2", + const newSteps = [ + { + id: "intro", + scrollTo: true, + beforeShowPromise: function() { + return new Promise(function(resolve) { + setTimeout(function() { + window.scrollTo(0, 0); + resolve(); + }, 500); + }); + }, + buttons: [ + { + classes: "shepherd-button-primary", + style: { + backgroundColor: "red", + color: "white", + }, + text: "Next", + type: "next" + } + ], + highlightClass: "highlight", + showCancelLink: true, + text: [ + "React-Shepherd is a JavaScript library for guiding users through your React app." + ], + when: { + show: () => { + console.log("show step 1"); + }, + hide: () => { + console.log("hide step 1"); + } + } + }, + { + id: "second", + attachTo: { + element: "second-step", + on: "top" + }, + text: [ + "Yuk eksplorasi hasil Tes Minat Bakat-mu dan rekomendasi Jurusan dan Karier." + ], + buttons: [ + { + classes: "btn btn-info", + text: "Kembali", + type: "back" + }, + { + classes: "btn btn-success", + text: "Saya Mengerti", + type: "cancel" + } + ], + when: { + show: () => { + console.log("show stepp"); + }, + hide: () => { + console.log("complete step"); + } + }, + showCancelLink: false, + scrollTo: true, + modalOverlayOpeningPadding: 4, + useModalOverlay: false, + canClickTarget: false + } + ] + + function TourButton() { + const tour = useContext(ShepherdTourContext); + + return ( + + ); + } + + //import { ShepherdTour, ShepherdTourContext } from 'react-shepherd' const WorkflowView = () => { + /* if (workflows.length === 0) { return (
@@ -2467,6 +2566,7 @@ const Workflows = (props) => {
); } + */ var workflowDelay = -150 - var appDelay = -75 + var appDelay = -75 + + return (
+
@@ -2895,6 +2999,11 @@ const Workflows = (props) => { const loadedCheck = isLoaded && isLoggedIn && workflowDone ? (
+ {/* + + + + */} 1366 ? 1366 : 1200, diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index 6f9b2d85..1075eb0a 100644 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -17,6 +17,7 @@ import ( "io" "io/ioutil" "log" + "net" "net/http" "os" "os/exec" @@ -624,6 +625,42 @@ func findActiveSwarmNodes() (int64, error) { */ } +// Get IP +func getLocalIP() string { + addrs, err := net.InterfaceAddrs() + if err != nil { + return "" + } + + for _, address := range addrs { + // check the address type and if it is not a loopback the display it + if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { + if ipnet.IP.To4() != nil { + return ipnet.IP.String() + } + } + } + + return "" +} + +func checkSwarmService(ctx context.Context) { + // https://docs.docker.com/engine/reference/commandline/swarm_init/ + ip := getLocalIP() + log.Printf("[DEBUG] Attempting swarm setup on %s", ip) + req := swarm.InitRequest{ + ListenAddr: fmt.Sprintf("0.0.0.0:2377", ip), + AdvertiseAddr: fmt.Sprintf("%s:2377", ip), + } + + ret, err := dockercli.SwarmInit(ctx, req) + if err != nil { + log.Printf("[WARNING] Swarm init: %s", err) + } + + log.Printf("[DEBUG] Swarm info: %s\n\n", ret) +} + // Initial loop etc func main() { log.Println("[INFO] Setting up execution environment") @@ -685,6 +722,10 @@ func main() { log.Printf("[INFO] Setting up Docker environment. Downloading worker and App SDK!") initializeImages() + if swarmConfig == "run" { + checkSwarmService(ctx) + + } //workerName := "worker" //workerVersion := "0.1.0"