Skip to content

Conversation

@osmman
Copy link
Collaborator

@osmman osmman commented May 7, 2025

Uses go generate feature to copy images.env into embed folder. Which content will be added into embeded file system.

Summary by Sourcery

Refactor the images configuration to use config/default/images.env as the single source of truth, leveraging go generate to manage the embedded configuration

Bug Fixes:

  • Ensured consistent images configuration across different build and deployment processes

Enhancements:

  • Moved images configuration from internal/images to config/default directory
  • Implemented go generate to copy images.env into embedded filesystem

Chores:

  • Updated workflow files to reference new images.env location
  • Modified Makefile and Dockerfile to support new configuration approach

@sourcery-ai
Copy link

sourcery-ai bot commented May 7, 2025

Reviewer's Guide

This PR refactors image configuration to use config/default/images.env as the single source of truth. This file's content is copied via go:generate into internal/images/embed/ and then embedded into the Go binary using go:embed. Build scripts, CI workflows, and the Dockerfile are updated to support this new approach and ensure go generate is executed.

Sequence Diagram: Runtime Loading of Embedded Image Configuration

sequenceDiagram
    participant RT as Go Runtime
    participant INIT as images.init()
    participant FS as embed.FS (content)
    participant PCF as parseConfigFile()
    participant REG as images.Registry

    RT->>+INIT: Executes package initialization
    INIT->>+FS: ReadFile("embed/images.env")
    FS-->>-INIT: []byte (fileData), error
    Note right of INIT: if err != nil, panic(err)
    INIT->>+PCF: parseConfigFile(fileData)
    PCF->>PCF: Creates bytes.NewReader(fileData)
    PCF->>PCF: Creates bufio.NewScanner(reader)
    PCF->>PCF: Scans lines & parses key-value pairs
    PCF-->>-INIT: map[Image]string (data), error
    Note right of INIT: if err != nil, panic(err)
    INIT->>+REG: Populate(data)
    REG-->>-INIT: 
    INIT-->>-RT: Initialization complete
Loading

File-Level Changes

Change Details Files
Established a new single source of truth for image definitions from an external .env file, embedding its content into the application using go:generate for copying and go:embed for inclusion.
  • Added go:generate and go:embed directives in the image handling Go module to manage the copying and embedding of the external image definition file.
  • Updated image handling Go code to read the embedded image file from an embed.FS and parse its []byte content.
  • Deleted the previous internally stored image definition file, as its content is now generated from the new external source.
  • Modified build scripts (Makefile, Dockerfile) and CI workflows to reference the new external .env file as the primary source for image definitions (e.g., for sed operations, cat commands, and COPY instructions).
  • Removed a Makefile rule that previously propagated the old internal image file.
internal/images/images.go
internal/images/images.env
Makefile
.github/workflows/main.yml
Dockerfile
Integrated the go generate command into build and CI processes to ensure the image definition file is correctly prepared before application build.
  • Added go generate ./... to the main generate target in the Makefile.
  • Included a RUN go generate ./... step in the Dockerfile build sequence.
  • Updated specific make commands in GitHub Actions workflows to include the generate target, ensuring image files are prepared.
Makefile
Dockerfile
.github/workflows/main.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@openshift-ci openshift-ci bot requested review from JasonPowr and bouskaJ May 7, 2025 13:14
@openshift-ci openshift-ci bot added the approved label May 7, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @osmman - I've reviewed your changes - here's some feedback:

  • Consider directly embedding ../../config/default/images.env (e.g., into a []byte) to simplify the embedding mechanism, as this would remove the go:generate cp step and the intermediate embed/ directory.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Uses go generate feature to copy images.env into embed folder.
Which content will be added into embeded file system.

Signed-off-by: Tomas Turek <tturek@redhat.com>
@osmman osmman force-pushed the tturek/refactor-images branch from b5397f6 to 41357da Compare May 9, 2025 09:01
Copy link
Contributor

@JasonPowr JasonPowr left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented May 9, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JasonPowr, osmman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit f808d24 into main May 9, 2025
20 checks passed
@openshift-merge-bot openshift-merge-bot bot deleted the tturek/refactor-images branch May 9, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants