Skip to content

Commit

Permalink
Merge pull request #188 from valory-xyz/fix/brew-installation
Browse files Browse the repository at this point in the history
Feat/compiled backend
  • Loading branch information
truemiller authored Jun 21, 2024
2 parents 6988fbf + 496ab15 commit 3f56adf
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 248 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: "20.11"
- name: Download binary
run: mkdir electron/bins && curl -L -o electron/bins/pearl_arm64 https://tempfileserver.staging.autonolas.tech/pearl_arm64 && chmod +x electron/bins/pearl_arm64 && curl -L -o electron/bins/pearl_x64 https://tempfileserver.staging.autonolas.tech/pearl_arm64 && chmod +x electron/bins/pearl_x64
- uses: snok/install-poetry@v1
with:
version: "1.7.1"
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ tmp/
temp/

!operate/data
dist/
electron/.next

dist/
build/

cache
leak_report

*.dist
*.build
/electron/bins/
7 changes: 7 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const main = async () => {
directories: {
output: 'dist',
},
extraResources: [
{
from: 'electron/bins',
to: 'bins',
filter: ['**/*'],
},
],
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
cscLink: process.env.CSC_LINK,
mac: {
Expand Down
37 changes: 3 additions & 34 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ const { BrewScript } = require('./scripts');
* - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26"
* - use "alpha" for alpha release, for example "0.1.0rc26-alpha"
*/
const OlasMiddlewareVersion = '0.1.0rc56';
const OlasMiddlewareVersion = '0.1.0rc59';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
const VersionFile = `${OperateDirectory}/version.txt`;
const LogFile = `${OperateDirectory}/logs.txt`;
const OperateInstallationLog = `${os.homedir()}/operate.log`;
const OperateCmd = `${os.homedir()}/.operate/venv/bin/operate`;
const Env = {
...process.env,
PATH: `${process.env.PATH}:/opt/homebrew/bin:/usr/local/bin`,
Expand Down Expand Up @@ -337,20 +336,6 @@ function removeInstallationLogFile() {

async function setupDarwin(ipcChannel) {
removeInstallationLogFile();
console.log(appendLog('Checking brew installation'));
if (!isBrewInstalled()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing brew'));
await installBrew();
}

console.log(appendLog('Checking python installation'));
if (!isPythonInstalledDarwin()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing python'));
installPythonDarwin();
}

console.log(appendLog('Creating required directories'));
await createDirectory(`${OperateDirectory}`);
await createDirectory(`${OperateDirectory}/temp`);
Expand All @@ -362,31 +347,15 @@ async function setupDarwin(ipcChannel) {
await installTendermintUnix();
}

if (!fs.existsSync(VenvDir)) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Creating virtual environment'));
createVirtualEnvUnix(VenvDir);

console.log(appendLog('Installing pearl backend'));
installOperatePackageUnix(OperateDirectory);
}

console.log(appendLog('Checking if upgrade is required'));
if (versionBumpRequired()) {
console.log(
appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`),
);
reInstallOperatePackageUnix(OperateDirectory);
writeVersion();
removeLogFile();
// reInstallOperatePackageUnix(OperateDirectory);
}

if (!fs.existsSync(`${OperateDirectory}/venv/bin/operate`)) {
reInstallOperatePackageUnix(OperateDirectory);
}

console.log(appendLog('Installing pearl CLI'));
await installOperateCli('/opt/homebrew/bin/operate');
}

// TODO: Add Tendermint installation
Expand Down Expand Up @@ -477,8 +446,8 @@ module.exports = {
startDocker,
setupUbuntu,
OperateDirectory,
OperateCmd,
Env,
appendLog,
dirs: {
VersionFile,
LogFile,
Expand Down
80 changes: 43 additions & 37 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const dotenv = require('dotenv');

const console = require('electron-log/main'); // Supports log levels and file logging
console.initialize();

const {
app,
BrowserWindow,
Expand All @@ -19,14 +22,8 @@ const http = require('http');
const AdmZip = require('adm-zip');
const { TRAY_ICONS, TRAY_ICONS_PATHS } = require('./icons');

const {
setupDarwin,
setupUbuntu,
OperateCmd,
OperateDirectory,
Env,
dirs,
} = require('./install');
const { OperateDirectory, Env, dirs } = require('./install');

const { killProcesses } = require('./processes');
const { isPortAvailable, findAvailablePort } = require('./ports');
const { PORT_RANGE, isWindows, isMac } = require('./constants');
Expand All @@ -43,6 +40,13 @@ if (!singleInstanceLock) app.quit();
const platform = os.platform();
const isDev = process.env.NODE_ENV === 'development';

const binaryPaths = {
darwin: {
arm64: 'bins/pearl_arm64',
x64: 'bins/pearl_x64',
},
};

let appConfig = {
ports: {
dev: {
Expand Down Expand Up @@ -284,16 +288,19 @@ async function launchDaemon() {
let endpoint = fs
.readFileSync(`${OperateDirectory}/operate.kill`)
.toString()
.trimLeft()
.trimRight();
.trim();

await fetch(`http://localhost:${appConfig.ports.prod.operate}/${endpoint}`);
} catch (err) {
console.log('Backend not running!');
}

const check = new Promise(function (resolve, _reject) {
operateDaemon = spawn(
OperateCmd,
path.join(
process.resourcesPath,
binaryPaths.prod[platform][process.arch.toString()],
),
[
'daemon',
`--port=${appConfig.ports.prod.operate}`,
Expand All @@ -302,13 +309,13 @@ async function launchDaemon() {
{ env: Env },
);
operateDaemonPid = operateDaemon.pid;
fs.appendFileSync(
`${OperateDirectory}/operate.pip`,
`${operateDaemon.pid}`,
{
encoding: 'utf-8',
},
);
// fs.appendFileSync(
// `${OperateDirectory}/operate.pip`,
// `${operateDaemon.pid}`,
// {
// encoding: 'utf-8',
// },
// );

operateDaemon.stderr.on('data', (data) => {
if (data.toString().includes('Uvicorn running on')) {
Expand All @@ -325,6 +332,7 @@ async function launchDaemon() {
console.log(appendLog(data.toString().trim()));
});
});

return await check;
}

Expand Down Expand Up @@ -410,23 +418,21 @@ async function launchNextAppDev() {
ipcMain.on('check', async function (event, _argument) {
// Update
try {
macUpdater.checkForUpdates().then((res) => {
if (!res) return;
if (!res.downloadPromise) return;

new Notification({
title: 'Update Available',
body: 'Downloading update...',
}).show();

res.downloadPromise.then(() => {
new Notification({
title: 'Update Downloaded',
body: 'Restarting application...',
}).show();
macUpdater.quitAndInstall();
});
});
// macUpdater.checkForUpdates().then((res) => {
// if (!res) return;
// if (!res.downloadPromise) return;
// new Notification({
// title: 'Update Available',
// body: 'Downloading update...',
// }).show();
// res.downloadPromise.then(() => {
// new Notification({
// title: 'Update Downloaded',
// body: 'Restarting application...',
// }).show();
// macUpdater.quitAndInstall();
// });
// });
} catch (e) {
console.error(e);
}
Expand All @@ -436,11 +442,11 @@ ipcMain.on('check', async function (event, _argument) {
event.sender.send('response', 'Checking installation');
if (!isDev) {
if (platform === 'darwin') {
await setupDarwin(event.sender);
//await setupDarwin(event.sender);
} else if (platform === 'win32') {
// TODO
} else {
await setupUbuntu(event.sender);
//await setupUbuntu(event.sender);
}
}

Expand Down
38 changes: 38 additions & 0 deletions operate/pearl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""File used for pyinstaller to create a single executable file."""

# pylint: disable=all
# mypy: ignore-errors
# flake8: noqa
from aea.crypto.registries.base import *
from aea.mail.base_pb2 import DESCRIPTOR
from aea_ledger_cosmos.cosmos import * # noqa
from aea_ledger_ethereum.ethereum import *
from aea_ledger_ethereum_flashbots.ethereum_flashbots import * # noqa
from google.protobuf.descriptor_pb2 import FileDescriptorProto
from multiaddr.codecs.idna import to_bytes as _
from multiaddr.codecs.uint16be import to_bytes as _

from operate.cli import main


if __name__ == "__main__":
main()
9 changes: 7 additions & 2 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(
Initialze service manager
:param path: Path to service storage.
:param keys: Keys manager.
:param master_key_path: Path to master key.
:param keys_manager: Keys manager.
:param wallet_manager: Wallet manager instance.
:param logger: logging.Logger object.
"""
self.path = path
Expand Down Expand Up @@ -141,6 +141,9 @@ def create_or_load(
:param hash: Service hash
:param rpc: RPC string
:param on_chain_user_params: On-chain user parameters
:param keys: Keys
:return: Service instance
"""
path = self.path / hash
if path.exists():
Expand Down Expand Up @@ -946,6 +949,7 @@ def deploy_service_locally(self, hash: str, force: bool = True) -> Deployment:
:param hash: Service hash
:param force: Remove previous deployment and start a new one.
:return: Deployment instance
"""
deployment = self.create_or_load(hash=hash).deployment
deployment.build(force=force)
Expand All @@ -958,6 +962,7 @@ def stop_service_locally(self, hash: str, delete: bool = False) -> Deployment:
:param hash: Service hash
:param delete: Delete local deployment.
:return: Deployment instance
"""
deployment = self.create_or_load(hash=hash).deployment
deployment.stop()
Expand Down
Loading

0 comments on commit 3f56adf

Please sign in to comment.