-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Handle WebP encoding without CGO dependency #132
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
fix: Handle WebP encoding without CGO dependency #132
Conversation
Summary of ChangesHello @gocanto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the WebP image encoding mechanism to decouple it from a direct CGO dependency. It introduces a build-tag-based approach, providing a functional WebP encoder when CGO is available and a graceful fallback (stub) when it's not. This change improves flexibility for environments where CGO might be restricted or undesirable, ensuring the application can still compile and run, albeit with limited WebP encoding capabilities in CGO-disabled contexts. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Caution Review failedThe pull request is closed. Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds CGO-gated WebP encoding and a non-CGO stub, refactors image saving to delegate ".webp" writes to encodeWebp(...), updates tests to skip WebP encoding when unsupported, and adjusts the Dockerfile to enable CGO and include libwebp system packages. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Images as images.Save
participant Helper as encodeWebp
participant CGO as CGO WebP (chai2010/webp)
participant Stub as No-CGO Stub
Caller->>Images: Save(path=".webp", img, quality)
alt extension == ".webp"
Images->>Helper: encodeWebp(writer, img, quality)
alt built with cgo
Helper->>CGO: webp.Encode(writer, img, options{Quality})
CGO-->>Helper: result (nil / error)
else !cgo
Helper-->>Stub: return error "webp encoding requires cgo"
end
Helper-->>Images: result (nil / error)
else other extension
Images-->>Caller: use existing encoders
end
Images-->>Caller: result (nil / error)
sequenceDiagram
autonumber
participant Test as TestSaveWebP
participant Cap as webpEncodeSupported
participant Images as images.Save
Test->>Cap: webpEncodeSupported()
alt unsupported
Test-->>Test: t.Skip("webp encoding requires cgo")
else supported
Test->>Images: Save(".webp", img, quality)
Images-->>Test: result (nil / error)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively isolates the CGO-dependent WebP encoding functionality using build tags. This is a great approach to allow the package to be built in environments without CGO. The changes are well-structured, with separate files for the CGO and non-CGO implementations, and a corresponding check in the tests to skip WebP encoding tests when unsupported. I have one minor suggestion to improve the stub implementation to adhere to Go conventions.
There was a problem hiding this 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
🧹 Nitpick comments (2)
docker/dockerfile-api (2)
44-48: Consider pinning package versions for reproducibility.The system dependencies are installed without version constraints, which could lead to non-reproducible builds or introduce vulnerabilities if package versions change. While Alpine's package ecosystem is relatively stable, pinning versions improves build reproducibility and security posture.
Example:
-RUN apk add --no-cache \ - build-base \ - pkgconfig \ - libwebp-dev +RUN apk add --no-cache \ + build-base=0.5-r3 \ + pkgconfig=2.3.0-r0 \ + libwebp-dev=1.4.0-r0Note: Use
apk info <package>to determine the currently available version in alpine:3.22.
98-99: Runtime libwebp is correctly included, but consider version pinning.The libwebp library is necessary at runtime for the CGO-enabled binary to function. However, similar to the builder stage, the package is not version-pinned, which could affect reproducibility.
Consider pinning the version:
-RUN apk add --no-cache tzdata libwebp +RUN apk add --no-cache tzdata=2025a-r0 libwebp=1.4.0-r0Note: Ensure the libwebp version matches between builder and runtime stages to avoid ABI incompatibilities.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docker/dockerfile-api(3 hunks)pkg/images/webp_encode_stub.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/images/webp_encode_stub.go
🔇 Additional comments (2)
docker/dockerfile-api (2)
54-54: LGTM!Enabling CGO is necessary for the WebP encoding support introduced in this PR. The change is correct and aligns with the PR objectives.
69-79: LGTM!The build command is correctly configured to compile with CGO enabled. The updated comment clearly explains why CGO is necessary, and the build flags are appropriate.
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docker/dockerfile-api(3 hunks)pkg/images/webp_encode_stub.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/images/webp_encode_stub.go
🔇 Additional comments (3)
docker/dockerfile-api (3)
44-48: LGTM! Correct dependencies for CGO and libwebp.The system dependencies are appropriate:
build-base: Provides gcc, g++, make, and other tools required for CGO compilation.pkgconfig: Locates library headers and linking flags.libwebp-dev: Development headers and libraries for WebP encoding.
54-54: LGTM! CGO correctly enabled.Setting
CGO_ENABLED=1allows Go to link with C libraries, which is necessary for WebP encoding via libwebp.
75-79: LGTM! Build command correctly configured.The build command properly compiles with CGO enabled, applying the necessary build tags and linker flags.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting |
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68eca1d3f9508333b65801e2e424cc15
Summary by CodeRabbit
New Features
Bug Fixes
Tests