Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot access a replica running in another container #85

Open
jb747 opened this issue May 31, 2023 · 6 comments
Open

cannot access a replica running in another container #85

jb747 opened this issue May 31, 2023 · 6 comments

Comments

@jb747
Copy link

jb747 commented May 31, 2023

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.

@ZenVoich
Copy link
Owner

ZenVoich commented Jun 2, 2023

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.

@jb747
Copy link
Author

jb747 commented Jun 4, 2023

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 :).

@ZenVoich
Copy link
Owner

ZenVoich commented Jun 5, 2023

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.

@jb747
Copy link
Author

jb747 commented Jun 8, 2023

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!

@ZenVoich
Copy link
Owner

ZenVoich commented Jun 8, 2023

@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?

@jb747
Copy link
Author

jb747 commented Jun 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants