Skip to content

Use Zstd compression for published images to reduce their size and speedup decompression#220

Closed
slonopotamus wants to merge 1 commit intohassio-addons:mainfrom
slonopotamus:zstd
Closed

Use Zstd compression for published images to reduce their size and speedup decompression#220
slonopotamus wants to merge 1 commit intohassio-addons:mainfrom
slonopotamus:zstd

Conversation

@slonopotamus
Copy link

@slonopotamus slonopotamus commented Jul 20, 2025

Proposed Changes

Zstd is a faster and more efficient compression algorithm than Gzip. This PR enables Zstd for all images created using hassio-addons/workflows. Docker supports Zstd images for multiple years already.

Related Issues

home-assistant/operating-system#4123 (review)
home-assistant/builder#245

Summary by CodeRabbit

  • Chores
    • Updated deployment workflows to combine build and push steps for Docker images, improving efficiency and simplifying the process.
    • Adjusted image output settings to use a specific compression method.

@coderabbitai
Copy link

coderabbitai bot commented Jul 20, 2025

"""

Walkthrough

The GitHub Actions workflows for Docker image deployment have been updated. The build and push steps are now consolidated into a single step using the docker/build-push-action with push: true and specific output settings. Manual docker push commands and separate push steps have been removed.

Changes

Files Change Summary
.github/workflows/addon-deploy.yaml,
.github/workflows/base-deploy.yaml
Consolidated separate build and push steps into a single "Build & Push" step using docker/build-push-action with push: true and specified output/compression. Removed manual docker push commands and the separate push step.

Estimated code review effort

1 (<30 minutes)

Possibly related PRs

Suggested labels

no-stale

Suggested reviewers

  • frenck

Poem

A rabbit hops where workflows dwell,
Build and push now merged as well.
No more steps to push by hand,
One swift leap, just as planned!
Docker images soar with glee—
Simpler scripts for all to see.
🐇🚀
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a27f41 and 3278b91.

📒 Files selected for processing (2)
  • .github/workflows/addon-deploy.yaml (1 hunks)
  • .github/workflows/base-deploy.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/base-deploy.yaml
  • .github/workflows/addon-deploy.yaml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@slonopotamus
Copy link
Author

Hmm... CI complains that my PR doesn't have labels. But I do not have permissions to add labels =/

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

♻️ Duplicate comments (1)
.github/workflows/addon-deploy.yaml (1)

140-146: Same outputs/load issue as in base workflow

Replicate the fix here to ensure Zstd compression really applies and to avoid redundant local image loading.

-          load: true
-          push: true
-          outputs: type=image,compression=zstd
+          push: true
+          outputs: type=registry,compression=zstd

Without this adjustment the published add-on images will still be gzip-compressed and the job will spend time loading an image it no longer needs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be9a800 and b131bef.

📒 Files selected for processing (2)
  • .github/workflows/addon-deploy.yaml (1 hunks)
  • .github/workflows/base-deploy.yaml (1 hunks)

Comment on lines 105 to 132
- name: 🚀 Build & Push
uses: docker/build-push-action@v6.18.0
with:
load: true
push: true
outputs: type=image,compression=zstd
# yamllint disable rule:line-length
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

outputs should use type=registry; current value silently disables Zstd compression

compression=zstd is only honoured when the output type is registry (or oci); with type=image Buildx falls back to an OCI layout on disk and the pushed layers remain gzip-compressed.
Additionally, load: true forces an extra, unneeded local load which increases runner I/O time and cache size now that the explicit docker push step is gone.

-          load: true
-          push: true
-          outputs: type=image,compression=zstd
+          push: true
+          outputs: type=registry,compression=zstd

This keeps the job fast, avoids the extra local artefact, and actually produces Zstd-compressed layers on GHCR.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: 🚀 Build & Push
uses: docker/build-push-action@v6.18.0
with:
load: true
push: true
outputs: type=image,compression=zstd
# yamllint disable rule:line-length
- name: 🚀 Build & Push
uses: docker/build-push-action@v6.18.0
with:
push: true
outputs: type=registry,compression=zstd
# yamllint disable rule:line-length
🤖 Prompt for AI Agents
In .github/workflows/base-deploy.yaml around lines 105 to 111, the docker
build-push-action uses outputs with type=image and compression=zstd, but
compression=zstd only works with type=registry or oci. Change outputs to use
type=registry to enable Zstd compression. Also, remove load: true to avoid
unnecessary local loading and reduce runner I/O and cache size since the push
step is already handled.

@slonopotamus slonopotamus force-pushed the zstd branch 3 times, most recently from 6f6471e to 0a5c7fb Compare July 20, 2025 15:06
with:
load: true
outputs:
- type=image,oci-mediatypes=true,compression=zstd,push=true
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to combine pushing.

The reason for this is caching. If a push fails, we still have the cache, hence it is a separate step right after cleanup.

Please revert that (also unrelated to this PR) change.

../Frenck

Copy link
Author

Choose a reason for hiding this comment

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

Okay. I'll need to think how to avoid copy-pasting all args passed to build-push-action between build and push steps...

Copy link
Author

@slonopotamus slonopotamus Jul 21, 2025

Choose a reason for hiding this comment

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

It seems I can't because GitHub Actions does not support YAML anchors: actions/runner#1182

@frenck Do you want me to copy-paste the whole thing so the only difference will be load: for build step vs outputs: for push step?

Copy link
Author

Choose a reason for hiding this comment

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

Do you want me to copy-paste the whole thing so the only difference will be load: for build step vs outputs: for push step?

Updated PR with these changes...

@slonopotamus slonopotamus force-pushed the zstd branch 2 times, most recently from 1a27f41 to 2471b3a Compare July 21, 2025 13:14
Comment on lines -174 to -179
# yamllint disable rule:line-length
run: |
docker push \
"ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.environment }}"
docker push \
"ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.version }}"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not following why this part needs to go?

Copy link
Author

Choose a reason for hiding this comment

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

Because push is done through outputs: parameter to docker/build-push-action step.

Comment on lines +174 to +182
uses: docker/build-push-action@v6.18.0
with:
outputs: type=image,oci-mediatypes=true,compression=zstd,push=true
# yamllint disable rule:line-length
tags: |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.environment }}
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.version }}
# yamllint enable rule:line-length
context: ${{ needs.information.outputs.target }}
Copy link
Member

Choose a reason for hiding this comment

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

We do not need to build it again, this step only pushes out the tags.

Copy link
Author

@slonopotamus slonopotamus Jul 21, 2025

Choose a reason for hiding this comment

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

Yes, but I need to invoke docker/build-push-action with outputs: flag. So I need to pass it list of tags, build context and etc. Otherwise, it will build and push something different.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe you want to revise your decision about splitting build and push? That would remove lots of copy-pasting. Is it really a common case when build succeeds but pushing fails and you still want to save the cache?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but I need to invoke docker/build-push-action with outputs: flag.

We can use docker directly.

Maybe you want to revise your decision about splitting build and push?

Nope. I explained the reasoning earlier. I think think being able to really on cache is better than the speed bump added in this PR.

It is a nice improvement, but not something I think is important enough to drop other things for. In the end, if this really was the best and critical option, it would have been the default in Docker.

Copy link
Author

Choose a reason for hiding this comment

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

We can use docker directly.

docker push doesn't allow configuring compression method, that's why I have to go the route I went.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, I am going to friendly decline this contribution. Honestly, the juice is not worth the squeeze imho.

Especially, since it doesn’t solve an actual issue we are experiencing.

Nevertheless, thanks for being willing to contribute.

../Frenck

@frenck frenck closed this Jul 27, 2025
@slonopotamus slonopotamus deleted the zstd branch July 27, 2025 09:04
@github-actions github-actions bot locked and limited conversation to collaborators Jul 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants