Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ docker run -it \
-p 5999:5999 \
-p 5866:5866 \
-v juno_skylab_test:/juno/.juno \
-v "$(pwd)/juno.config.mjs:/juno/juno.config.mjs" \
-v "$(pwd)/target/deploy:/juno/target/deploy" \
junobuild/skylab:latest
```
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ docker run -it \
-p 5999:5999 \
-p 5866:5866 \
-v juno_skylab_test:/juno/.juno \
-v "$(pwd)/juno.config.mjs:/juno/juno.config.mjs" \
-v "$(pwd)/target/deploy:/juno/target/deploy" \
junobuild/skylab:latest
```
Expand Down
2 changes: 1 addition & 1 deletion cli/.env.satellite
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MODULES="satellite"
WATCHERS="satellite, sputnik"
WATCHERS=""
2 changes: 1 addition & 1 deletion cli/.env.skylab
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MODULES="console, observatory"
WATCHERS="satellite-dynamic, sputnik"
WATCHERS=""
38 changes: 32 additions & 6 deletions cli/src/commands/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {buildContext} from '../services/context.services';
import {collectIdentities} from '../services/identity.services';
import {setController} from '../services/server/controller.services';
import {transfer} from '../services/server/ledger.services';
import {touchWatchedFile} from '../services/server/touch.services';
import {upgradeSatellite} from '../services/server/satellite.services';
import {buildSputnik} from '../services/server/sputnik.services';
import type {CliContext} from '../types/context';
import {nextArg} from '../utils/args.utils';

Expand Down Expand Up @@ -95,6 +96,8 @@ const buildServer = ({context}: {context: CliContext}): Server =>
return;
}

const consoleBuild = process.env.CLI_BUILD === 'console';

if (command === 'satellite') {
switch (subCommand) {
case 'controller':
Expand All @@ -107,6 +110,34 @@ const buildServer = ({context}: {context: CliContext}): Server =>
return;
}

if (!consoleBuild) {
switch (subCommand) {
case 'upgrade':
// We don't await the promise on purpose given the process takes some time.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
upgradeSatellite({
context,
searchParams
});
done();
return;
}
}

error404();
return;
}

if (!consoleBuild && command === 'sputnik') {
switch (subCommand) {
case 'build':
// We don't await the promise on purpose given the process takes some time.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
buildSputnik();
done();
return;
}

error404();
return;
}
Expand All @@ -125,11 +156,6 @@ const buildServer = ({context}: {context: CliContext}): Server =>
res.end(JSON.stringify(identities));
return;
}
case 'touch': {
await touchWatchedFile({searchParams});
done();
return;
}
}

error404();
Expand Down
16 changes: 0 additions & 16 deletions cli/src/configs/juno.config.ts

This file was deleted.

6 changes: 0 additions & 6 deletions cli/src/constants/dev.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export const DEV_MISSION_CONTROL_WASM_FILENAME = 'mission_control.wasm.gz';

export const DEV_METADATA = join(DEV_DEPLOY_FOLDER, 'metadata.json');

/**
* Configuration
*/

export const JUNO_CONFIG_FILENAME = 'juno.config'; // .json | .js | .cjs | .mjs | .ts

/**
* JS/TS
*/
Expand Down
39 changes: 4 additions & 35 deletions cli/src/modules/satellite/dynamic.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import {ICManagementCanister} from '@dfinity/ic-management';
import {Principal} from '@dfinity/principal';
import {fromNullable, isNullish, nonNullish, uint8ArrayToHexString} from '@dfinity/utils';
import {
junoConfigExist as junoConfigExistTools,
junoConfigFile as junoConfigFileTools
} from '@junobuild/config-loader';
import kleur from 'kleur';
import {existsSync} from 'node:fs';
import {basename} from 'node:path';
import {readJunoConfig} from '../../configs/juno.config';
import {DEV_SATELLITE, JUNO_CONFIG_FILENAME} from '../../constants/dev.constants';
import {DEV_SATELLITE} from '../../constants/dev.constants';
import type {CliContext} from '../../types/context';
import type {InitDynamicModuleResult, ModuleCanisterId} from '../../types/module';
import {SATELLITE, SatelliteModule} from './index';
Expand Down Expand Up @@ -87,37 +81,12 @@ class SatelliteDynamicModule extends SatelliteModule {
}

export const initSatelliteDynamicModule = async ({
context
context,
satelliteId
}: {
context: CliContext;
satelliteId: ModuleCanisterId;
}): Promise<InitDynamicModuleResult<SatelliteDynamicModule>> => {
if (!(await junoConfigExistTools({filename: JUNO_CONFIG_FILENAME}))) {
const err = new Error(
`ℹ️ No configuration file provided. Skipping upgrade of ${SATELLITE.name}.`
);
console.log(err.message);
return {
err
};
}

const config = await readJunoConfig();

const satelliteId = config.satellite.ids?.development;

if (isNullish(satelliteId)) {
const {configPath} = junoConfigFileTools({filename: JUNO_CONFIG_FILENAME});

const err = new Error(
`ℹ️ No ${SATELLITE.name} provided in ${basename(configPath)}. Skipping upgrade.`
);
console.log(err.message);

return {
err
};
}

const mod = new SatelliteDynamicModule({
...SATELLITE,
canisterId: satelliteId,
Expand Down
26 changes: 26 additions & 0 deletions cli/src/services/server/satellite.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {assertNonNullish} from '@dfinity/utils';
import {DEV_SATELLITE_WASM_FILENAME} from '../../constants/dev.constants';
import {initSatelliteDynamicModule} from '../../modules/satellite/dynamic';
import type {CliContext} from '../../types/context';
import type {InitDynamicModuleResult} from '../../types/module';
import {DeployWatcher} from '../../watch/_watchers/deploy.watcher';

export const upgradeSatellite = async ({
context,
searchParams
}: {
context: CliContext;
searchParams: URLSearchParams;
}) => {
const satelliteId = searchParams.get('id');

assertNonNullish(satelliteId, 'The request must provide a satellite ID.');

const satelliteDynamicWatcher = new DeployWatcher({
moduleFileName: DEV_SATELLITE_WASM_FILENAME,
initModule: async ({context}: {context: CliContext}): Promise<InitDynamicModuleResult> =>
await initSatelliteDynamicModule({context, satelliteId})
});

await satelliteDynamicWatcher.onRequest({context});
};
41 changes: 0 additions & 41 deletions cli/src/services/server/touch.services.ts

This file was deleted.

18 changes: 0 additions & 18 deletions cli/src/watch/_modules/satellite.ts

This file was deleted.

11 changes: 0 additions & 11 deletions cli/src/watch/_modules/sputnik.ts

This file was deleted.

9 changes: 9 additions & 0 deletions cli/src/watch/_watchers/_watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export abstract class Watcher {
this.#debounceExec({context});
};

onRequest = async ({context}: {context: CliContext}) => {
if (this.executing) {
this.#requestExecution = true;
return;
}

this.#debounceExec({context});
};

private readonly exec = async ({context}: {context: CliContext}) => {
this.executing = true;

Expand Down
28 changes: 0 additions & 28 deletions cli/src/watch/_watchers/build.watcher.ts

This file was deleted.

18 changes: 1 addition & 17 deletions cli/src/watch/watchers.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
import {notEmptyString} from '@dfinity/utils';
import {consoleModule} from '../modules/console';
import {observatory} from '../modules/observatory';
import {satellite} from '../modules/satellite';
import type {ModuleKey} from '../types/module';
import {consoleWatchers} from './_modules/console';
import {observatoryWatcher} from './_modules/oberservatory';
import {satelliteDynamicWatcher, satelliteWatcher} from './_modules/satellite';
import {sputnikWatcher} from './_modules/sputnik';
import type {Watcher} from './_watchers/_watcher';

interface WatcherKey {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
key: ModuleKey | `${ModuleKey}-dynamic` | 'sputnik';
key: ModuleKey;
watcher: Watcher;
}

const WATCHERS: WatcherKey[] = [
{
key: satellite.key,
watcher: satelliteWatcher
},
{
key: `${satellite.key}-dynamic`,
watcher: satelliteDynamicWatcher
},
{
key: 'sputnik',
watcher: sputnikWatcher
},
...consoleWatchers.map((watcher) => ({
key: consoleModule.key,
watcher
Expand Down