Skip to content

Commit

Permalink
Changes to bring back fileserver (#106)
Browse files Browse the repository at this point in the history
* Changes to bring back fileserver

* Bumped version to 0.3.3
  • Loading branch information
hanzlamateen authored Jun 22, 2023
1 parent 0238061 commit b32ff55
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 5 deletions.
39 changes: 39 additions & 0 deletions assets/scripts/configure-file-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

#===========
# Parameters
#===========

while getopts f: flag; do
case "${flag}" in
f) ENGINE_FOLDER=${OPTARG} ;;
*)
echo "Invalid arguments passed" >&2
exit 1
;;
esac
done

if [[ -z $ENGINE_FOLDER ]]; then
echo "Missing arguments"
exit 1
fi

#=========================
# Verify Local File Server
#=========================

if lsof -Pi :8642 -sTCP:LISTEN -t >/dev/null; then
echo "file server is configured"
lsof -Pi :8642 -sTCP:LISTEN
else
echo "file server is not configured"

cd "$ENGINE_FOLDER"/packages/server

npm run serve-local-files
fi

exit 0
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "etherealengine-control-center",
"version": "0.3.2",
"version": "0.3.3",
"description": "A desktop app for managing Ethereal Engine cluster.",
"license": "MIT",
"author": {
Expand Down
1 change: 1 addition & 0 deletions src/constants/Channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Channels = {
PushBranch: 'PushBranch'
},
Engine: {
StartFileServer: 'StartFileServer',
EnsureAdminAccess: 'EnsureAdminAccess',
EnsureAdminAccessError: 'EnsureAdminAccessError',
EnsureAdminAccessResponse: 'EnsureAdminAccessResponse'
Expand Down
15 changes: 14 additions & 1 deletion src/main/Clusters/MicroK8s/MicroK8s.appstatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const MicroK8sAppsStatus = (sudoPassword?: string): AppModel[] => {
getAppModel('docker', 'Docker', 'docker --version;'),
getAppModel('dockercompose', 'Docker Compose', 'docker-compose --version;'),
getAppModel('mysql', 'MySql', 'docker top etherealengine_minikube_db;'),
getAppModel('minio', 'MinIO', 'docker top etherealengine_minio_s3;'),
getAppModel('kubectl', 'kubectl', 'kubectl version --client --output=yaml;'),
getAppModel('helm', 'Helm', 'helm version;'),
getAppModel(
Expand All @@ -61,6 +60,20 @@ export const MicroK8sAppsStatus = (sudoPassword?: string): AppModel[] => {
),
getAppModel('redis', 'Redis', microk8sDependantScript(`helm status local-redis;`, microk8sPrefix)),
getAppModel('agones', 'Agones', microk8sDependantScript(`helm status agones;`, microk8sPrefix)),
getAppModel(
'fileserver',
'Local File Server',
`
if lsof -Pi :8642 -sTCP:LISTEN -t >/dev/null ; then
echo 'File server configured:';
lsof -Pi :8642 -sTCP:LISTEN;
${type !== 'Windows_NT' ? 'exit 0;' : ''}
else
echo 'File server not configured' >&2;
${type !== 'Windows_NT' ? 'exit 1;' : ''}
fi
`
),
getAppModel(
'hostfile',
'Hostfile',
Expand Down
3 changes: 3 additions & 0 deletions src/main/Clusters/MicroK8s/MicroK8s.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ClusterModel } from '../../../models/Cluster'
import { LogModel } from '../../../models/Log'
import Utilities from '../../handlers/Utilities/Utilities.class'
import { executeWebViewJS } from '../../managers/BrowserManager'
import { startFileServer } from '../../managers/FileServerManager'
import { assetsPath, ensureConfigsFolder, ensureWindowsToWSLPath, scriptsPath } from '../../managers/PathManager'
import { execStream, execStreamScriptFile } from '../../managers/ShellManager'
import { ensureConfigs } from '../../managers/YamlManager'
Expand Down Expand Up @@ -156,6 +157,8 @@ class MicroK8s {
if (code !== 0) {
throw `Failed with error code ${code}.`
}

await startFileServer(window, cluster)
} catch (err) {
log.error('Error in configureCluster MicroK8s.', err)
window.webContents.send(Channels.Utilities.Log, cluster.id, {
Expand Down
15 changes: 14 additions & 1 deletion src/main/Clusters/Minikube/Minikube.appstatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const MinikubeAppsStatus: AppModel[] = [
getAppModel('docker', 'Docker', 'docker --version;'),
getAppModel('dockercompose', 'Docker Compose', 'docker-compose --version;'),
getAppModel('mysql', 'MySql', 'docker top etherealengine_minikube_db;'),
getAppModel('minio', 'MinIO', 'docker top etherealengine_minio_s3;'),
getAppModel('virtualbox', 'VirtualBox', 'vboxmanage --version;'),
getAppModel('kubectl', 'kubectl', 'kubectl version --client --output=yaml;'),
getAppModel('helm', 'Helm', 'helm version;'),
Expand All @@ -35,6 +34,20 @@ export const MinikubeAppsStatus: AppModel[] = [
),
getAppModel('redis', 'Redis', minikubeDependantScript('helm status local-redis;')),
getAppModel('agones', 'Agones', minikubeDependantScript('helm status agones;')),
getAppModel(
'fileserver',
'Local File Server',
`
if lsof -Pi :8642 -sTCP:LISTEN -t >/dev/null ; then
echo 'File server configured:'
lsof -Pi :8642 -sTCP:LISTEN
exit 0;
else
echo 'File server not configured' >&2;
exit 1;
fi
`
),
getAppModel(
'hostfile',
'Hostfile',
Expand Down
3 changes: 3 additions & 0 deletions src/main/Clusters/Minikube/Minikube.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Storage from '../../../constants/Storage'
import { DeploymentAppModel } from '../../../models/AppStatus'
import { ClusterModel } from '../../../models/Cluster'
import { LogModel } from '../../../models/Log'
import { startFileServer } from '../../managers/FileServerManager'
import { assetsPath, ensureConfigsFolder, isValidUrl, scriptsPath } from '../../managers/PathManager'
import { execStream, execStreamScriptFile } from '../../managers/ShellManager'
import { ensureConfigs } from '../../managers/YamlManager'
Expand Down Expand Up @@ -111,6 +112,8 @@ class Minikube {
if (code !== 0) {
throw `Failed with error code ${code}.`
}

await startFileServer(window, cluster)
} catch (err) {
log.error('Error in configureCluster Minikube.', err)
window.webContents.send(Channels.Utilities.Log, cluster.id, {
Expand Down
13 changes: 13 additions & 0 deletions src/main/handlers/Engine/Engine.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Storage from '../../../constants/Storage'
import { ClusterModel } from '../../../models/Cluster'
import { LogModel } from '../../../models/Log'
import { executeJS } from '../../managers/BrowserManager'
import { startFileServer } from '../../managers/FileServerManager'
import { exec } from '../../managers/ShellManager'

class Engine {
Expand Down Expand Up @@ -118,6 +119,18 @@ class Engine {
)
}
}

static startFileServer = async (parentWindow: BrowserWindow, cluster: ClusterModel) => {
try {
await startFileServer(parentWindow, cluster)
} catch (err) {
parentWindow.webContents.send(Channels.Utilities.Log, cluster.id, {
category: 'file server',
message: JSON.stringify(err)
} as LogModel)
throw err
}
}
}

export default Engine
3 changes: 3 additions & 0 deletions src/main/handlers/Engine/Engine.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class EngineHandler implements IBaseHandler {
configure = (window: BrowserWindow) => {
ipcMain.handle(Channels.Engine.EnsureAdminAccess, async (_event: IpcMainInvokeEvent, cluster: ClusterModel) => {
await Engine.ensureAdminAccess(window, cluster)
}),
ipcMain.handle(Channels.Engine.StartFileServer, async (_event: IpcMainInvokeEvent, cluster: ClusterModel) => {
await Engine.startFileServer(window, cluster)
})
}
}
Expand Down
56 changes: 56 additions & 0 deletions src/main/managers/FileServerManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { app, BrowserWindow } from 'electron'
import path from 'path'
import { kill } from 'ps-node'

import Channels from '../../constants/Channels'
import Storage from '../../constants/Storage'
import { ClusterModel } from '../../models/Cluster'
import { LogModel } from '../../models/Log'
import { scriptsPath } from './PathManager'
import { execStreamScriptFile, getProcessList } from './ShellManager'

export const startFileServer = async (window: BrowserWindow, cluster: ClusterModel) => {
const existingServer = await getProcessList('http-server')
if (existingServer.length > 0) {
window.webContents.send(Channels.Utilities.Log, cluster.id, {
category: 'file server',
message: `File server already running. http-server count: ${existingServer.length}`
} as LogModel)
return
}

// Below block of code is to ensure file server is stopped when app is closed.
app.on('before-quit', async (e) => {
try {
e.preventDefault()

const existingServers = await getProcessList('http-server')
existingServers.forEach((httpProcess) => {
kill(httpProcess.pid)
})
} catch {}

app.quit()
process.exit()
})

const scriptsFolder = scriptsPath()
const fileServerScript = path.join(scriptsFolder, 'configure-file-server.sh')

const onFileServerStd = (data: any) => {
try {
window.webContents.send(Channels.Utilities.Log, cluster.id, {
category: 'file server',
message: data
} as LogModel)
} catch {}
}

execStreamScriptFile(
fileServerScript,
[`-f "${cluster.configs[Storage.ENGINE_PATH]}"`],
onFileServerStd,
onFileServerStd
)
}

12 changes: 10 additions & 2 deletions src/renderer/components/StatusView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { delay } from 'common/UtilitiesManager'
import Channels from 'constants/Channels'
import Storage from 'constants/Storage'
import { AppModel, AppStatus } from 'models/AppStatus'
Expand Down Expand Up @@ -143,7 +144,7 @@ export const StatusViewItem = ({ status, titleVariant, verticalAlignTop, titleSx

{status.detail && <InfoTooltip sx={titleSx} message={status.detail} />}

{status.status === AppStatus.NotConfigured && (status.id === 'mysql' || status.id === 'minio') && (
{status.status === AppStatus.NotConfigured && (status.id === 'mysql' || status.id === 'fileserver') && (
<>
{isFixing && <CircularProgress size={20} sx={{ ml: 2 }} />}
{isFixing === false && (
Expand Down Expand Up @@ -174,7 +175,7 @@ const onFix = async (appStatus: AppModel, setFixing: React.Dispatch<React.SetSta

const clonedCluster = cloneCluster(selectedCluster)

if (appStatus.id === 'mysql' || appStatus.id === 'minio') {
if (appStatus.id === 'mysql') {
await processOnFix(appStatus, clonedCluster, async () => {
const command = `cd '${clonedCluster.configs[Storage.ENGINE_PATH]}' && npm run dev-docker`

Expand All @@ -187,6 +188,13 @@ const onFix = async (appStatus: AppModel, setFixing: React.Dispatch<React.SetSta
throw output.error
}
})
} else if (appStatus.id === 'fileserver') {
await processOnFix(appStatus, clonedCluster, async () => {
await window.electronAPI.invoke(Channels.Engine.StartFileServer, clonedCluster)

// Delay to wait for fileserver to start
await delay(4000)
})
}

setFixing(false)
Expand Down

0 comments on commit b32ff55

Please sign in to comment.