Closed ScovottoDavide closed 11 minutes ago
Thanks @ScovottoDavide for putting together a super detailed example! We actually have a feature already existing that should support the outcome you're trying to achieve.
You can supply either a name or config directory to the start command, which allows you to obtain a copy of the LocalNet setup that can be customise in any way that you desire. Here's the docs for it. https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md#named-localnet-configuration-directory
In practice what you'd do is run algokit localnet start --name custom-localnet
(use whatever name you like). That will clone the localnet configuration and dump it to disk in the default configuration directory. You can then customise the configuration (including the compose file) to do anything you'd like. You can then restart the containers and everything should work as you'd like. To start that named localnet again, you run the above command again.
Keen to hear if this works for your scenario and shout if you have any questions/issues.
@neilcampbell thanks for the quick and detailed response.
I was testing stuff on various networks, and being a lazy person I just added a new option to the localnet command so that I could do it quicker than manually modifying the compose yml :).
I apologize for bothering, and thanks again for your time.
@ScovottoDavide No worries at all, happy to help!
Problem
It would be nice to have the possibility to deploy the localnet instance onto an already existing external docker network. This could be helpful when locally running/testing microservices that are all on the same docker network
Solution
Add a new click option to the
localnet start
andlocalnet reset
commands that accept the name of theexternal_network
. I've forked the project and propose a solution that can be found here: ProposalProposal
If the
external_network
option is provided:ComposeSandbox
by passing the provided network and modify thedocker_compose_yaml
accordingly. The yaml file is modified using thePyYAML
library.ComposeSandbox::_run_docker_command
)ComposeFileStatus == OUT_OF_DATE
, write to file the new yaml filesandbox.up()
Pros and Cons
Pros: possibility to don't rely only on the default docker network created by default, but also leverage already existing ones
Dependencies
None
Best regards.