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

build: adjust docker build context #2336

Merged
merged 4 commits into from
Nov 19, 2024
Merged

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Nov 18, 2024

Issue being fixed or feature implemented

All docker Images are building when you modify any file in monorepo.

What was done?

  • Build drive only if drive related packages are changed
  • Build JS only if related packages are changed
  • Build DAPI only if DAPI is changed
  • Build Dashmate helper only if dashmate is changed
  • Build test suite only if test suite is changed
  • Reduced layer sizes

How Has This Been Tested?

Changing various files and building locally

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Updated Dockerfile syntax to a newer version, introducing optimizations for the build process.
    • Enhanced organization and efficiency of the Docker build process for better image management.
  • Chores

    • Modified .dockerignore to exclude the .github directory from the Docker build context.

Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request involve modifications to the .dockerignore and Dockerfile. The .dockerignore file now includes .github to exclude it from the Docker build context. The Dockerfile has been updated to a newer syntax version, with significant alterations to the build process, including additional packages, refined environment variable handling, and improved file copying methods to maintain directory structure. These changes enhance the organization and efficiency of the Docker build process.

Changes

File Change Summary
.dockerignore Added .github to the list of ignored files and directories.
Dockerfile Updated syntax version to 1.7-labs. Added multiple ARG declarations and modified COPY commands to maintain directory structure. Enhanced environment variable handling and streamlined dependency installation for various build stages.

Possibly related PRs

  • build: devcontainer support #2179: The changes in the .devcontainer/Dockerfile may relate to the modifications in the main PR's Dockerfile, as both involve updates to Dockerfile configurations and dependencies.
  • ci: prebuild dev containers #2184: The updates to the .devcontainer/devcontainer.json and the introduction of a new workflow in this PR may connect with the changes in the main PR's Dockerfile, particularly regarding the Docker build context and configurations.
  • fix(dashmate): invalid mount path from helper #2296: The modifications to the docker-compose.yml file in this PR may relate to the changes in the main PR's Dockerfile, as both involve Docker configurations and environment variables.
  • ci: prebuilt librocksdb in docker image #2318: The changes in the Dockerfile regarding the installation of dependencies and build processes may relate to the updates in the main PR's Dockerfile, particularly concerning the handling of build arguments and dependencies.

Suggested reviewers

  • QuantumExplorer

🐇 In the burrow, changes abound,
Docker's dance, new syntax found.
.github tucked away with care,
Builds refined, light as air.
With each layer, we hop and play,
Optimized paths lead the way! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bb5fb7a and f2dce7c.

📒 Files selected for processing (1)
  • Dockerfile (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dockerfile

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@shumkov shumkov added this to the v1.6.0 milestone Nov 18, 2024
@shumkov shumkov self-assigned this Nov 18, 2024
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: 2

🧹 Outside diff range and nitpick comments (1)
Dockerfile (1)

393-394: Remove commented-out code or explain its necessity

The commented-out RUN command at line 394 can cause confusion. If it's no longer needed, consider removing it. If it's temporarily disabled, add a comment explaining why.

Apply this diff to remove the commented-out code:

-#RUN touch /platform/packages/dapi-grpc/build.rs
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ff2a831 and 45d7fdd.

📒 Files selected for processing (2)
  • .dockerignore (1 hunks)
  • Dockerfile (11 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .dockerignore
🔇 Additional comments (6)
Dockerfile (6)

1-1: Dockerfile syntax version update is acceptable

Updating to # syntax = docker/dockerfile:1.7-labs enables new features and optimizations available in Dockerfile syntax version 1.7.


288-288: Verify that COPY --parents is supported in your build environment

The --parents flag in the COPY command is an experimental feature introduced in BuildKit with Dockerfile syntax version 1.7-labs. Ensure that your Docker builder supports this feature to prevent build failures.


360-360: Verify that COPY --parents is supported in your build environment

As noted earlier, the use of COPY --parents is an experimental feature. Please ensure your build environment supports it.


447-447: Verify that COPY --parents is supported in your build environment

Reiterating the earlier point, ensure that the COPY --parents feature is supported to avoid issues during the build.


493-495: Ensure wildcard deletion of packages/rs-* is safe

Using rm -rf packages/rs-* deletes all directories matching rs-*. Verify that this won't remove necessary packages, especially if new packages matching this pattern are added in the future.


385-386: 🛠️ Refactor suggestion

Remove unnecessary packages from the build context

The TODO comment indicates that packages/rs-drive-proof-verifier may not be needed here as well. Removing it can improve the build efficiency.

Apply this diff:

     packages/rs-json-schema-compatibility-validator \
-    # TODO: We don't need those. Maybe dynamically remove them from workspace or move outside of monorepo?
-    packages/rs-drive-proof-verifier \
     packages/wasm-dpp \

Comment on lines +313 to +314
# TODO: We don't need those. Maybe dynamically remove them from workspace or move outside of monorepo?
packages/rs-drive-proof-verifier \
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unnecessary packages from the build context

The TODO comment indicates that packages/rs-drive-proof-verifier may not be needed. Removing it from the COPY command can optimize the build context and reduce build times.

Apply this diff to remove the unnecessary package:

     packages/rs-json-schema-compatibility-validator \
-    # TODO: We don't need those. Maybe dynamically remove them from workspace or move outside of monorepo?
-    packages/rs-drive-proof-verifier \
     packages/wasm-dpp \

Committable suggestion skipped: line range outside the PR's diff.

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 (5)
Dockerfile (5)

288-320: Optimize build context by excluding unnecessary files

The COPY command includes several packages that might not be needed for the build planner stage. Consider using a .dockerignore file to exclude test files, documentation, and other non-essential files to reduce the build context size.

#!/bin/bash
# Check the size of copied directories
find packages -type f -name "*.md" -o -name "*.test.*" -o -name "*.spec.*" | wc -l

393-394: Remove commented-out code

The commented-out workaround for dapi-grpc's build.rs should be either implemented or removed to maintain clean code.

-# Workaround: as we cache dapi-grpc, its build.rs is not rerun, so we need to touch it
-#RUN touch /platform/packages/dapi-grpc/build.rs

417-420: Optimize layer size reduction

Good practice of removing the /platform directory to reduce layer size. However, consider combining this with the previous commands in the same RUN instruction to avoid creating an intermediate layer.

-    cp target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
-    if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi && \
-    # Remove /platform to reduce layer size
-    rm -rf /platform
+    cp target/${OUT_DIRECTORY}/drive-abci /artifacts/ && \
+    if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi && \
+    cd / && rm -rf /platform

493-495: Optimize cleanup process

The cleanup process removes Rust packages after the build. Consider moving this cleanup into the same RUN instruction as the build to reduce layer size.

-    if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi && \
-    # Remove target directory and rust packages to save space
-    rm -rf target packages/rs-*
+    if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi && \
+    rm -rf target packages/rs-* && \
+    yarn cache clean

552-554: Consider using multi-stage build for dashmate

The dashmate package copy could be optimized by using a separate build stage for its dependencies, similar to how the JS build stage is structured.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 45d7fdd and b4e674d.

📒 Files selected for processing (1)
  • Dockerfile (11 hunks)
🔇 Additional comments (2)
Dockerfile (2)

629-630: LGTM: Clean DAPI package copy

The DAPI package copy is well-structured and follows the pattern established in other stages.


1-1: Consider the implications of using labs features

The Dockerfile syntax is set to docker/dockerfile:1.7-labs, which includes experimental features. While this enables advanced functionality, be aware that labs features may change or be removed in future versions.

✅ Verification successful

Let me gather more specific information about the labs features usage in the Dockerfile.


Labs features are actively utilized and provide significant benefits

The Dockerfile makes effective use of labs features that improve build performance and maintainability:

  • Cache mounts for Cargo registry and git database, which significantly speed up Rust builds
  • --parents flag with COPY commands for maintaining directory structure
  • All features used are stable within the labs feature set

These features provide substantial benefits for the build process and their usage is justified. The warning about labs features can be dismissed as the benefits outweigh the risks in this case.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any labs-specific features are used in the Dockerfile
rg -l "^#syntax.*labs" .

Length of output: 1132


Script:

#!/bin/bash
# Check for labs-specific features in the Dockerfile
rg "^#syntax.*labs" Dockerfile

# Look for common labs features
rg -i "mount=?type=(secret|ssh|cache)" Dockerfile
rg "RUN.*--mount=" Dockerfile
rg "COPY.*--parents" Dockerfile

Length of output: 1814

Dockerfile Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Copy link
Contributor

@lklimek lklimek left a comment

Choose a reason for hiding this comment

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

lgtm

Dockerfile Show resolved Hide resolved
@shumkov shumkov merged commit 0cb24ea into v1.6-dev Nov 19, 2024
18 checks passed
@shumkov shumkov deleted the build/adjust-build-context branch November 19, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants