mops icon indicating copy to clipboard operation
mops copied to clipboard

cannot access a replica running in another container

Open jb747 opened this issue 1 year ago • 6 comments

I would like to treat a container running a 'local' replica in a separate Docker container as a docker-compose service accessible via the service name within the Docker runtime environment.

I think this would require, at a minimum, changing getNetwork() to accept an internet address or DNS name by adding an 'else' to the logic:

export function getNetwork() {
	let network = 'ic';
	if (fs.existsSync(networkFile)) {
		network = fs.readFileSync(networkFile).toString() || 'ic';
	}

	if (network === 'local') {
		let ids = JSON.parse(fs.readFileSync(new URL('../.dfx/local/canister_ids.json', import.meta.url)).toString());
		return {
			network,
			host: 'http://127.0.0.1:4943',
			canisterId: ids.main.local,
		};
	}
	else if (network === 'staging') {
		return {
			network,
			host: 'https://ic0.app',
			canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
		};
	}
	else if (network === 'ic') {
		return {
			network,
			host: 'https://ic0.app',
			canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
		};
	} else {
		// ASSUME 'network' is the network address of a replica 
                 // i.e. 'replica_service:4943' or '123.456.7.8:5007'
		return {
			network,
			host: 'http://' + network,
			canisterId: ids.main.local,
		};
	}
}

I can submit a pull request, but currently have difficulty reproducing the build so I cannot test it in my environment. If this change makes sense, let me know if I can help.

jb747 avatar May 31 '23 19:05 jb747

Could you describe what problem you want to solve?

If you are using custom network address, you need to deploy mops on that network and publish packages, if you want to install them.

ZenVoich avatar Jun 02 '23 10:06 ZenVoich

A local replica, from limited testing, seems capable of running at an arbitrary internet address.. like a production ic server. Tying it to '127.0.0.1' seems unnecessarily limiting.

In a docker-compose environment, the local replica may be running in a service with its own name i.e. 'test-replica'. In this environment, other services can access it via 'http://test-replica:4943'.

A docker-compose environment is quite handy for testing in some CI/CD settings. A canister dockerfile can easily switch between 'test-replica' and 'ic' names for testing and production, respectively and it's fairly easy to add containers and external services.

Hopefully that makes sense.. but I am adapting this approach from other projects so perhaps there is an easier way to do this. That would be Nice, too :).

jb747 avatar Jun 04 '23 05:06 jb747

A local replica, from limited testing, seems capable of running at an arbitrary internet address.. like a production ic server. Tying it to '127.0.0.1' seems unnecessarily limiting.

In mops, local '127.0.0.1' is must be used when you developing mops, when you just use mops to install packages it is assumed that you are using the 'ic' network in mops with the 'ic' mops canister containing all published packages.

So, if you are just using mops to use published packages(for example mops sources or mops add ... or mops install) you don't need to switch network in mops.

ZenVoich avatar Jun 05 '23 10:06 ZenVoich

Ok.. will look into it some more when I revisit this and let you know how it goes. My environment does not have many dependencies so it may well be atypical. If you wish to classify this as a feature request or close it, I would have no objection. Thanks for your help!

jb747 avatar Jun 08 '23 04:06 jb747

@jb747 if you are sure you need it, I can add this feature, no problem) I just want to understand your use case.

What canister id is should be when you specify a custom network? If it is mainnet canister id of mops, do you have problems installing packages via https://ic0.app network? If it is local canister id of mops, do you want to deploy mops locally, then publish packages locally, then install that packages locally?

ZenVoich avatar Jun 08 '23 05:06 ZenVoich

I'll get back to you.. it's not a blocker, currently.

jb747 avatar Jun 08 '23 05:06 jb747