Skip to content

Commit

Permalink
feat: add deployment for workers with deals [fixes DXJ-287] (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem authored Feb 15, 2023
1 parent adcb9c2 commit a92b65b
Show file tree
Hide file tree
Showing 15 changed files with 1,580 additions and 297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ oclif.manifest.json
/fluence-lock.yaml
/hosts.yaml
/workers.yaml
/deals.yaml
src/aqua
src/services
src/ts
Expand Down
26 changes: 14 additions & 12 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ EXAMPLES
$ fluence aqua
```

_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/aqua.ts)_
_See code: [dist/commands/aqua.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/aqua.ts)_

## `fluence autocomplete [SHELL]`

Expand Down Expand Up @@ -110,7 +110,7 @@ EXAMPLES
$ fluence build
```

_See code: [dist/commands/build.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/build.ts)_
_See code: [dist/commands/build.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/build.ts)_

## `fluence deal change-app [DEAL-ADDRESS] [DEAL-NEW-APP-CID]`

Expand All @@ -125,7 +125,7 @@ ARGUMENTS
DEAL-NEW-APP-CID New app CID for the deal
FLAGS
-k, --privKey=<value> Private key with which transactions will be signed through cli
-k, --privKey=<value> !WARNING! for debug purposes only. Passing private keys through flags is unsecure
--network=<network> [default: testnet] $The network in which the transactions used by the command will be carried
out (local, testnet)
--no-input Don't interactively ask for any input from the user
Expand All @@ -140,11 +140,11 @@ Create your deal with the specified parameters

```
USAGE
$ fluence deal create --appCID <value> [--no-input] [-k <value>] [--minWorkers <value>] [--targetWorkers
<value>] [--network <value>]
$ fluence deal create --appCID <value> [--no-input] [--minWorkers <value>] [--targetWorkers <value>] [--network
<value>] [-k <value>]
FLAGS
-k, --privKey=<value> Private key with which transactions will be signed through cli
-k, --privKey=<value> !WARNING! for debug purposes only. Passing private keys through flags is unsecure
--appCID=<value> (required) CID of the application that will be deployed
--minWorkers=<value> [default: 1] Required workers to activate the deal
--network=<network> [default: testnet] $The network in which the transactions used by the command will be carried
Expand Down Expand Up @@ -284,7 +284,7 @@ EXAMPLES
$ fluence deploy
```

_See code: [dist/commands/deploy.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/deploy.ts)_
_See code: [dist/commands/deploy.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/deploy.ts)_

## `fluence help [COMMANDS]`

Expand Down Expand Up @@ -328,7 +328,7 @@ EXAMPLES
$ fluence init
```

_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/init.ts)_
_See code: [dist/commands/init.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/init.ts)_

## `fluence key default [NAME]`

Expand Down Expand Up @@ -483,7 +483,7 @@ EXAMPLES
$ fluence remove
```

_See code: [dist/commands/remove.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/remove.ts)_
_See code: [dist/commands/remove.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/remove.ts)_

## `fluence resource-owner pat create [DEAL-ADDRESS]`

Expand All @@ -497,7 +497,7 @@ ARGUMENTS
DEAL-ADDRESS Deal address
FLAGS
-k, --privKey=<value> Private key with which transactions will be signed through cli
-k, --privKey=<value> !WARNING! for debug purposes only. Passing private keys through flags is unsecure
--network=<network> [default: testnet] $The network in which the transactions used by the command will be carried
out (local, testnet)
--no-input Don't interactively ask for any input from the user
Expand Down Expand Up @@ -551,7 +551,7 @@ EXAMPLES
$ fluence run
```

_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.38/dist/commands/run.ts)_
_See code: [dist/commands/run.ts](https://github.com/fluencelabs/fluence-cli/blob/v0.2.39/dist/commands/run.ts)_

## `fluence service add [PATH | URL]`

Expand Down Expand Up @@ -648,11 +648,13 @@ Deploy workers to hosts, described in hosts.yaml
```
USAGE
$ fluence workers deploy [--no-input] [--relay <value>] [--force] [--timeout <value>] [--ttl <value>] [-k <value>]
[--aqua-logs]
[--aqua-logs] [--direct] [-k <value>]
FLAGS
-k, --key-pair-name=<name> Key pair name
-k, --privKey=<value> !WARNING! for debug purposes only. Passing private keys through flags is unsecure
--aqua-logs Enable Aqua logs
--direct Deploy workers directly to hosts (use hosts.yaml config instead of deals.yaml)
--force Force removing of previously deployed app
--no-input Don't interactively ask for any input from the user
--relay=<multiaddr> Relay node multiaddr
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
"check": "npm run build && npm run lint-fix && npm run circular",
"circular": "madge --circular --extensions ts ./",
"pre-commit": "exitzero npm run build && exitzero npm run lint-fix && cd docs/commands && oclif readme --no-aliases && git add README.md",
"clean": "shx rm -rf .fluence && shx rm -rf fluence-lock.yaml && shx rm -rf fluence.yaml && shx rm -rf src/aqua && shx rm -rf src/ts && shx rm -rf src/js",
"clean": "shx rm -rf .fluence && shx rm -rf fluence-lock.yaml && shx rm -rf fluence.yaml && shx rm -rf hosts.yaml && shx rm -rf workers.yaml && shx rm -rf deals.yaml && shx rm -rf src/aqua && shx rm -rf src/ts && shx rm -rf src/js",
"gen-config-docs": "shx rm -rf schemas && shx rm -rf docs/configs && ts-node ./src/schemas.ts && jsonschema2md -d schemas -o docs/configs -h false -f yaml -x schemas -n && ts-node ./src/schemas.ts -f",
"compile-cli-aqua": "./bin/dev.js aqua -i node_modules/@fluencelabs/installation-spell/src/aqua/cli.aqua -o src/lib/compiled-aqua/installation-spell --import node_modules",
"compile-files-aqua": "./bin/dev.js aqua -i node_modules/@fluencelabs/installation-spell/src/aqua/files.aqua -o src/lib/compiled-aqua/installation-spell --import node_modules",
"compile-config-aqua": "./bin/dev.js aqua -i node_modules/@fluencelabs/installation-spell/src/aqua/config.aqua -o src/lib/compiled-aqua/installation-spell --import node_modules",
"compile-air": "./bin/dev.js aqua --no-relay -i node_modules/@fluencelabs/installation-spell/src/aqua/spell.aqua -o src/lib/compiled-aqua/installation-spell/air --import node_modules --air"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/aqua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export default class Aqua extends Command {
"Enter path to the output directory. Will be created if it doesn't exists",
flagName: "input",
})),
js = flags.js ?? maybeFluenceConfig?.aquaOutputJSPath !== undefined,
js = flags.js ??
(flags.output === undefined
? maybeFluenceConfig?.aquaOutputJSPath !== undefined
: false),
"log-level-compiler": logLevelCompiler,
"common-js": isCommonJs,
...aquaCliOptionalFlags
Expand Down
12 changes: 3 additions & 9 deletions src/commands/deal/change-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { Args, Flags } from "@oclif/core";
import { Args } from "@oclif/core";

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { NETWORK_FLAG } from "../../lib/const.js";
import { NETWORK_FLAG, PRIV_KEY_FLAG } from "../../lib/const.js";
import { initCli } from "../../lib/lifecyle.js";
import { input } from "../../lib/prompt.js";
import {
Expand All @@ -33,13 +33,7 @@ export default class ChangeApp extends BaseCommand<typeof ChangeApp> {
static override description = "Change app id in the deal";
static override flags = {
...baseFlags,
privKey: Flags.string({
char: "k",
description:
"Private key with which transactions will be signed through cli",
required: false,
}),

...PRIV_KEY_FLAG,
...NETWORK_FLAG,
};

Expand Down
63 changes: 10 additions & 53 deletions src/commands/deal/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,38 @@
* limitations under the License.
*/

import assert from "node:assert";

import { Flags } from "@oclif/core";
import { BigNumber } from "ethers";

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { NETWORK_FLAG } from "../../lib/const.js";
import { commandObj } from "../../lib/commandObj.js";
import { NETWORK_FLAG, PRIV_KEY_FLAG } from "../../lib/const.js";
import { dealCreate } from "../../lib/dealCreate.js";
import { initCli } from "../../lib/lifecyle.js";
import {
getFactoryContract,
getSigner,
ensureChainNetwork,
} from "../../lib/provider.js";

const EVENT_TOPIC_FRAGMENT = "DealCreated";
const DEAL_LOG_ARG_NAME = "deal";

export default class Create extends BaseCommand<typeof Create> {
static override description =
"Create your deal with the specified parameters";
static override flags = {
...baseFlags,
privKey: Flags.string({
char: "k",
description:
"Private key with which transactions will be signed through cli",
required: false,
}),
appCID: Flags.string({
description: "CID of the application that will be deployed",
required: true,
}),
minWorkers: Flags.string({
minWorkers: Flags.integer({
description: "Required workers to activate the deal",
required: false,
default: "1",
default: 1,
}),
targetWorkers: Flags.string({
targetWorkers: Flags.integer({
description: "Max workers in the deal",
required: false,
default: "3",
default: 3,
}),

...NETWORK_FLAG,
...PRIV_KEY_FLAG,
};

async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(Create));

const network = await ensureChainNetwork({
maybeChainNetwork: flags.network,
});

const signer = await getSigner(network, flags.privKey);
const factory = getFactoryContract(signer, network);

const tx = await factory.createDeal(
BigNumber.from(flags.minWorkers),
BigNumber.from(flags.targetWorkers),
flags.appCID
);

const res = await tx.wait();
const eventTopic = factory.interface.getEventTopic(EVENT_TOPIC_FRAGMENT);

const log = res.logs.find(
(log: { topics: Array<string> }) => log.topics[0] === eventTopic
);

assert(log !== undefined);

const dealAddress: unknown =
factory.interface.parseLog(log).args[DEAL_LOG_ARG_NAME];

assert(typeof dealAddress === "string");
this.log(`Deal contract created: ${dealAddress}`);
const dealAddress = await dealCreate(flags);
commandObj.log(`Deal contract created: ${dealAddress}`);
}
}
11 changes: 3 additions & 8 deletions src/commands/resource-owner/pat/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import assert from "node:assert";

import { Args, Flags } from "@oclif/core";
import { Args } from "@oclif/core";

import { BaseCommand, baseFlags } from "../../../baseCommand.js";
import { NETWORK_FLAG } from "../../../lib/const.js";
import { NETWORK_FLAG, PRIV_KEY_FLAG } from "../../../lib/const.js";
import { initCli } from "../../../lib/lifecyle.js";
import { input } from "../../../lib/prompt.js";
import {
Expand All @@ -36,12 +36,7 @@ export default class CreatePAT extends BaseCommand<typeof CreatePAT> {
static override description = "Create provider access token for the deal";
static override flags = {
...baseFlags,
privKey: Flags.string({
char: "k",
description:
"Private key with which transactions will be signed through cli",
required: false,
}),
...PRIV_KEY_FLAG,
...NETWORK_FLAG,
};
static override args = {
Expand Down
Loading

0 comments on commit a92b65b

Please sign in to comment.