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

Host runtime for agent deployments #151

Merged
merged 35 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ee106fb
feat: add support for runing agent deployments on host machines
angrybayblade May 29, 2024
9e49daa
fix: linters
angrybayblade May 29, 2024
f4a3e8f
chore: gitleaks fix
angrybayblade May 29, 2024
99c0f13
fix: security warnings
angrybayblade May 29, 2024
f54783c
chore: gitleaks ignore
angrybayblade May 29, 2024
a3a7e65
feat: add support for installing tendermint binary
angrybayblade May 29, 2024
4a786b9
Merge branch 'main' into feat/host-runtime
angrybayblade May 29, 2024
4fe78d7
feat: bump to v0.1.0-rc27
angrybayblade May 29, 2024
881ee11
feat: update releaseType to 'draft' in publishOptions
truemiller May 29, 2024
2ed9346
turn off OTA for draft, for now
truemiller May 29, 2024
9ecce1b
Merge branch 'main' into feat/host-runtime
angrybayblade May 30, 2024
91ec074
chore: formatters
angrybayblade May 30, 2024
9e28707
chore: remove docker requirements from the app
angrybayblade May 30, 2024
2362ee2
feat: bump to v0.1.0-rc28
angrybayblade May 30, 2024
1a820f4
fix: remove hardcoded path
0xArdi May 30, 2024
43ecf44
Merge remote-tracking branch 'origin/feat/host-runtime' into feat/hos…
0xArdi May 30, 2024
15868c3
feat: bump v0.1.0-rc29
angrybayblade May 30, 2024
c352ebe
fix: add tendermint installation for ubuntu
angrybayblade May 31, 2024
d02b769
fix: handle deployment errors
angrybayblade May 31, 2024
0ffd75e
chore: formatters
angrybayblade May 31, 2024
f57b891
fix: add more logging when installing tendermint
angrybayblade May 31, 2024
a34b1f1
fix: remove log method
angrybayblade May 31, 2024
652dafc
fix: run aea init before fetching agent
angrybayblade May 31, 2024
fc6b3ca
fix: mech pricing patch
angrybayblade May 31, 2024
291edf7
fix: agent and tendermint process kill logic
angrybayblade May 31, 2024
2337930
fix: mach price patch
angrybayblade May 31, 2024
af837cc
feat: bump to v0.1.0-r30
angrybayblade May 31, 2024
7b2e72f
fix: process termination
angrybayblade May 31, 2024
09bd69a
fix: benchmark dir path
angrybayblade May 31, 2024
4c1e96b
feat: bump to v0.1.0-rc31
angrybayblade May 31, 2024
42e0a4f
fix: tendermint installation step
angrybayblade May 31, 2024
011c0a7
feat: bump release
angrybayblade May 31, 2024
1f512c5
fix: service ID patch
angrybayblade May 31, 2024
f03f7ee
feat: bump to v0.1.0-rc33
angrybayblade May 31, 2024
2793e61
final bump to rc34 before merge
truemiller May 31, 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
541 changes: 541 additions & 0 deletions .gitleaks.toml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ daf41a143aa8c483db584ba1e7222e8eafec1d3b:backend/controller.py:generic-api-key:2
af77e930289cbc87987567bff0efc25936484df2:backend/controller.py:generic-api-key:354b04972639d66053109596d3b73a1d91688964ebb:electron/constants/publishOptions.js:github-fine-grained-pat:3
b04972639d66053109596d3b73a1d91688964ebb:electron/constants/publishOptions.js:github-fine-grained-pat:3
af77e930289cbc87987567bff0efc25936484df2:backend/controller.py:generic-api-key:354
e7de9ce0b902ed6d68f8c5b033d044f39b08f5a1:operate/data/contracts/service_staking_token/contract.yaml:generic-api-key:10
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:405
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:406
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:454
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:455
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ E0611: no-name-in-module
R0903: Too few public methods

[IMPORTS]
ignored-modules=os,io
ignored-modules=os,io,psutil

[DESIGN]
# min-public-methods=1
Expand Down
2 changes: 1 addition & 1 deletion electron/constants/publishOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const publishOptions = {
releaseType: 'draft',
token: process.env.GH_TOKEN,
private: false,
publishAutoUpdate: true,
publishAutoUpdate: false,
};

module.exports = { publishOptions };
94 changes: 75 additions & 19 deletions electron/install.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Installation helpers.

const https = require('https');
const path = require('path');
const fs = require('fs');
const os = require('os');
const sudo = require('sudo-prompt');
const process = require('process');
const { spawnSync } = require('child_process');
const axios = require("axios")

const Docker = require('dockerode');
const { spawnSync } = require('child_process');

const Version = '0.1.0rc26';
const Version = '0.1.0rc33';
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`;
Expand All @@ -22,6 +27,20 @@ const SudoOptions = {
name: 'Pearl',
env: Env,
};
const TendermintUrls = {
darwin: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_arm64.tar.gz",
},
linux: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_arm64.tar.gz",
},
win32: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_arm64.tar.gz"
}
}

function getBinPath(command) {
return spawnSync('/usr/bin/which', [command], { env: Env })
Expand Down Expand Up @@ -104,6 +123,46 @@ function installBrew() {
]);
}

function isTendermintInstalledUnix() {
return Boolean(getBinPath('tendermint'));
}

async function downloadFile(url, dest) {
const writer = fs.createWriteStream(dest);
try {
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
});
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
} catch (err) {
fs.unlink(dest, () => { }); // Delete the file if there is an error
console.error('Error downloading the file:', err.message);
}
}

async function installTendermintUnix() {
const cwd = process.cwd()
process.chdir(TempDir)

console.log(appendLog(`Installing tendermint for ${os.platform()}-${process.arch}`))
const url = TendermintUrls[os.platform()][process.arch]

console.log(appendLog(`Downloading ${url}, might take a while...`))
await downloadFile(url, `${TempDir}/tendermint.tar.gz`)

console.log(appendLog(`Installing tendermint binary`))
await runCmdUnix("tar", ["-xvf", "tendermint.tar.gz"])
await runSudoUnix("install", "tendermint /usr/local/bin")
process.chdir(cwd)
}


function isDockerInstalledDarwin() {
return Boolean(getBinPath('docker'));
}
Expand Down Expand Up @@ -212,7 +271,7 @@ function versionBumpRequired() {
}

function removeLogFile() {
if (fs.existsSync()) {
if (fs.existsSync(LogFile)) {
fs.rmSync(LogFile);
}
}
Expand All @@ -236,13 +295,6 @@ async function setupDarwin(ipcChannel) {
installBrew();
}

console.log(appendLog('Checking docker installation'));
if (!isDockerInstalledDarwin()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing docker'));
installDockerDarwin();
}

console.log(appendLog('Checking python installation'));
if (!isPythonInstalledDarwin()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
Expand All @@ -254,6 +306,13 @@ async function setupDarwin(ipcChannel) {
await createDirectory(`${OperateDirectory}`);
await createDirectory(`${OperateDirectory}/temp`);

console.log(appendLog('Checking tendermint installation'));
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
}

if (!fs.existsSync(VenvDir)) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Creating virtual environment'));
Expand All @@ -279,14 +338,9 @@ async function setupDarwin(ipcChannel) {
await installOperateCli('/opt/homebrew/bin/operate');
}

// TODO: Add Tendermint installation
async function setupUbuntu(ipcChannel) {
removeInstallationLogFile();
console.log(appendLog('Checking docker installation'));
if (!isDockerInstalledUbuntu()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing docker'));
await installDockerUbuntu();
}

console.log(appendLog('Checking python installation'));
if (!isPythonInstalledUbuntu()) {
Expand All @@ -306,9 +360,11 @@ async function setupUbuntu(ipcChannel) {
await createDirectory(`${OperateDirectory}`);
await createDirectory(`${OperateDirectory}/temp`);

if (versionBumpRequired()) {
// removePreviousInstallation();
writeVersion();
console.log(appendLog('Checking tendermint installation'));
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
}

if (!fs.existsSync(VenvDir)) {
Expand Down
3 changes: 0 additions & 3 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
setupUbuntu,
OperateCmd,
OperateDirectory,
startDocker,
Env,
} = require('./install');
const { killProcesses } = require('./processes');
Expand Down Expand Up @@ -438,8 +437,6 @@ ipcMain.on('check', async function (event, _argument) {
}
}

startDocker(event.sender);

if (isDev) {
event.sender.send(
'response',
Expand Down
28 changes: 1 addition & 27 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
from pathlib import Path

from aea.helpers.logging import setup_logger
from autonomy.constants import (
AUTONOMY_IMAGE_NAME,
AUTONOMY_IMAGE_VERSION,
TENDERMINT_IMAGE_NAME,
TENDERMINT_IMAGE_VERSION,
)
from autonomy.deploy.generators.docker_compose.base import get_docker_client
from clea import group, params, run
from compose.project import ProjectError
from docker.errors import APIError
Expand Down Expand Up @@ -159,23 +152,6 @@ def create_app( # pylint: disable=too-many-locals, unused-argument, too-many-st
shutdown_endpoint
)

def pull_latest_images() -> None:
"""Pull latest docker images."""
logger.info("Pulling latest images")
client = get_docker_client()

logger.info(f"Pulling {AUTONOMY_IMAGE_NAME}:{AUTONOMY_IMAGE_VERSION}")
client.images.pull(
repository=AUTONOMY_IMAGE_NAME,
tag=AUTONOMY_IMAGE_VERSION,
)

logger.info(f"Pulling {TENDERMINT_IMAGE_NAME}:{TENDERMINT_IMAGE_VERSION}")
client.images.pull(
repository=TENDERMINT_IMAGE_NAME,
tag=TENDERMINT_IMAGE_VERSION,
)

def schedule_funding_job(
service: str,
from_safe: bool = True,
Expand Down Expand Up @@ -203,9 +179,7 @@ def cancel_funding_job(service: str) -> None:
if not status:
logger.info(f"Funding job cancellation for {service} failed")

app = FastAPI(
on_startup=[pull_latest_images],
)
app = FastAPI()

app.add_middleware(
CORSMiddleware,
Expand Down
10 changes: 5 additions & 5 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,too
if service.chain_data.on_chain_state == OnChainState.MINTED:
cost_of_bond = user_params.cost_of_bond
if user_params.use_staking:
token_utility = "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8"
olas_token = "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f"
token_utility = "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8" # nosec
olas_token = "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f" # nosec
self.logger.info(
f"Approving OLAS as bonding token from {wallet.safe} to {token_utility}"
)
Expand Down Expand Up @@ -451,8 +451,8 @@ def deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,too
if service.chain_data.on_chain_state == OnChainState.ACTIVATED:
cost_of_bond = user_params.cost_of_bond
if user_params.use_staking:
token_utility = "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8"
olas_token = "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f"
token_utility = "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8" # nosec
olas_token = "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f" # nosec
self.logger.info(
f"Approving OLAS as bonding token from {wallet.safe} to {token_utility}"
)
Expand Down Expand Up @@ -865,7 +865,7 @@ def deploy_service_locally(self, hash: str, force: bool = True) -> Deployment:
deployment.start()
return deployment

def stop_service_locally(self, hash: str, delete: bool) -> Deployment:
def stop_service_locally(self, hash: str, delete: bool = False) -> Deployment:
"""
Stop service locally

Expand Down
Loading
Loading