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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@junobuild/admin": "^4.2.1",
"@junobuild/cdn": "^2.3.1",
"@junobuild/cli-tools": "^0.12.3",
"@junobuild/config": "^2.14.2",
"@junobuild/config": "^2.14.2", // TODO: Bump this to the version with extraHosts support.
"@junobuild/config-loader": "^0.4.9",
"@junobuild/core": "^5.2.2",
"@junobuild/functions-tools": "^0.5.3",
Expand Down
5 changes: 4 additions & 1 deletion src/configs/emulator.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const readEmulatorConfig = async (): Promise<

const targetDeploy = config.runner?.target ?? DEPLOY_LOCAL_REPLICA_PATH;

const extraHosts = (config.runner?.extraHosts ?? []).map(([hostname, destination]) => `${hostname}:${destination}`);

return {
success: true,
config: {
Expand All @@ -48,7 +50,8 @@ export const readEmulatorConfig = async (): Promise<
containerName,
emulatorType,
runner,
targetDeploy
targetDeploy,
extraHosts
}
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/services/emulator/_runner.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const initConfigFile = async () => {
const startEmulator = async ({config: extendedConfig}: {config: CliEmulatorConfig}) => {
const {
config,
derivedConfig: {emulatorType, containerName, runner, targetDeploy}
derivedConfig: {emulatorType, containerName, runner, targetDeploy, extraHosts}
} = extendedConfig;

const {running} = await assertContainerRunning({containerName, runner});
Expand Down Expand Up @@ -249,6 +249,10 @@ const startEmulator = async ({config: extendedConfig}: {config: CliEmulatorConfi
'-v',
`${targetDeploy}:/juno/target/deploy`,
...(nonNullish(platform) ? [`--platform=${platform}`] : []),
// Inject extra host-to-IP mappings so services on the host machine
// (e.g. a local Ethereum RPC node) are reachable inside the container
// via a stable hostname like host.docker.internal.
...extraHosts.flatMap((host) => ['--add-host', host]),
image
]
});
Expand Down
18 changes: 18 additions & 0 deletions src/types/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ export interface CliEmulatorDerivedConfig {
runner: EmulatorRunnerType;
emulatorType: EmulatorType;
targetDeploy: string;
/**
* Additional host-to-IP mappings injected into the container via `--add-host`.
* Format: `"hostname:ip"` or `"hostname:host-gateway"`.
*
* 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
*/
extraHosts: string[];
}

export interface CliEmulatorConfig {
Expand Down
Loading