Skip to content

Adding Build and Push Script#12

Open
shekhar316 wants to merge 3 commits intokruize:mvp_demofrom
shekhar316:scheduler
Open

Adding Build and Push Script#12
shekhar316 wants to merge 3 commits intokruize:mvp_demofrom
shekhar316:scheduler

Conversation

@shekhar316
Copy link
Copy Markdown
Contributor

@shekhar316 shekhar316 commented Mar 31, 2026

PR Description: Adding build_and_push.sh Script

Summary

Added the build_and_push.sh script to support flexible command-line parameters for building and pushing container images, making it more versatile for different deployment scenarios.

Parameters Added

Flag Description Default Value
-i Full image name (registry/repository:tag) quay.io/rh-ee-shesaxen/optimizer:0.1_mvp
-t Image tag (used when -i is not provided) 0.1_mvp
-b Build image (true/false) true
-p Push image (true/false) true
-h Show help message -

Usage Examples

Use full image name

./build_and_push.sh -i quay.io/myuser/kruize-optimizer:1.0.0 -b true -p true

Use custom tag with default registry/repository

./build_and_push.sh -t 0.1_mvp -p false

Use all defaults

./build_and_push.sh

Build only (no push)

./build_and_push.sh -t 1.0.0 -b true -p false

Summary by Sourcery

Build:

  • Introduce a configurable build_and_push.sh helper script to build and push container images to a container registry.

Signed-off-by: Shekhar Saxena <shekhar.saxena@ibm.com>
Signed-off-by: Shekhar Saxena <shekhar.saxena@ibm.com>
@shekhar316 shekhar316 added this to the Kruize 0.10.0 Release milestone Mar 31, 2026
@shekhar316 shekhar316 self-assigned this Mar 31, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 31, 2026

Reviewer's Guide

Adds a Bash helper script to build and optionally push a Quarkus-based container image using the Maven wrapper and Jib extension, with configurable image name, tag, build, and push flags.

Sequence diagram for build_and_push.sh image build and push flow

sequenceDiagram
    actor Developer
    participant Script as build_and_push_sh
    participant Maven as mvnw_Maven
    participant QuarkusJib as Quarkus_Jib
    participant Registry as Container_Registry

    Developer->>Script: Execute with options (-i, -t, -b, -p)
    Script->>Script: Parse arguments with getopts
    Script->>Script: Resolve IMAGE_NAME and QUARKUS_PLATFORMS
    Script->>Maven: ./mvnw clean package with Quarkus Jib properties
    Maven->>QuarkusJib: Invoke container image build

    alt QUARKUS_BUILD is true
        QuarkusJib->>QuarkusJib: Build container image for platforms
    else QUARKUS_BUILD is false
        QuarkusJib->>QuarkusJib: Skip image build
    end

    alt QUARKUS_PUSH is true
        QuarkusJib->>Registry: Push image IMAGE_NAME
    else QUARKUS_PUSH is false
        QuarkusJib->>QuarkusJib: Keep image local only
    end

    QuarkusJib-->>Maven: Build and push result
    Maven-->>Script: mvnw exit status
    Script-->>Developer: Exit with success or error code
Loading

File-Level Changes

Change Details Files
Introduce a parameterized Bash script to build and push a Quarkus container image via Maven/Jib.
  • Add CLI parsing for image name, tag, and build/push boolean flags with a usage helper
  • Default image configuration to quay.io/kruize/optimizer with tag 0.1 when no explicit image is provided
  • Configure multi-architecture build targets for linux/amd64 and linux/arm64 via QUARKUS_PLATFORMS
  • Invoke ./mvnw clean package with appropriate quarkus.container-image and quarkus.jib properties based on provided options
build_and_push.sh

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

Copy link
Copy Markdown

@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 - I've found 4 issues, and left some high level feedback:

  • Consider using set -euo pipefail and quoting variables like "$IMAGE_NAME" and "$QUARKUS_PLATFORMS" to make the script more robust against unset variables and word-splitting issues.
  • It might be helpful to validate that -b and -p only accept true/false (or a defined set of values) and fail fast with a clear error message when an invalid value is provided.
  • Rather than hardcoding QUARKUS_PLATFORMS inside the script, consider allowing it to be overridden via an environment variable or CLI flag to make the script more flexible for different build targets.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider using `set -euo pipefail` and quoting variables like `"$IMAGE_NAME"` and `"$QUARKUS_PLATFORMS"` to make the script more robust against unset variables and word-splitting issues.
- It might be helpful to validate that `-b` and `-p` only accept `true`/`false` (or a defined set of values) and fail fast with a clear error message when an invalid value is provided.
- Rather than hardcoding `QUARKUS_PLATFORMS` inside the script, consider allowing it to be overridden via an environment variable or CLI flag to make the script more flexible for different build targets.

## Individual Comments

### Comment 1
<location path="build_and_push.sh" line_range="1-2" />
<code_context>
+#!/bin/bash
+set -e
+
+# Usage function
</code_context>
<issue_to_address>
**suggestion:** Consider strengthening shell safety flags beyond `set -e`.

Since this script builds and pushes images, consider using a more defensive set of options like `set -euo pipefail` so unset variables and pipeline failures are caught explicitly. You may need to adjust any code that currently relies on undefined variables or non-critical pipeline steps succeeding.

Suggested implementation:

```
#!/bin/bash
set -euo pipefail

# Usage function

```

If the rest of the script uses any variables that may be unset (e.g., rely on them defaulting to empty), you may need to:
1. Initialize them explicitly before use, or
2. Use parameter expansion with defaults (e.g., `${VAR:-}`) where appropriate.

Also, if there are pipelines where a non-zero exit in an early command is acceptable, you may need to explicitly handle those cases (e.g., with `|| true` or restructuring the pipeline) now that `pipefail` is enabled.
</issue_to_address>

### Comment 2
<location path="build_and_push.sh" line_range="31-40" />
<code_context>
+IMAGE_NAME=""
+
+# Parse command line arguments
+while getopts "i:t:b:p:h" opt; do
+    case ${opt} in
+        i )
+            IMAGE_NAME=$OPTARG
+            ;;
+        t )
+            IMAGE_TAG=$OPTARG
+            ;;
+        b )
+            QUARKUS_BUILD=$OPTARG
+            ;;
+        p )
+            QUARKUS_PUSH=$OPTARG
+            ;;
+        h )
</code_context>
<issue_to_address>
**issue:** Validate `-b`/`-p` values to avoid surprising behavior from typos.

`-b` and `-p` are described as boolean flags, but any string is currently passed to `-Dquarkus.container-image.{build,push}` (e.g. `-b ture` would be accepted). Please restrict accepted values to `true|false` (case-normalized) and fail fast with a clear error on invalid input, or otherwise fall back to a safe default.
</issue_to_address>

### Comment 3
<location path="build_and_push.sh" line_range="13-21" />
<code_context>
+    echo "  -t TAG           Image tag (default: 0.1) - used only if -i is not provided"
+    echo "  -b BUILD         Build image true/false (default: true)"
+    echo "  -p PUSH          Push image true/false (default: true)"
+    echo "  -h               Show this help message"
+    echo ""
+    echo "Examples:"
+    echo "  $0 -i quay.io/myuser/kruize-optimizer:1.0.0 -b true -p true"
+    echo "  $0 -t 0.1_mvp -p false"
+    echo "  $0 -b true -p true"
+    echo ""
+    echo "Note: Use either -i for full image name OR -t for tag with default registry/repo"
+    exit 1
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use a success exit code when showing help via `-h`.

`usage` always exits with status 1, so a normal `-h` run is reported as an error by callers/CI. Consider distinguishing invalid usage from explicit help (e.g., accept a status argument or add a separate help function) so `-h` exits 0 while real parsing errors remain non‑zero.

Suggested implementation:

```
# Usage function
usage() {
    # Optional first argument is the desired exit code (default: 1)
    local exit_code="${1:-1}"

    echo "Usage: $0 [OPTIONS]"
    echo ""
    echo "Options:"
    echo "  -i IMAGE_NAME    Full image name (registry/repository:tag)"
    echo "  -t TAG           Image tag (default: 0.1) - used only if -i is not provided"
    echo "  -b BUILD         Build image true/false (default: true)"
    echo "  -p PUSH          Push image true/false (default: true)"
    echo "  -h               Show this help message"

    exit "${exit_code}"

```

To fully implement the behavior you described, the argument parsing logic elsewhere in `build_and_push.sh` should be updated to:
1. Call `usage 0` when handling the `-h` option (explicit help).
2. Call `usage 1` (or omit the argument and rely on the default) for invalid options or other usage errors.

For example, in a `getopts` case block you’d want something conceptually like:
- `h) usage 0 ;;`
- `\?) usage 1 ;;`
Adjust these calls in the actual option-parsing code in this script.
</issue_to_address>

### Comment 4
<location path="build_and_push.sh" line_range="60" />
<code_context>
+    IMAGE_NAME="quay.io/kruize/optimizer:${IMAGE_TAG}"
+fi
+
+QUARKUS_PLATFORMS="linux/amd64,linux/arm64"
+
+echo "Building and pushing image: ${IMAGE_NAME}..."
</code_context>
<issue_to_address>
**suggestion:** Consider making target platforms configurable instead of hard-coded.

Since the list is fixed to `linux/amd64,linux/arm64`, consider reading the platforms from a flag or environment variable (with this as the default). That would let the same script work in local dev, CI with QEMU limits, or single-arch registries without needing manual edits.

Suggested implementation:

```
# Allow overriding target platforms via environment variable; default to linux/amd64,linux/arm64
: "${QUARKUS_PLATFORMS:=linux/amd64,linux/arm64}"

```

If you want platforms to be configurable via a command-line flag as well, you’ll need to:
1. Add a new option (e.g. `-p` or `--platforms`) in the argument parsing section to set `QUARKUS_PLATFORMS`.
2. Update the `usage` function to document the new flag and mention that `QUARKUS_PLATFORMS` can also be set via environment variable.
</issue_to_address>

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.

Signed-off-by: Shekhar Saxena <shekhar.saxena@ibm.com>
@shekhar316 shekhar316 moved this to Under Review in Monitoring Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

2 participants