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

chore: improve localnet build performance #2928

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Sep 26, 2024

Description

  • Don't use a timestamp if dirty build. Doing this forced unconditional rebuilds every run.
  • Don't copy the git directory into the build. This requires that we also provide a way to push the version info into the build.

With this change you should be able to run make start-e2e-test and if nothing has changed zetanode should not be rebuilt.

I could also be convinced that the localnet build should always just be static. Like v22.0.0-next or something like that.

Summary by CodeRabbit

  • New Features

    • Enhanced versioning logic in the version.sh script, providing more detailed version information including short commit hashes.
  • Improvements

    • Docker build process optimized with new arguments for version control.
    • Streamlined handling of legacy versions in Dockerfile.
  • Bug Fixes

    • Adjusted output format for versioning in version.sh to include commit details for both dirty and non-dirty builds.

@gartnera gartnera added the no-changelog Skip changelog CI check label Sep 26, 2024
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant modifications across several files, primarily focusing on the Docker and Makefile configurations. Key changes include the introduction of new versioning arguments (NODE_VERSION, NODE_COMMIT, OLD_VERSION, and BUILDARCH) in the Dockerfile, updates to the Makefile for tracking these new variables, and enhancements to the versioning logic in the version.sh script. The .dockerignore file has also been adjusted to improve the build process by ignoring unnecessary files and directories.

Changes

Files Change Summary
.dockerignore Added .git to ignore list; removed localnet, package.json, yarn.lock, .github/, .gitignore, and dist/**; excluded Dockerfile entries from ignore list.
Dockerfile-localnet Introduced NODE_VERSION, NODE_COMMIT, OLD_VERSION, and BUILDARCH arguments; organized build stages for modularity; included legacy build options.
Makefile Replaced VERSION and COMMIT with NODE_VERSION and NODE_COMMIT; updated ldflags to reflect new variables; modified zetanode target for Docker build args.
version.sh Added conditional check for NODE_VERSION; modified output format for version strings to include short commit hash; improved logic for dirty and non-dirty builds.

Possibly related PRs

  • chore: use v19 binaries in upgrade tests #2689: The changes in the Makefile to update the OLD_VERSION argument to NODE_VERSION and NODE_COMMIT are directly related to the modifications made in the main PR, which also introduced these new arguments in the Dockerfile and Makefile.

Suggested labels

UPGRADE_IMPORT_MAINNET_TESTS

Suggested reviewers

  • lumtis
  • skosito
  • kingpinXD
  • brewmaster012
  • fbac
  • swift1337

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gartnera gartnera added the UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light label Sep 26, 2024
@gartnera gartnera marked this pull request as ready for review September 30, 2024 13:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
version.sh (3)

3-8: Approve the addition of NODE_VERSION check with a minor suggestion.

The new conditional check for NODE_VERSION is a valuable addition. It enhances performance and maintainability by allowing version determination without git operations, which is particularly useful for Docker builds.

Consider adding input validation for NODE_VERSION to ensure it's not empty or malformed:

 if [[ -n $NODE_VERSION ]]; then
+    if [[ ! $NODE_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
+        echo "Error: NODE_VERSION is not in a valid semantic versioning format" >&2
+        exit 1
+    fi
     echo $NODE_VERSION
     exit
 fi

This change would improve robustness by ensuring NODE_VERSION adheres to semantic versioning format before using it.


19-22: Approve the enhancement of version string with a suggestion for clarity.

The addition of the short commit hash to the version string is a commendable improvement. It provides more detailed version information, which enhances traceability and debugging capabilities.

To improve clarity and maintainability, consider using more descriptive variable names:

-commit_timestamp=$(git show --no-patch --format=%at)
-short_commit=$(git rev-parse --short HEAD)
+commit_unix_timestamp=$(git show --no-patch --format=%at)
+short_commit_hash=$(git rev-parse --short HEAD)

This change makes the purpose of each variable immediately clear to future maintainers.


25-25: Approve the modified version string output with a suggestion for consistency.

The changes to the version string output for both dirty and non-dirty builds are beneficial. They provide more detailed and consistent version information, which is crucial for debugging and tracking builds.

To maintain consistency with semantic versioning and improve readability, consider restructuring the version string:

-echo "0.0.${commit_timestamp}-${short_commit}-dirty"
+echo "0.0.0-${commit_timestamp}.${short_commit}.dirty"

-echo "0.0.${commit_timestamp}-${short_commit}"
+echo "0.0.0-${commit_timestamp}.${short_commit}"

This format aligns better with semantic versioning principles and improves parsing consistency.

Also applies to: 29-29

Makefile (1)

236-236: Incorporation of version information in Docker build

The addition of NODE_VERSION and NODE_COMMIT as build arguments in the Docker build command is a positive change, aligning with the improved versioning strategy. However, the line length could be reduced for better readability.

Consider breaking the long command into multiple lines for improved readability:

-	$(DOCKER) build -t zetanode --build-arg NODE_VERSION=$(NODE_VERSION) --build-arg NODE_COMMIT=$(NODE_COMMIT) --target latest-runtime -f ./Dockerfile-localnet .
+	$(DOCKER) build -t zetanode \
+		--build-arg NODE_VERSION=$(NODE_VERSION) \
+		--build-arg NODE_COMMIT=$(NODE_COMMIT) \
+		--target latest-runtime \
+		-f ./Dockerfile-localnet .
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2892114 and e4c1cb4.

📒 Files selected for processing (4)
  • .dockerignore (1 hunks)
  • Dockerfile-localnet (1 hunks)
  • Makefile (3 hunks)
  • version.sh (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
version.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

🔇 Additional comments (5)
.dockerignore (3)

7-7: Commendable addition of .git to the ignore list.

This change aligns with the PR objective of not copying the git directory into the build. It will significantly reduce the size of the build context and improve build performance.


Line range hint 9-13: Appropriate exclusion of Dockerfile and docker-compose files.

Excluding Dockerfile and docker-compose files from the Docker build context is a good practice. These files are not needed inside the Docker build and their exclusion can help reduce the build context size.


Line range hint 1-6: Verify the necessity of including previously ignored files.

The removal of localnet, package.json, yarn.lock, .github/, .gitignore, and dist/** from the ignore list may increase the build context size and potentially impact build performance. Please confirm that these files are essential for the build process or need to be included in the final image.

✅ Verification successful

Verified: Essential Files Necessary for Build Process

The removed .dockerignore entries (localnet, package.json, yarn.lock, .github/, .gitignore, and dist/**) are essential for the build process as they are actively used in Dockerfiles and build scripts. Their inclusion ensures proper Docker image construction and build functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the removed ignore entries are used in the Dockerfile or build process

# Test 1: Check Dockerfile for usage of previously ignored files
echo "Checking Dockerfile for usage of previously ignored files:"
rg -i -e "localnet|package.json|yarn.lock|\.github|\.gitignore|dist" Dockerfile*

# Test 2: Check if these files exist in the repository
echo "Checking if previously ignored files exist in the repository:"
fd -H "localnet|package.json|yarn.lock|\.github|\.gitignore|dist"

# Test 3: Check if these files are used in any build scripts
echo "Checking build scripts for usage of previously ignored files:"
rg -i -e "localnet|package.json|yarn.lock|\.github|\.gitignore|dist" *.sh Makefile

Length of output: 4358

Makefile (2)

4-5: Improved version and commit management

The introduction of NODE_VERSION and NODE_COMMIT variables enhances the flexibility and consistency of version management in the build process. The use of ./version.sh for NODE_VERSION and the fallback mechanism for NODE_COMMIT are particularly noteworthy improvements.


20-21: Consistent application of new versioning variables

The ldflags have been updated to use NODE_VERSION and NODE_COMMIT, ensuring consistency with the newly introduced variables. This change maintains coherence in version information across different parts of the build process.

Also applies to: 23-24

Dockerfile-localnet Show resolved Hide resolved
@gartnera gartnera self-assigned this Sep 30, 2024
Dockerfile-localnet Show resolved Hide resolved
@gartnera gartnera force-pushed the improve-localnet-build-cache branch from 276ff05 to a151c82 Compare September 30, 2024 19:30
@lumtis lumtis added this pull request to the merge queue Oct 1, 2024
Merged via the queue into develop with commit f9cbcfc Oct 1, 2024
32 checks passed
@lumtis lumtis deleted the improve-localnet-build-cache branch October 1, 2024 10:44
morde08 pushed a commit that referenced this pull request Oct 2, 2024
* chore: improve localnet build performance

* propagate NODE_VERSION and NODE_COMMIT
github-merge-queue bot pushed a commit that referenced this pull request Oct 3, 2024
…guration (#2953)

* update artillery config

* more fixes

* feat: integrate authenticated calls smart contract functionality into protocol (#2904)

* e2e tests and modifications for authenticated call

* extend test with sender check and revert case

* separate tests into separate files

* cleanup

* withdraw and call support and tests

* bump protocol contracts

* split tests into separate files

* small cleanup

* fmt

* generate

* lint

* changelog

* PR  comments

* fix case in proto

* bump vote inbound gas limit in zetaclient

* fix test

* generate

* fixing tests

* call options non empty

* generate

* test fix

* rename gateway caller

* pr comments rename tests

* PR comment

* generate

* tests

* update tests fixes

* tests fixes

* fix

* test fix

* feat!: bank precompile (#2860)

* feat: bank precompile

* feat: add deposit

* feat: extend deposit

* PoC: spend amount on behalf of EOA

* feat: expand deposit with transferFrom

* use CallEVM instead on ZRC20 bindings

* divide the contract into different files

* initialize e2e testing

* remove duplicated funding

* add codecov

* expand e2e

* fix: wait for deposit tx to be mined

* apply first round of reviews

* cover al error types test

* fixes using time.Since

* Include CallContract interface

* fix eth events in deposit precompile method

* emit Deposit event

* add withdraw function

* finalize withdraw

* pack event arguments generically

* add high level event function

* first round of review fixes

* second round of reviews

* create bank account when instantiating bank

* e2e: add good and bad scenarios

* modify fmt

* chore: group input into eventData struct

* docs: document bank's methods

* chore: generate files with suffix .gen.go

* chore: assert errors with errorIs

* chore: reset e2e test by resetting allowance

* test: add first batch of unit test

* test: cover all cases

* test: complete unit test cases

* include review suggestions

* include e2e through contract

* test: add e2e through contract complete

* test: revert balance between tests

* Update precompiles/bank/const.go

Co-authored-by: Lucas Bertrand <[email protected]>

* fix: changed coin denom

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>

* feat: add sender to revert context (#2919)

* e2e tests and modifications for authenticated call

* extend test with sender check and revert case

* separate tests into separate files

* cleanup

* withdraw and call support and tests

* bump protocol contracts

* split tests into separate files

* small cleanup

* fmt

* generate

* lint

* changelog

* PR  comments

* fix case in proto

* bump vote inbound gas limit in zetaclient

* fix test

* generate

* fixing tests

* call options non empty

* generate

* test fix

* rename gateway caller

* pr comments rename tests

* PR comment

* generate

* tests

* add sender in test contract

* extend e2e tests

* generate

* changelog

* PR comment

* generate

* update tests fixes

* tests fixes

* fix

* test fix

* gas limit fixes

* PR comment fix

* fix bad merge

* ci: add option to enable monitoring stack (#2927)

* ci: add option to enable monitoring stack

* start prometheus faster

* update

* ci: add rpcimportable test (#2817)

* ci: add rpcimportable test

* add ci

* fmt

* use github.com/btcsuite/btcd/btcutil in pkg/chains

* remove app imports types tests

* use standalone sdkconfig package

* fix policies test

* move crosschain keeper tests from types to keeper

* never seal config in tests

* use zeta-chain/ethermint#126

* add some comments

* use merged ethermint hash

* show resulting go.mod

* ci: Add SARIF upload to GitHub Security Dashboard (#2929)

* add semgrep sarif upload to GHAS

* added comment to clairfy the usage of the utility script

* use ghcr.io instead

* add tag to image

* bad org name

---------

Co-authored-by: jkan2 <[email protected]>

* fix: add recover to InitChainer to diplay informative message when starting a node from block 1 (#2925)

* add recover to InitChainer

* generate files

* add docs link to error message

* move InitChainErrorMessage to app.go

* Update app/app.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* use const for message

---------

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* test: add wait for block to tss migration test (#2931)

* add wait for block to tss migration test

* add comments

* refactor identifiers

* rename checkNumberOfTssGenerated to checkNumberOfTSSGenerated

* chore: allow full zetaclient config overlay (#2945)

* test(e2e): add gateway upgrade in upgrade test (#2932)

* add gateway upgrade

* change reference

* add v2 setup for all tests

* test v2 in light upgrade

* refactor setup to use custody v2 directly

* chore: improve localnet build performance (#2928)

* chore: improve localnet build performance

* propagate NODE_VERSION and NODE_COMMIT

* update hashes

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
Co-authored-by: Alex Gartner <[email protected]>
Co-authored-by: jkan2 <[email protected]>
Co-authored-by: jkan2 <[email protected]>
Co-authored-by: Tanmay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants