Skip to content
Merged
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
40 changes: 26 additions & 14 deletions packages/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ References:

| Constant | Type |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `EmulatorConfigSchema` | `ZodUnion<readonly [ZodObject<{ runner: ZodOptional<ZodObject<{ type: ZodEnum<{ docker: "docker"; podman: "podman"; }>; image: ZodOptional<ZodString>; name: ZodOptional<ZodString>; volume: ZodOptional<...>; target: ZodOptional<...>; platform: ZodOptional<...>; }, $strict>>; network: ZodOptional<...>; skylab: ZodObjec...` |
| `EmulatorConfigSchema` | `ZodUnion<readonly [ZodObject<{ runner: ZodOptional<ZodObject<{ type: ZodEnum<{ docker: "docker"; podman: "podman"; }>; image: ZodOptional<ZodString>; name: ZodOptional<ZodString>; volume: ZodOptional<...>; target: ZodOptional<...>; platform: ZodOptional<...>; extraHosts: ZodOptional<...>; }, $strict>>; network: ZodO...` |

References:

- EmulatorConfig

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L249)
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L288)

#### :gear: ModuleLogVisibilitySchema

Expand Down Expand Up @@ -530,16 +530,17 @@ Configuration for the Satellite emulator.

Shared options for all runner variants.

| Property | Type | Description |
| ---------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `type` | `"docker" or "podman"` | The containerization tool to run the emulator. |
| `image` | `string or undefined` | Image reference. default: depends on emulator type, e.g. "junobuild/skylab:latest" |
| `name` | `string or undefined` | Optional container name to use for the emulator. Useful for reusing or managing a specific container. |
| `volume` | `string or undefined` | Persistent volume to store internal state. default: "juno" |
| `target` | `string or undefined` | Shared folder for deploying and hot-reloading serverless functions. |
| `platform` | `"linux/amd64" or "linux/arm64" or undefined` | The platform to use when running the emulator container. |
| Property | Type | Description |
| ------------ | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | `"docker" or "podman"` | The containerization tool to run the emulator. |
| `image` | `string or undefined` | Image reference. default: depends on emulator type, e.g. "junobuild/skylab:latest" |
| `name` | `string or undefined` | Optional container name to use for the emulator. Useful for reusing or managing a specific container. |
| `volume` | `string or undefined` | Persistent volume to store internal state. default: "juno" |
| `target` | `string or undefined` | Shared folder for deploying and hot-reloading serverless functions. |
| `platform` | `"linux/amd64" or "linux/arm64" or undefined` | The platform to use when running the emulator container. |
| `extraHosts` | `[string, string][] or undefined` | Additional host-to-IP mappings to inject into the container via `--add-host`. Each entry is a `[hostname, destination]` tuple where destination is an IPv4 address, an IPv6 address, `"host-gateway"`, or an arbitrary host string. This is useful for making host-machine services (e.g. a local Ethereum RPC node) reachable from within the container under a stable DNS name such as `host.docker.internal`. example: `ts runner: { extraHosts: [['host.docker.internal', 'host-gateway']] } `see: https://docs.docker.com/reference/cli/docker/container/run/#add-host |

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L125)
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L144)

#### :gear: NetworkServices

Expand All @@ -559,7 +560,7 @@ in the local Internet Computer network when the emulator starts.
| `internet_identity` | `boolean or undefined` | Internet Identity: Deploys the II canister for authentication. |
| `nns_dapp` | `boolean or undefined` | NNS dapp: Deploys the NNS UI canister and frontend application Requires cmc, icp, nns, sns, internet_identity to be enabled. |

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L180)
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L219)

#### :gear: Network

Expand All @@ -570,7 +571,7 @@ by the emulator.
| ---------- | ----------------- | ----------------------------------------------------------- |
| `services` | `NetworkServices` | System canisters and applications available in the network. |

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L239)
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L278)

#### :gear: ModuleSettings

Expand Down Expand Up @@ -746,6 +747,7 @@ changes, typically through CLI commands (e.g., `juno config`).
- [RulesType](#gear-rulestype)
- [DatastoreCollection](#gear-datastorecollection)
- [StorageCollection](#gear-storagecollection)
- [Hostname](#gear-hostname)
- [EmulatorConfig](#gear-emulatorconfig)
- [ModuleLogVisibility](#gear-modulelogvisibility)
- [JunoConfigMode](#gear-junoconfigmode)
Expand Down Expand Up @@ -794,6 +796,16 @@ changes, typically through CLI commands (e.g., `juno config`).

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/collections.ts#L32)

#### :gear: Hostname

A non-empty hostname string.

| Type | Type |
| ---------- | ---- |
| `Hostname` | |

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L118)

#### :gear: EmulatorConfig

The configuration for running the Juno emulator.
Expand All @@ -802,7 +814,7 @@ The configuration for running the Juno emulator.
| ---------------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `EmulatorConfig` | ` | {runner?: EmulatorRunner; network?: Network; skylab: EmulatorSkylab} or {runner?: EmulatorRunner; network?: Network; console: EmulatorConsole} or {runner?: EmulatorRunner; network?: Network; satellite: EmulatorSatellite}` |

[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L272)
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/config/src/satellite/configs/emulator.config.ts#L311)

#### :gear: ModuleLogVisibility

Expand Down
20 changes: 17 additions & 3 deletions packages/config/src/satellite/configs/emulator.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,18 @@ export interface EmulatorSatellite {
}

/**
* @see EmulatorRunner
* @see Hostname
*/
const HostnameSchema = z.string().min(1);

/**
* A non-empty hostname string.
*/
export type Hostname = string;

/**
* @see EmulatorRunner
*/
const EmulatorRunnerSchema = z.strictObject({
type: z.enum(['docker', 'podman']),
image: z.string().optional(),
Expand All @@ -120,7 +128,13 @@ const EmulatorRunnerSchema = z.strictObject({
target: z.string().optional(),
platform: z.enum(['linux/amd64', 'linux/arm64']).optional(),
extraHosts: z
.array(z.tuple([HostnameSchema, z.union([z.ipv4(), z.ipv6(), z.literal('host-gateway'), HostnameSchema])]))
.array(
z.tuple([
HostnameSchema,
z.union([z.ipv4(), z.ipv6(), z.literal('host-gateway'), HostnameSchema])
])
)
.min(1)
.optional()
});

Expand Down Expand Up @@ -179,7 +193,7 @@ export interface EmulatorRunner {
*
* @see https://docs.docker.com/reference/cli/docker/container/run/#add-host
*/
extraHosts?: [string, string][];
extraHosts?: [Hostname, string | 'host-gateway' | Hostname][];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,12 @@ describe('emulator.config', () => {
});

it('accepts a valid IPv4 entry', () => {
const result = EmulatorConfigSchema.safeParse(
withExtraHosts([['myhost', '192.168.1.1']])
);
const result = EmulatorConfigSchema.safeParse(withExtraHosts([['myhost', '192.168.1.1']]));
expect(result.success).toBe(true);
});

it('accepts a valid IPv6 entry', () => {
const result = EmulatorConfigSchema.safeParse(
withExtraHosts([['myhost', '::1']])
);
const result = EmulatorConfigSchema.safeParse(withExtraHosts([['myhost', '::1']]));
expect(result.success).toBe(true);
});

Expand Down Expand Up @@ -637,9 +633,9 @@ describe('emulator.config', () => {
expect(result.success).toBe(true);
});

it('accepts an empty array', () => {
it('rejects an empty array', () => {
const result = EmulatorConfigSchema.safeParse(withExtraHosts([]));
expect(result.success).toBe(true);
expect(result.success).toBe(false);
});

it('is optional (omitted entirely)', () => {
Expand All @@ -655,16 +651,12 @@ describe('emulator.config', () => {
});

it('rejects an entry with an empty hostname', () => {
const result = EmulatorConfigSchema.safeParse(
withExtraHosts([['', '192.168.1.1']])
);
const result = EmulatorConfigSchema.safeParse(withExtraHosts([['', '192.168.1.1']]));
expect(result.success).toBe(false);
});

it('rejects an entry with an empty destination', () => {
const result = EmulatorConfigSchema.safeParse(
withExtraHosts([['myhost', '']])
);
const result = EmulatorConfigSchema.safeParse(withExtraHosts([['myhost', '']]));
expect(result.success).toBe(false);
});

Expand All @@ -676,9 +668,7 @@ describe('emulator.config', () => {
});

it('rejects a tuple with only one element', () => {
const result = EmulatorConfigSchema.safeParse(
withExtraHosts([['myhost']])
);
const result = EmulatorConfigSchema.safeParse(withExtraHosts([['myhost']]));
expect(result.success).toBe(false);
});

Expand Down