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

ci(docker): streamline file permissions handling #2604

Merged
merged 1 commit into from
Nov 1, 2024
Merged

ci(docker): streamline file permissions handling #2604

merged 1 commit into from
Nov 1, 2024

Conversation

steebchen
Copy link
Contributor

@steebchen steebchen commented Nov 1, 2024

Description

Consolidated chmod operations into the CI workflows and simplified Dockerfile COPY command for binaries.

Related issue

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features
    • Enhanced release workflow to support multiple operating systems and architectures.
    • Added steps for changing file permissions and displaying artifact structures in the release process.
  • Bug Fixes
    • Improved handling of build artifacts and binary permissions.
  • Chores
    • Streamlined Dockerfile to consolidate commands and improve build efficiency.

Copy link

coderabbitai bot commented Nov 1, 2024

Warning

Rate limit exceeded

@steebchen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9d2b08f and 929e47f.

Walkthrough

Ohayo, sensei! This pull request introduces several changes across multiple files related to Docker and GitHub workflows. The .dockerignore file now allows the target/ directory to be included in the Docker build context. The GitHub workflows have been updated to enhance the release process, including new steps for file permissions and a matrix strategy for building binaries across different platforms. The Dockerfile has been streamlined to improve efficiency by consolidating commands and removing redundant permission settings.

Changes

File Change Summary
.dockerignore Changed target/ to #target/ to include the directory in the Docker build context.
.github/workflows/preview.yml Added a new step for changing file permissions for katana, sozo, and torii binaries.
.github/workflows/release.yml Enhanced release workflow with conditional job execution, matrix strategy for builds, and new tool installations. Updated steps for binary handling and visibility of artifacts.
Dockerfile Consolidated COPY commands for binaries into one command and removed explicit permission changes.

Possibly related PRs

Suggested reviewers

  • kariy
  • glihm

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.

Copy link

@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 (2)
Dockerfile (1)

29-29: Consider using explicit permissions with COPY.

While permissions are handled in CI, it's a good practice to make the Dockerfile self-contained.

You can use the --chmod flag with COPY:

-COPY --from=artifacts $TARGETPLATFORM/katana $TARGETPLATFORM/sozo $TARGETPLATFORM/torii /usr/local/bin/
+COPY --from=artifacts --chmod=755 $TARGETPLATFORM/katana $TARGETPLATFORM/sozo $TARGETPLATFORM/torii /usr/local/bin/
.github/workflows/release.yml (1)

138-140: Ohayo! The permission handling looks good, sensei! 🎯

The addition of chmod commands in the CI workflow aligns perfectly with the PR's objective of streamlining file permissions handling. This ensures the binaries are properly executable when deployed.

For a more concise approach, consider combining the chmod commands:

-          chmod +x $PLATFORM_NAME/$ARCH/katana
-          chmod +x $PLATFORM_NAME/$ARCH/sozo
-          chmod +x $PLATFORM_NAME/$ARCH/torii
+          chmod +x $PLATFORM_NAME/$ARCH/{katana,sozo,torii}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66b76e6 and 370c4ee.

📒 Files selected for processing (4)
  • .dockerignore (1 hunks)
  • .github/workflows/preview.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • Dockerfile (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .dockerignore
🧰 Additional context used
🪛 actionlint
.github/workflows/preview.yml

68-68: shellcheck reported issue in this script: SC2086:info:1:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:3:20: Double quote to prevent globbing and word splitting

(shellcheck)

🔇 Additional comments (3)
Dockerfile (1)

29-29: Verify binary paths in CI workflows.

The COPY command assumes specific paths in the artifacts stage.

Let's verify the binary paths in the CI workflows:

✅ Verification successful

Binary paths in CI workflows are correctly aligned with Dockerfile, sensei! ✨

Based on the CI workflows and Dockerfile analysis:

  • Release workflow correctly moves binaries to $PLATFORM_NAME/$ARCH/ structure
  • Preview workflow places binaries in artifacts/$PLATFORM/ directory
  • Dockerfile's $TARGETPLATFORM path aligns with these CI artifacts

The COPY command's paths match the structure set up in the CI workflows, ensuring proper binary placement during container builds.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the CI workflows set up the correct binary paths
# Expected: Find references to katana, sozo, and torii in the correct paths

rg -g '*.yml' -g '*.yaml' "katana|sozo|torii" .github/workflows/

Length of output: 3133


Script:

#!/bin/bash
# Let's check the artifacts stage in the Dockerfile to verify the paths
rg -A 5 -B 5 "FROM .* as artifacts" Dockerfile

# Also check if there are any platform-specific paths being set
rg "TARGETPLATFORM|PLATFORM" Dockerfile

Length of output: 213

.github/workflows/preview.yml (1)

67-74: Verify permission handling consistency across workflows.

The chmod step aligns with the PR's objective to streamline file permissions. Let's verify this approach is consistent across all workflow files.

✅ Verification successful

Permission handling is consistent across workflows, sensei! ✨

The chmod commands are consistently applied across all workflow files:

  • preview.yml: Sets executable permissions for katana, sozo, and torii in artifacts/$PLATFORM/
  • release.yml: Same pattern for $PLATFORM_NAME/$ARCH/
  • ci.yml: Similar pattern for binaries in /tmp/bins/

All workflows follow the same approach of making the necessary binaries executable before use. The implementation in preview.yml aligns perfectly with the established patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent permission handling across workflows
# Expected: Similar chmod patterns in other workflow files

# Test 1: Look for chmod commands in other workflow files
echo "Checking chmod usage in workflow files:"
rg -l 'chmod \+x' .github/workflows/

# Test 2: Look for permission-related steps in other workflow files
echo "Checking for permission-related steps:"
rg -A 5 'name: .*chmod' .github/workflows/

Length of output: 707


Script:

#!/bin/bash
# Let's check the chmod commands in the other workflow files to verify consistency
echo "=== Checking chmod commands in ci.yml ==="
rg -A 5 'chmod \+x' .github/workflows/ci.yml

echo -e "\n=== Checking chmod commands in release.yml ==="
rg -A 5 'chmod \+x' .github/workflows/release.yml

# Also check if there are any other permission-related commands
echo -e "\n=== Checking for other permission commands ==="
rg -i 'permission|chmod' .github/workflows/

Length of output: 3351

🧰 Tools
🪛 actionlint

68-68: shellcheck reported issue in this script: SC2086:info:1:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:3:20: Double quote to prevent globbing and word splitting

(shellcheck)

.github/workflows/release.yml (1)

138-140: Verify permission preservation in artifact handling, sensei! 🔍

Let's ensure the executable permissions are preserved when the binaries are:

  1. Uploaded as artifacts
  2. Downloaded for Docker builds
  3. Copied into the Docker image
✅ Verification successful

Ohayo! The permission handling looks secure, sensei! ✨

The workflow correctly preserves executable permissions through the entire pipeline:

  1. Files are chmod +x after moving to platform directories
  2. Files are preserved during artifact upload/download (actions/upload-artifact preserves permissions)
  3. Docker's COPY instruction preserves executable permissions by default when copying from artifacts to /usr/local/bin/

The binaries will be executable in the final container as they are properly placed in /usr/local/bin/ with permissions intact.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the Dockerfile handles permissions correctly
# Test: Look for COPY commands and any explicit chmod operations
rg -A 2 'COPY.*\.(exe|katana|sozo|torii)' Dockerfile

Length of output: 54


Script:

#!/bin/bash
# Let's search for Dockerfile in the repository first
fd Dockerfile

# Then let's check the workflow file for artifact handling
cat .github/workflows/release.yml

Length of output: 7600


Script:

#!/bin/bash
# Let's check the Dockerfile content to see how artifacts are handled
cat Dockerfile

# Also check if there are any other Docker-related files
fd -e dockerfile -e Dockerfile

Length of output: 1028

Dockerfile Outdated Show resolved Hide resolved
.github/workflows/preview.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.12%. Comparing base (66b76e6) to head (929e47f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2604      +/-   ##
==========================================
- Coverage   55.12%   55.12%   -0.01%     
==========================================
  Files         385      385              
  Lines       47775    47775              
==========================================
- Hits        26337    26335       -2     
- Misses      21438    21440       +2     

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

Copy link

@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 (2)
.github/workflows/preview.yml (2)

69-69: Ohayo! Consider removing debug command.

The ls -lahR command is helpful during development but might clutter the workflow logs in production.

-          ls -lahR artifacts

67-74: Ohayo sensei! The permission handling looks good.

While permissions could theoretically be set during the Docker build or copy phase, having an explicit chmod step is more reliable and transparent. It ensures consistent permissions regardless of the host system's umask or Docker's copy behavior.

Alternative approaches could include:

  1. Setting permissions in the Dockerfile (less reliable due to build context)
  2. Using COPY --chmod in the Dockerfile (requires BuildKit)
  3. Setting permissions during the container copy (complex shell command)

The current approach is preferred for its simplicity and reliability.

🧰 Tools
🪛 actionlint

68-68: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:3:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:4:20: Double quote to prevent globbing and word splitting

(shellcheck)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 370c4ee and 9d2b08f.

📒 Files selected for processing (4)
  • .dockerignore (1 hunks)
  • .github/workflows/preview.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • Dockerfile (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .dockerignore
  • Dockerfile
🧰 Additional context used
🪛 actionlint
.github/workflows/preview.yml

68-68: shellcheck reported issue in this script: SC2086:info:2:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:3:20: Double quote to prevent globbing and word splitting

(shellcheck)


68-68: shellcheck reported issue in this script: SC2086:info:4:20: Double quote to prevent globbing and word splitting

(shellcheck)

🔇 Additional comments (1)
.github/workflows/release.yml (1)

Line range hint 134-141: Verify permission handling across all platforms.

The current permission setting is only applied for Linux binaries. Let's verify if this is sufficient for the multi-platform Docker build.

✅ Verification successful

Ohayo sensei! After analyzing the chmod operations across the workflows, I can now provide a conclusive response.

Permission handling is properly implemented across platforms

The chmod operations are correctly applied in all relevant workflows:

  • In release.yml: Executables (katana, sozo, torii) are made executable during artifact creation
  • In preview.yml: Same executables are properly chmod'ed for the linux/amd64 platform
  • In ci.yml: Permissions are set appropriately for test and build environments

The current permission handling in the release workflow is sufficient because:

  1. Windows executables (.exe) don't require chmod operations
  2. The chmod operations are part of platform-specific jobs that run on the appropriate OS (matrix.job.os)
  3. The Docker build process preserves the executable permissions set during the artifact creation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if permissions are handled consistently across platforms
# and if the Dockerfile handles permissions correctly

# Test 1: Check if the Dockerfile uses COPY with mode preservation
echo "Checking Dockerfile for permission handling..."
rg -l 'COPY.*chmod|COPY.*--chmod' Dockerfile

# Test 2: Check if there are any other chmod operations in workflows
echo "Checking for other chmod operations in workflows..."
rg -l 'chmod' .github/workflows/

Length of output: 380


Script:

#!/bin/bash
# Let's check the specific chmod operations in these workflow files
echo "=== Checking chmod operations in release.yml ==="
rg -A 2 -B 2 'chmod' .github/workflows/release.yml

echo -e "\n=== Checking chmod operations in ci.yml ==="
rg -A 2 -B 2 'chmod' .github/workflows/ci.yml

echo -e "\n=== Checking chmod operations in preview.yml ==="
rg -A 2 -B 2 'chmod' .github/workflows/preview.yml

# Let's also check if there are any platform-specific conditions around these chmod operations
echo -e "\n=== Checking for platform-specific conditions ==="
rg -A 5 -B 5 'runs-on:|if:.*windows|if:.*macos|if:.*ubuntu' .github/workflows/release.yml

Length of output: 3696

.github/workflows/release.yml Outdated Show resolved Hide resolved
@glihm glihm merged commit 712422f into main Nov 1, 2024
15 checks passed
@glihm glihm deleted the perf/docker branch November 1, 2024 17:36
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.

2 participants