-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix: removing only networks started by hedera instead of global prune #686
Changes from 4 commits
7dce9a2
728fc89
1c19719
a77e477
851de02
358a4b6
4e8569b
6cfd740
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,10 @@ services: | |
volumes: | ||
- "${NETWORK_NODE_LOGS_ROOT_PATH}/accountBalances/:/node/streams/accountBalances/" | ||
- "${NETWORK_NODE_LOGS_ROOT_PATH}/recordStreams/:/node/streams/recordstreams/" | ||
networks: | ||
- multinode-importer-evm-network | ||
|
||
networks: | ||
multinode-importer-evm-network: | ||
name: hedera-multinode-importer-evm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need a different network here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess not, I've replaced the extra networks with
declarations. |
||
driver: bridge |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ services: | |
start_period: 10s | ||
volumes: | ||
- "${APPLICATION_ROOT_PATH}/config.multinode.txt:/opt/hgcapp/services-hedera/HapiApp2.0/config.txt" | ||
networks: | ||
- network-node-bridge | ||
|
||
network-node-1: | ||
&network-node-definition | ||
|
@@ -222,3 +224,10 @@ services: | |
importer: | ||
volumes: | ||
- ./compose-network/mirror-node/addressBook.multinode.bin:/usr/etc/hedera-mirror-importer/local-dev-1-node.addressbook.f102.json.bin | ||
networks: | ||
- multinode-importer-network | ||
|
||
networks: | ||
multinode-importer-network: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this extra network? |
||
name: hedera-multinode-importer | ||
driver: bridge |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*- | ||
* | ||
* Hedera Local Node | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import shell from 'shelljs'; | ||
import { IS_WINDOWS, NETWORK_PREFIX } from '../constants'; | ||
|
||
/** | ||
* Checks if the given string is a valid Docker network ID. | ||
* A valid Docker network ID is a 12-character hexadecimal string. | ||
* | ||
* @param {string} id - The string to be validated as a Docker network ID. | ||
* @returns {boolean} - Returns true if the string is a valid Docker network ID, false otherwise. | ||
* | ||
* @example | ||
* const id = "89ded1eca1d5"; | ||
* console.log(isCorrectDockerId(id)); // Output: true | ||
* | ||
* @example | ||
* const invalidId = "invalidID123"; | ||
* console.log(isCorrectDockerId(invalidId)); // Output: false | ||
*/ | ||
const isCorrectDockerId = (id: string) => id.trim() !== '' && /^[a-f0-9]{12}$/.test(id); | ||
|
||
/** | ||
* Provides utility methods for safe networks removal. | ||
*/ | ||
export class SafeDockerNetworkRemover { | ||
/** | ||
* Removes all the networks started by docker compose. Only networks with the "hedera-" prefix will be affected. | ||
*/ | ||
public static removeAll() { | ||
const result = shell.exec(`docker network ls --filter name=${NETWORK_PREFIX} --format "{{.ID}}"`); | ||
if (!result || result.stderr !== '') { | ||
return; | ||
} | ||
result.stdout.split('\n').filter(isCorrectDockerId).forEach((id) => { | ||
shell.exec(`docker network rm ${id} -f 2>${IS_WINDOWS ? 'null' : '/dev/null'}`); | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe for consistency's sake all networks should have a -bridge suffix, or none of them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isavov
I chose the latter option since there is only one network with the “bridge” suffix and a few without it.
I have only updated the name used by Docker, not the Docker Compose level alias, as changing the alias seemed to be outside the current scope.