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

Refactor Docker files for ARM performance improvements #282

Merged
merged 12 commits into from
Oct 13, 2024

Conversation

katosdev
Copy link
Contributor

@katosdev katosdev commented Oct 12, 2024

What type of PR is this?

  • Enhancement

What this PR does / why we need it:

Make adjustments to Docker build processes to better leverage cache and refactor to improve overall performance and reliability.

Which issue(s) this PR fixes:

#281

Summary by CodeRabbit

  • New Features

    • Enhanced Docker publishing workflows for ARM architecture, improving build performance and efficiency.
    • Introduced image attestation for better provenance in built images.
  • Bug Fixes

    • Streamlined metadata extraction and caching processes for improved reliability.
  • Documentation

    • Updated comments in Dockerfiles for better clarity on build stages and processes.
  • Chores

    • Optimized Dockerfile structure for cross-platform compatibility and reduced image sizes.

Update Dockerfile to attempt to optimise build times,
Update with optimisation attempts
Fix my absolute shit-show of a Docker refactor.
Update the action for Arm
Copy link
Contributor

coderabbitai bot commented Oct 12, 2024

Walkthrough

The changes in this pull request involve significant updates to Docker publishing workflows for ARM architecture and rootless images, alongside modifications to Dockerfiles. The workflows now include refined triggers, environment variable settings, and enhanced build steps utilizing Docker Buildx for improved performance. Both workflows have introduced image attestation for build provenance. The Dockerfiles have been optimized for cross-platform compatibility and caching efficiency, with structural adjustments to enhance clarity and functionality.

Changes

File Change Summary
.github/workflows/docker-publish-arm.yaml Updated triggers, environment variables, and build steps for Docker publishing on ARM. Added image attestation step.
.github/workflows/docker-publish-rootless-arm.yaml Modified triggers, environment variables, and build steps for rootless ARM images. Introduced image attestation step.
Dockerfile Enhanced structure with --platform=$TARGETPLATFORM, improved caching, and clarified comments.
Dockerfile.rootless Adjusted COPY commands, optimized package installation, and reformatted health checks for clarity.

Possibly related PRs

  • chore: split arm docker builds into their own tags #264: The changes in the main PR regarding the Docker publishing workflows for ARM architecture are directly related to the modifications made in this PR, which also focuses on enhancing Docker builds for ARM by introducing a new workflow and refining the tagging structure.

Suggested labels

⬆️ enhancement

🎉 In the world of Docker, we strive,
With ARM and rootless, our builds come alive!
Caching and clarity, we now embrace,
Attesting our images, keeping pace.
So here's to the changes, both bold and bright,
In the realm of containers, we take flight! 🚀

Security Recommendations

  • Ensure that the image attestation process is properly configured to validate the integrity of the images being built and pushed to the registry.
  • Regularly review and update permissions in your workflows to adhere to the principle of least privilege, minimizing potential security risks.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f26b5e1 and d45c8b2.

📒 Files selected for processing (1)
  • .github/workflows/docker-publish-rootless-arm.yaml (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/docker-publish-rootless-arm.yaml

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.

I didn't mean to use a remote build... Force of habit!
Fixing a force-of-habit mistake 🙁
This is starting to annoy me now
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: 0

🧹 Outside diff range and nitpick comments (6)
.github/workflows/docker-publish-rootless-arm.yaml (6)

53-56: Approve Docker Buildx setup with a security recommendation.

The update to Docker Buildx action v3.0.0 and the addition of 'install' and 'use' options are good improvements. They ensure the latest stable version is used and Buildx is properly set up for the job.

For enhanced security, consider pinning the action to a specific commit SHA instead of using a version tag. This prevents potential supply chain attacks if the tag is compromised. For example:

uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

You can find the commit SHA for a specific version in the action's release notes or GitHub repository.


62-62: Approve Docker login action update with a security recommendation.

Updating the Docker login action to v3.0.0 is a good practice for maintaining up-to-date and secure dependencies.

Similar to the previous recommendation, consider pinning this action to a specific commit SHA for enhanced security:

uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0

This practice helps prevent potential supply chain attacks by ensuring you're using a specific, verified version of the action.


72-78: Approve metadata action update and tagging strategy with security recommendations.

The update to Docker metadata action v5.0.0 and the enhanced tagging strategy are excellent improvements. The new tagging approach provides better versioning granularity and supports nightly builds, which is beneficial for tracking and potential rollbacks.

Consider the following security recommendations:

  1. Pin the action to a specific commit SHA:

    uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4 # v5.0.0
  2. For the nightly builds, consider adding a SHA or build number to the tag to ensure uniqueness and traceability:

    type=schedule,pattern=nightly-{{sha}}
  3. Implement a retention policy for nightly builds to manage the accumulation of images over time.

These practices enhance the security and manageability of your Docker images.


86-97: Approve build and push action update with security recommendations.

The update to Docker build-push action v5.0.0 and the additions for multi-platform builds, caching, and build arguments are excellent improvements. These changes enhance build performance, cross-platform compatibility, and image traceability.

Consider the following security recommendations:

  1. Pin the action to a specific commit SHA:

    uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.0.0
  2. Implement content trust for image signing and verification:

    with:
      ...
      trust-server-cert: ${{ secrets.DOCKER_TRUST_SERVER_CERT }}
  3. Consider using BuildKit's secret passing feature for sensitive build arguments:

    secrets: |
      "mysecret=${{ secrets.MYSECRET }}"
  4. Implement image scanning in your workflow to detect vulnerabilities before pushing:

    - name: Scan image
      uses: anchore/scan-action@v3
      with:
        image: "${{ steps.build-and-push.outputs.imageid }}"
        fail-build: true
        severity-cutoff: high

These practices will further enhance the security of your build and push process.


99-108: Highly approve image attestation addition with further security recommendations.

The addition of image attestation is an excellent security improvement. It enhances the provenance and integrity of your built images, which is crucial for maintaining a secure software supply chain.

To further strengthen your security posture, consider the following recommendations:

  1. Pin the attestation action to a specific commit SHA:

    uses: actions/attest-build-provenance@2d7a3f2d1f2d0d0e0d0d0d0d0d0d0d0d0d0d0d0d # v1
  2. Implement a policy to verify attestations before deployment:

    - name: Verify attestation
      run: |
        cosign verify-attestation ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}
  3. Consider implementing additional attestations, such as SLSA provenance:

    - uses: slsa-framework/slsa-github-generator@v1
      with:
        base64-subjects: ${{ steps.build-and-push.outputs.digest }}
        provenance-name: provenance.intoto.jsonl
  4. Ensure that your artifact consumers are set up to verify these attestations before using the images.

These practices will further enhance the security and trustworthiness of your build artifacts.


81-81: Remove trailing space for better code hygiene.

There is a trailing space on this line. While this doesn't affect functionality, it's good practice to remove it for code cleanliness.

Please remove the trailing space from this line:

-  
+

This small change will improve code consistency and eliminate potential issues with systems sensitive to trailing spaces.

🧰 Tools
🪛 yamllint

[error] 81-81: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0d6ec9c and 52f9306.

📒 Files selected for processing (2)
  • .github/workflows/docker-publish-arm.yaml (2 hunks)
  • .github/workflows/docker-publish-rootless-arm.yaml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/docker-publish-arm.yaml
🧰 Additional context used
🪛 yamllint
.github/workflows/docker-publish-rootless-arm.yaml

[error] 81-81: trailing spaces

(trailing-spaces)

@katosdev
Copy link
Contributor Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Oct 12, 2024

✅ Actions performed

Full review triggered.

@katosdev
Copy link
Contributor Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Oct 12, 2024

✅ Actions performed

Full review triggered.

@katosdev katosdev marked this pull request as ready for review October 12, 2024 17:06
@katosdev
Copy link
Contributor Author

Bit of a messy PR sorry as I had a bit of a 'mare with the old Docker commands (force of habit of using remote build controls)
@tankerkiller125 - Would be good to get a review if you can please bud, but no major rush.

In testing, I've gotten ARM builds down from an average of ~24minutes to an average of ~14 minutes.

I suspect this may get better with more aggressive caching.

@katosdev katosdev merged commit 9b72419 into main Oct 13, 2024
8 checks passed
@katosdev katosdev deleted the katos/docker-arm-refactor branch October 13, 2024 11:58
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.

1 participant