Skip to content

Commit

Permalink
fix: raw config to be parsed, improve local up and service new [fixes D…
Browse files Browse the repository at this point in the history
…XJ-564] (#649)

* fix: raw config to be parsed, improve local up and service new [fixes DXJ-564]

* Apply automatic changes

* fix?

* improve

* remove restart

* remove wrapper

* Apply automatic changes

* fix

* rename

* use homedir

---------

Co-authored-by: shamsartem <[email protected]>
  • Loading branch information
shamsartem and shamsartem authored Dec 13, 2023
1 parent 97a0b9a commit ca308df
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 162 deletions.
21 changes: 0 additions & 21 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* [`fluence local init`](#fluence-local-init)
* [`fluence local logs`](#fluence-local-logs)
* [`fluence local ps`](#fluence-local-ps)
* [`fluence local restart`](#fluence-local-restart)
* [`fluence local up`](#fluence-local-up)
* [`fluence module add [PATH | URL]`](#fluence-module-add-path--url)
* [`fluence module new [NAME]`](#fluence-module-new-name)
Expand Down Expand Up @@ -720,26 +719,6 @@ EXAMPLES

_See code: [src/commands/local/ps.ts](https://github.com/fluencelabs/cli/blob/v0.13.0/src/commands/local/ps.ts)_

## `fluence local restart`

Restart docker-compose.yaml using docker compose

```
USAGE
$ fluence local restart [--no-input]
FLAGS
--no-input Don't interactively ask for any input from the user
DESCRIPTION
Restart docker-compose.yaml using docker compose
EXAMPLES
$ fluence local restart
```

_See code: [src/commands/local/restart.ts](https://github.com/fluencelabs/cli/blob/v0.13.0/src/commands/local/restart.ts)_

## `fluence local up`

Run docker-compose.yaml using docker compose
Expand Down
4 changes: 2 additions & 2 deletions docs/configs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Configuration to pass to the nox compute peer. Config.toml files are generated f
|------------------|---------------------------|----------|-------------------------------------------------------------------------------------------------------------------|
| `aquavmPoolSize` | number | No | Number of aquavm instances to run. Default: 2 |
| `httpPort` | number | No | Both host and container HTTP port to use. Default: for each nox a unique port is assigned starting from 18080 |
| `rawConfig` | string | No | Raw TOML config string to append to the generated config. Default: empty string |
| `rawConfig` | string | No | Raw TOML config string to parse and merge with the rest of the config. Has the highest priority |
| `systemServices` | [object](#systemservices) | No | System services to run by default. aquaIpfs and decider are enabled by default |
| `tcpPort` | number | No | Both host and container TCP port to use. Default: for each nox a unique port is assigned starting from 7771 |
| `websocketPort` | number | No | Both host and container WebSocket port to use. Default: for each nox a unique port is assigned starting from 9991 |
Expand Down Expand Up @@ -97,7 +97,7 @@ Configuration to pass to the nox compute peer. Config.toml files are generated f
|------------------|---------------------------|----------|-------------------------------------------------------------------------------------------------------------------|
| `aquavmPoolSize` | number | No | Number of aquavm instances to run. Default: 2 |
| `httpPort` | number | No | Both host and container HTTP port to use. Default: for each nox a unique port is assigned starting from 18080 |
| `rawConfig` | string | No | Raw TOML config string to append to the generated config. Default: empty string |
| `rawConfig` | string | No | Raw TOML config string to parse and merge with the rest of the config. Has the highest priority |
| `systemServices` | [object](#systemservices) | No | System services to run by default. aquaIpfs and decider are enabled by default |
| `tcpPort` | number | No | Both host and container TCP port to use. Default: for each nox a unique port is assigned starting from 7771 |
| `websocketPort` | number | No | Both host and container WebSocket port to use. Default: for each nox a unique port is assigned starting from 9991 |
Expand Down
1 change: 0 additions & 1 deletion src/commands/local/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default class Init extends BaseCommand<typeof Init> {
}

const dockerCompose = await initNewReadonlyDockerComposeConfig({
env: "local",
noxes: flags.noxes,
});

Expand Down
49 changes: 0 additions & 49 deletions src/commands/local/restart.ts

This file was deleted.

32 changes: 24 additions & 8 deletions src/commands/local/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,33 @@ export default class Up extends BaseCommand<typeof Up> {
const { flags } = await initCli(this, await this.parse(Up));

const dockerComposeConfig = await initNewReadonlyDockerComposeConfig({
env: "local",
noxes: flags.noxes,
});

await dockerCompose({
args: ["up", "-d"],
printOutput: true,
options: {
cwd: dockerComposeConfig.$getDirPath(),
},
});
try {
const res = await dockerCompose({
args: ["restart"],
printOutput: true,
options: {
cwd: dockerComposeConfig.$getDirPath(),
},
});

if (res.trim() === "") {
throw new Error("docker-compose restart failed");
}
} catch {
await dockerCompose({
args: ["up", "-d"],
flags: {
"quiet-pull": true,
},
printOutput: true,
options: {
cwd: dockerComposeConfig.$getDirPath(),
},
});
}

const env = "local";
const privKey = flags["priv-key"] ?? LOCAL_NET_DEFAULT_WALLET_KEY;
Expand Down
1 change: 1 addition & 0 deletions src/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare global {
[DEBUG_COUNTLY]: "true" | "false";
[FLUENCE_USER_DIR]?: string;
[CI]: "true" | "false";
PATH: string;
}
}
}
86 changes: 41 additions & 45 deletions src/lib/addService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ export const addService = async ({
);
}

await resolveSingleServiceModuleConfigsAndBuild(
serviceConfig,
fluenceConfig,
marineCli,
marineBuildArgs,
);

const facadeModuleConfig = await initReadonlyModuleConfig(
serviceConfig.modules[FACADE_MODULE_NAME].get,
serviceConfig.$getDirPath(),
Expand All @@ -122,14 +115,6 @@ export const addService = async ({
"Unreachable. Facade module is always present in service config",
);

await updateAquaServiceInterfaceFile(
{
[serviceName]: getModuleWasmPath(facadeModuleConfig),
},
fluenceConfig.services,
marineCli,
);

await fluenceConfig.$commit();

if (interactive) {
Expand All @@ -141,41 +126,52 @@ export const addService = async ({
}

if (
!(
isInteractive &&
fluenceConfig.deals !== undefined &&
DEFAULT_DEAL_NAME in fluenceConfig.deals &&
!(fluenceConfig.deals[DEFAULT_DEAL_NAME].services ?? []).includes(
serviceName,
) &&
(interactive
? await confirm({
message: `Do you want to add service ${color.yellow(
serviceName,
)} to a default deal ${color.yellow(DEFAULT_DEAL_NAME)}`,
})
: true)
)
isInteractive &&
fluenceConfig.deals !== undefined &&
DEFAULT_DEAL_NAME in fluenceConfig.deals &&
!(fluenceConfig.deals[DEFAULT_DEAL_NAME].services ?? []).includes(
serviceName,
) &&
(interactive
? await confirm({
message: `Do you want to add service ${color.yellow(
serviceName,
)} to a default deal ${color.yellow(DEFAULT_DEAL_NAME)}`,
})
: true)
) {
return serviceName;
}
const defaultDeal = fluenceConfig.deals[DEFAULT_DEAL_NAME];

const defaultDeal = fluenceConfig.deals[DEFAULT_DEAL_NAME];
fluenceConfig.deals[DEFAULT_DEAL_NAME] = {
...defaultDeal,
services: [...(defaultDeal.services ?? []), serviceName],
};

fluenceConfig.deals[DEFAULT_DEAL_NAME] = {
...defaultDeal,
services: [...(defaultDeal.services ?? []), serviceName],
};
await fluenceConfig.$commit();

await fluenceConfig.$commit();

if (interactive) {
commandObj.log(
`Added ${color.yellow(serviceName)} to ${color.yellow(
DEFAULT_DEAL_NAME,
)}`,
);
if (interactive) {
commandObj.log(
`Added ${color.yellow(serviceName)} to ${color.yellow(
DEFAULT_DEAL_NAME,
)}`,
);
}
}

await resolveSingleServiceModuleConfigsAndBuild(
serviceConfig,
fluenceConfig,
marineCli,
marineBuildArgs,
);

await updateAquaServiceInterfaceFile(
{
[serviceName]: getModuleWasmPath(facadeModuleConfig),
},
fluenceConfig.services,
marineCli,
);

return serviceName;
};
8 changes: 6 additions & 2 deletions src/lib/configs/project/dockerCompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,13 @@ export async function initNewDockerComposeConfig(args: ProviderConfigArgs) {
}

export async function initNewReadonlyDockerComposeConfig(
args: ProviderConfigArgs,
args: Omit<ProviderConfigArgs, "env">,
) {
const providerConfig = await initNewReadonlyProviderConfig(args);
const providerConfig = await initNewReadonlyProviderConfig({
...args,
env: "local",
});

await ensureConfigToml(providerConfig);
return getReadonlyConfigInitFunction(
initConfigOptions,
Expand Down
Loading

0 comments on commit ca308df

Please sign in to comment.