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

Docker local-testnet scripts #5998

Merged
merged 17 commits into from
Mar 22, 2024
Merged

Docker local-testnet scripts #5998

merged 17 commits into from
Mar 22, 2024

Conversation

cristure
Copy link
Contributor

@cristure cristure commented Feb 27, 2024

Reasoning behind the pull request

  • Scipt to setup a local testnet with docker.

Proposed changes

  • Added scripts to setup local testnet.

Testing procedure

  • Run scripts/docker-testnet/start.sh
  • Inspect the created containers.

Pre-requisites

  • Docker installed.

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@cristure cristure marked this pull request as draft February 27, 2024 16:04
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.17%. Comparing base (5e1569b) to head (71d48d4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5998      +/-   ##
==========================================
- Coverage   80.21%   80.17%   -0.04%     
==========================================
  Files         709      709              
  Lines       94166    94166              
==========================================
- Hits        75535    75501      -34     
- Misses      13284    13316      +32     
- Partials     5347     5349       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cristure cristure marked this pull request as ready for review February 28, 2024 10:10
@cristure cristure force-pushed the local-testnet-docker branch from 90b5a51 to 41d8908 Compare March 14, 2024 07:21
@iulianpascalau iulianpascalau self-requested a review March 14, 2024 08:16
scripts/docker-testnet/helpers.sh Outdated Show resolved Hide resolved
scripts/docker-testnet/helpers.sh Outdated Show resolved Hide resolved

copyConfig

copySeednodeConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, so you actually use a lot of the existing testnet scripts configuration functions 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it's mostly the same configuration. The only difference in configuration are the ports and the ip addresses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I've noticed that: the first question was: how was possible to function if all nodes run on the same ports. But then I've saw the IPs.

@AdoAdoAdo AdoAdoAdo self-requested a review March 14, 2024 08:27
iulianpascalau
iulianpascalau previously approved these changes Mar 14, 2024
iulianpascalau
iulianpascalau previously approved these changes Mar 14, 2024
AdoAdoAdo
AdoAdoAdo previously approved these changes Mar 14, 2024
@cristure cristure dismissed stale reviews from AdoAdoAdo and iulianpascalau via 4f53303 March 14, 2024 11:13
@cristure cristure changed the title Docker compose CI test. Docker local-testnet scripts Mar 14, 2024
iulianpascalau
iulianpascalau previously approved these changes Mar 15, 2024
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will test this ASAP

@@ -0,0 +1,6 @@
pushd ../..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #!/usr/bin/env bash here also? i think pushd is bash specific

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this script intended to be run separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is. I could have added the build step inside the ./start.sh script, but it was easier for me to debug, since it didn't build the images at every run. Don't have a strong opinion on this, I can add it to the wrapper script instead. I was planning on adding a README.md nevertheless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better that we keep the build separate from the run script. Not a strong opinion, thus.

Comment on lines 29 to 31
--network ${DOCKER_NETWORK_NAME} \
seednode:dev \
--rest-api-interface=0.0.0.0:10000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment on lines 62 to 64
-v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \
--network ${DOCKER_NETWORK_NAME} \
node:dev \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use same indentation pattern for the entire script and remove unnecessary empty lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope it's fixed.

}

createDockerNetwork() {
docker network create -d bridge --subnet=${DOCKER_NETWORK_SUBNET} ${DOCKER_NETWORK_NAME}
Copy link
Contributor

@ssd04 ssd04 Mar 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check if network DOCKER_NETWOR_NAME already exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added set -u. Unbound variables will throw an error now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I was referring to the fact that if the network is already created, it will fail because it is not able to create docker network again

Comment on lines 9 to 13
echo "Stopping all containers..."
docker stop $(docker ps -a -q)

echo "Removing all containers..."
docker container prune -f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the scripts will most probably be used in development environment where there might be also other local containers running, i don't think it's fine to stop and prune all containers, we should stop only the intended containers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

if [ "$TESTNETMODE" == "trace" ]; then
LOGLEVEL="*:TRACE"
fi
## Use tmux or not. If set to 1, only 2 terminal windows will be opened, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code. Can use a local.sh file instead. We have exceptions for it in the .gitignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed altogether. not needed in our context.

git clone [email protected]:multiversx/mx-chain-deploy-go.git || true
git clone [email protected]:multiversx/mx-chain-proxy-go.git || true
fi
cd $(dirname $MULTIVERSXDIR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Does this function will always clone the proxy and deploy repos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it will. But if the repository already exists, it won't clone them again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed that is working properly 👍

git clone [email protected]:multiversx/mx-chain-deploy-go.git || true
fatal: destination path 'mx-chain-deploy-go' already exists and is not an empty directory.

Comment on lines 7 to 9
./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry.
./start.sh # Will start the local-testnet.
./clean.sh # Will stop and remove the containers related to the local-testnet.
Copy link
Contributor

@ssd04 ssd04 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that a good flow here is to have also a stop step, in order to be able to have the following development flow:

  • initially: build
  • multiple times: start , stop
  • and finally: clean

i think is not very good to have to clean everything on each run, sometimes we just wan't to stop the squad and start it again, with the same/setup configuration, later on

Copy link
Contributor

@ssd04 ssd04 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also related to the docker network create comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This intended workflow adds some complexity. The start.sh uses the docker run command. If you stop all containers, they will only start again withdocker start instead, otherwise it will throw an error. I don't see much of a benefit to this behaviour, as I need to persists all the containerIds/containerNames between stopping and restarting. One can achieve this manually by leveraging already available commands in the clean.sh script.

iulianpascalau
iulianpascalau previously approved these changes Mar 18, 2024
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally with system-tests-go and worked perfectly

iulianpascalau
iulianpascalau previously approved these changes Mar 20, 2024
docker start $line
done < "$file_path"

rmdir ./tmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line?

for CONTAINER_ID in $CONTAINER_IDS; do
docker stop "$CONTAINER_ID"
echo "$CONTAINER_ID" >> ./tmp/stopped_containers
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line?

@cristure cristure merged commit 69d5f59 into master Mar 22, 2024
7 of 8 checks passed
@cristure cristure deleted the local-testnet-docker branch March 22, 2024 12:49
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

Successfully merging this pull request may close these issues.

4 participants