Skip to content

Commit

Permalink
Merge pull request #16 from valory-xyz/feat/packaging
Browse files Browse the repository at this point in the history
Packaging
  • Loading branch information
angrybayblade authored Feb 22, 2024
2 parents 76ebf9f + 6d11939 commit 5c3ca9a
Show file tree
Hide file tree
Showing 49 changed files with 12,493 additions and 894 deletions.
5 changes: 1 addition & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@

FORK_URL=
NODE_ENV=

# required for hardhat node in development mode
HARDHAT_GNOSIS_RPC=
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ frontend/build
# local env files
.env
.env*.local
.DS_STORE

# python
backend/__pycache__/
Expand All @@ -31,4 +32,6 @@ backend/temp/
tmp/
temp/

!backend/operate/data
!operate/data
dist/
electron/.next
1 change: 0 additions & 1 deletion backend/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions backend/__init__.py

This file was deleted.

Binary file added electron/assets/icons/robot-head-tray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 153 additions & 0 deletions electron/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Installation helpers.

const fs = require('fs');
const { spawnSync } = require("child_process");
const os = require('os');

const OperateDirectory = `${os.homedir()}/.operate`;
const OperateCmd = `${os.homedir()}/.operate/venv/bin/operate`;

function runSync(command, options) {
let process = spawnSync(command, options);
return {
error: process.error,
stdout: process.stdout?.toString(),
stderr: process.stderr?.toString(),
}
}

function isPythonInstalledDarwin() {
return runSync('/opt/homebrew/bin/python3.10', ['--version']);
}

function installPythonDarwin() {
return runSync('/opt/homebrew/bin/brew', ['install', '[email protected]'])
}

function createVirtualEnvDarwin(path) {
return runSync(
'/opt/homebrew/bin/python3.10',
[
'-m',
'venv',
path,
]
)
}

function isPythonInstalledUbuntu() {
return runSync('/usr/bin/python3.10', ['--version']);
}

function installPythonUbuntu() {
return runSync('/usr/bin/apt', ['install', 'python3.10 ', 'python3.10-dev'])
}

function createVirtualEnvUbuntu(path) {
return runSync('/usr/bin/python3.10', ['-m', 'venv', path])
}

function installOperatePackage(path) {
return runSync(
`${path}/venv/bin/python3.10`,
[
'-m',
'pip',
'install',
'git+https://github.com/valory-xyz/olas-operate-app.git@a2d203ad2d6c716a66a8d184ab77909b5ab22a85#egg=operate'
]
)
}

function installOperateAppDarwin(path) {
return new Promise((resolve, reject) => {
fs.copyFile(`${path}/venv/bin/operate`, "/opt/homebrew/bin/operate", function (error, stdout, stderr) {
resolve(!error)
})
});
}

function installOperateAppUbuntu(path) {
return new Promise((resolve, reject) => {
fs.copyFile(`${path}/venv/bin/operate`, "/usr/local/bin", function (error, stdout, stderr) {
resolve(!error)
})
});
}

function createDirectory(path) {
return new Promise((resolve, reject) => {
fs.mkdir(path, { recursive: true }, (error) => {
resolve(!error);
});
});
}

async function setupDarwin() {
let installCheck
// Python installation check
if (isPythonInstalledDarwin().error) {
installCheck = installPythonDarwin()
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}
}

// Create required directories
await createDirectory(`${OperateDirectory}`)
await createDirectory(`${OperateDirectory}/temp`)

// Create a virtual environment
installCheck = createVirtualEnvDarwin(`${OperateDirectory}/venv`)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}

// Install operate app
installCheck = installOperatePackage(OperateDirectory)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}
installCheck = installOperateAppDarwin(OperateDirectory)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}
}

async function setupUbuntu() {

// Python installation check
if (!await isPythonInstalledUbuntu()) {
console.log("Installing Python")
if (!await installPythonUbuntu()) {
throw new Error("Could not install python")
}
}

// Create required directories
await createDirectory(`${OperateDirectory}`)
await createDirectory(`${OperateDirectory}/temp`)

// Create a virtual environment
installCheck = createVirtualEnvUbuntu(`${OperateDirectory}/venv`)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}

// Install operate app
installCheck = installOperatePackage(OperateDirectory)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}
installCheck = installOperateAppUbuntu(OperateDirectory)
if (installCheck.error) {
throw new Error(`Error: ${installCheck.error}; Stdout: ${installCheck.stdout}; Stderr: ${installCheck.stderr}`)
}

}

function isInstalled() {
return fs.existsSync(OperateDirectory)
}

module.exports = { setupDarwin, setupUbuntu, isInstalled, OperateDirectory, OperateCmd }
17 changes: 0 additions & 17 deletions electron/loading.html

This file was deleted.

20 changes: 20 additions & 0 deletions electron/loading/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./loading.css" />
</head>
<body>
<span class="loader"></span>
&nbsp;&nbsp;
<div id="text" class="text">Loading</div>
</body>
<script>
const { ipcRenderer } = require("electron");
ipcRenderer.on("response", (event, arg) => {
document.getElementById("text").innerText = arg;
});
ipcRenderer.send("check", "Starting check...");
</script>
</html>
51 changes: 51 additions & 0 deletions electron/loading/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
* {
box-sizing: border-box;
margin: 0px;
padding: 0px;
height: 100%;
}

body {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.text {
font-family: monospace;
font-size: 14px;
height: fit-content;
}

.loader {
width: 18px;
height: 18px;
border-radius: 50%;
display: inline-block;
position: relative;
background: linear-gradient(0deg, white 10%, purple 100%);
box-sizing: border-box;
animation: rotation 1s linear infinite;
}

.loader::after {
content: "";
box-sizing: border-box;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 14px;
height: 14px;
border-radius: 50%;
background: white;
}
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
Loading

0 comments on commit 5c3ca9a

Please sign in to comment.