Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/compiled backend #188

Merged
merged 34 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3cff6e4
feat: entrypoint for pearl backend
angrybayblade Jun 7, 2024
6259117
feat: add specs
0xArdi Jun 14, 2024
55ac463
chore: operate path
0xArdi Jun 14, 2024
e01ce95
fix: cwd
0xArdi Jun 14, 2024
ffe2c20
Merge branch 'refs/heads/main' into feat/compiled-backend
0xArdi Jun 17, 2024
2f7b372
feat: single binary
0xArdi Jun 17, 2024
39be1ad
feat: use dist binary
0xArdi Jun 17, 2024
48dfbb4
temp: add binary
0xArdi Jun 18, 2024
da18e0c
feat: download pearl on the fly
0xArdi Jun 18, 2024
52b3548
release: rc48
0xArdi Jun 18, 2024
2334b9b
fix: add mkdir
0xArdi Jun 18, 2024
f318855
release: rc49
0xArdi Jun 18, 2024
abe7912
Merge branch 'refs/heads/main' into feat/compiled-backend
0xArdi Jun 18, 2024
a7789af
release: rc51
0xArdi Jun 18, 2024
17fce78
fix: add setup
0xArdi Jun 18, 2024
971797e
fix: skip bumping
0xArdi Jun 18, 2024
82a16d6
release: rc52
0xArdi Jun 18, 2024
f2c8f46
fix: version bump
0xArdi Jun 19, 2024
a98f657
release: rc53
0xArdi Jun 19, 2024
62132d8
chore: more logs
0xArdi Jun 19, 2024
1d8ab23
chore: more logs
0xArdi Jun 19, 2024
bb03cf9
chore: add extra files
0xArdi Jun 19, 2024
1a17645
release: rc55
0xArdi Jun 20, 2024
ef391a1
feat: add x64
0xArdi Jun 20, 2024
7f1a7a9
release: rc57
0xArdi Jun 20, 2024
de245b2
Merge branch 'refs/heads/main' into feat/compiled-backend
0xArdi Jun 21, 2024
6df3fee
chore: poetry.lock
0xArdi Jun 21, 2024
8cb551d
chore: lint
0xArdi Jun 21, 2024
a0b6882
chore: lint
0xArdi Jun 21, 2024
2d6f4f1
Merge pull request #174 from valory-xyz/feat/compiled-backend
0xArdi Jun 21, 2024
d8f0ce6
release: rc58
0xArdi Jun 21, 2024
322efa2
Merge pull request #189 from valory-xyz/feat/compiled-backend
0xArdi Jun 21, 2024
0c45fb5
chore: Remove unused code and update binary paths
truemiller Jun 21, 2024
496ab15
chore: Update OlasMiddlewareVersion to '0.1.0rc59' in install.js, pac…
truemiller Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading