Skip to content

Conversation

@gocanto
Copy link
Collaborator

@gocanto gocanto commented Oct 13, 2025

Summary

  • gate the WebP encoder behind a CGO build-tagged helper with a stub fallback
  • expose a runtime capability check so tests skip when WebP encoding is unavailable

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_68eca1d3f9508333b65801e2e424cc15

Summary by CodeRabbit

  • New Features

    • WebP image export enabled on platforms that support native WebP encoding; containers now include required runtime support and timezone handling.
  • Bug Fixes

    • Operations explicitly report when WebP encoding is not supported, avoiding unexpected failures.
  • Tests

    • WebP-related test now auto-skips in environments without encoding support for consistent results.

@gocanto gocanto marked this pull request as draft October 13, 2025 07:05
@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Conditional WebP Encoding: The WebP encoder is now conditionally compiled based on the presence of CGO using Go build tags. When CGO is enabled, the full WebP encoding functionality is available; otherwise, a stub implementation is used.
  • CGO Dependency Decoupling: The direct dependency on the github.com/chai2010/webp library, which relies on CGO, has been moved out of the main image.go file and into a CGO-specific build file.
  • Runtime Capability Check: A new function, webpEncodeSupported(), has been introduced to allow the application to check at runtime whether WebP encoding capabilities are available (i.e., if CGO is enabled and the full encoder is compiled in).
  • Test Adaptation: The TestSaveWebP test now gracefully skips execution if WebP encoding is not supported in the current build environment (e.g., when CGO is disabled), preventing test failures in such configurations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds 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

Cohort / File(s) Summary
Image save logic refactor
pkg/images/image.go
Remove direct chai2010/webp usage; delegate ".webp" handling to encodeWebp(fh, img, quality).
WebP encoding implementation (CGO)
pkg/images/webp_encode_cgo.go
Add CGO-backed encodeWebp(w io.Writer, img image.Image, quality int) error using github.com/chai2010/webp and webpEncodeSupported() bool (returns true). Build-tagged //go:build cgo.
WebP encoding stub (!cgo)
pkg/images/webp_encode_stub.go
Add non-CGO stub encodeWebp(...) error that returns a standardized error and webpEncodeSupported() bool (returns false). Build-tagged //go:build !cgo.
Tests update for conditional capability
pkg/images/image_test.go
TestSaveWebP now calls webpEncodeSupported() and skips the test when WebP encoding (CGO) is unavailable.
Dockerfile / build image
docker/dockerfile-api
Enable CGO (CGO_ENABLED=1), add build deps (build-base, pkgconf/pkgconfig, libwebp-dev) and runtime lib (libwebp), add TZ ARG and install tzdata; adjust build and final stages for CGO-enabled binaries.

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)
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I nibbled code like clover sweet,
Split CGO roots from stubby feet.
If WebP hops in, I'll paint it bright—
If not, I skip and save the night.
Thump-thump! The build keeps bouncing light. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly describes the main purpose of the changeset by focusing on handling WebP encoding in scenarios without CGO support and concisely indicates a fix. It aligns with the PR objectives of gating WebP encoding and providing a fallback stub when CGO is unavailable. The prefix “fix:” follows conventional commit style without introducing noise or ambiguity.

📜 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 6e901d7 and 296b715.

📒 Files selected for processing (1)
  • docker/dockerfile-api (4 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

@gocanto gocanto marked this pull request as ready for review October 13, 2025 07:08
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: 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-r0

Note: 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-r0

Note: 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

📥 Commits

Reviewing files that changed from the base of the PR and between f086cb2 and 6e901d7.

📒 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.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f086cb2 and 6e901d7.

📒 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=1 allows 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.

@gocanto gocanto marked this pull request as draft October 13, 2025 07:27
@gocanto gocanto removed the codex label Oct 13, 2025
@gocanto gocanto changed the title Handle WebP encoding without CGO dependency fix: Handle WebP encoding without CGO dependency Oct 13, 2025
@gocanto
Copy link
Collaborator Author

gocanto commented Oct 13, 2025

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

@gocanto gocanto marked this pull request as ready for review October 13, 2025 07:38
@gocanto gocanto merged commit 361e5c6 into main Oct 13, 2025
1 of 2 checks passed
@gocanto gocanto deleted the gus/fix-webp-package-undefined-errors-2025-10-13 branch October 13, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants