Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions workspaces/x2a/scripts/build-dynamic-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#
# Build x2a dynamic plugins and package them as OCI images.
#
# Usage: ./scripts/build-dynamic-plugins.sh
# Usage: ./scripts/build-dynamic-plugins.sh [--push]
#
# Produces two OCI images:
# Options:
# --push Push built images to the registry after packaging
#
# Produces OCI images:
# quay.io/x2ansible/red-hat-developer-hub-backstage-plugin-x2a:<version>
# quay.io/x2ansible/red-hat-developer-hub-backstage-plugin-x2a-backend:<version>
#
Expand All @@ -16,6 +19,7 @@
RHDH_CLI_VERSION="1.9.1"
EMBED_PACKAGE="@red-hat-developer-hub/backstage-plugin-x2a-common"
IMAGE_REGISTRY="quay.io/x2ansible"
PUSH_IMAGES=false

declare -A PLUGIN_IMAGES=(
["x2a"]="red-hat-developer-hub-backstage-plugin-x2a"
Expand Down Expand Up @@ -98,14 +102,34 @@
log "Packaging plugin image: ${image_tag}"
(cd "$plugin_path" && npx "@red-hat-developer-hub/cli@${RHDH_CLI_VERSION}" plugin package \
-t "$image_tag")
}

push_plugin() {

Check warning on line 107 in workspaces/x2a/scripts/build-dynamic-plugins.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add an explicit return statement at the end of the function.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZy6x1mPlHQ-rS5qhf2w&open=AZy6x1mPlHQ-rS5qhf2w&pullRequest=2453
local plugin_dir="$1"
local image_name="${PLUGIN_IMAGES[$plugin_dir]}"
local version
version="$(get_plugin_version "$plugin_dir")"
local image_tag="${IMAGE_REGISTRY}/${image_name}:${version}"

log "Pushing image: ${image_tag}"
podman push "$image_tag"
Comment on lines +107 to +115

Choose a reason for hiding this comment

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

Action required

1. Hardcoded push registry 🐞 Bug ⛨ Security

With --push, the script always pushes to the hardcoded quay.io/x2ansible registry/org, making it
easy for forks/CI to publish to the wrong place and impossible to redirect without editing the
script.
Agent Prompt
### Issue description
`--push` always publishes to `quay.io/x2ansible` because `IMAGE_REGISTRY` is hardcoded. This is risky in forks/CI and prevents pushing to test registries.

### Issue Context
The script already tags images with `${IMAGE_REGISTRY}/...` and `--push` simply runs `podman push` for those tags.

### Fix Focus Areas
- workspaces/x2a/scripts/build-dynamic-plugins.sh[19-29]
- workspaces/x2a/scripts/build-dynamic-plugins.sh[122-129]
- workspaces/x2a/scripts/build-dynamic-plugins.sh[107-116]

### Suggested change
- Change to `IMAGE_REGISTRY="${IMAGE_REGISTRY:-quay.io/x2ansible}"` (env override).
- Extend `parse_args` to support `--registry <value>` (or `--image-registry <value>`), validate non-empty.
- (Optional safety) If `--push` is set and `IMAGE_REGISTRY` is still the default, require a `--confirm-upstream` flag or print a prominent warning and ask for confirmation (only if interactive).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

}

# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------

parse_args() {

Check warning on line 122 in workspaces/x2a/scripts/build-dynamic-plugins.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add an explicit return statement at the end of the function.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZy6x1mPlHQ-rS5qhf2x&open=AZy6x1mPlHQ-rS5qhf2x&pullRequest=2453
for arg in "$@"; do
case "$arg" in
--push) PUSH_IMAGES=true ;;
*) echo "ERROR: unknown argument: $arg" >&2; exit 1 ;;
esac
done
}

main() {
parse_args "$@"
check_prerequisites
install_dependencies
build_workspace
Expand All @@ -117,6 +141,13 @@

log "Done. Images built:"
podman images --filter "reference=${IMAGE_REGISTRY}/*"

if [[ "$PUSH_IMAGES" == true ]]; then
for plugin_dir in "${!PLUGIN_IMAGES[@]}"; do
push_plugin "$plugin_dir"
done
log "All images pushed."
fi
}

main "$@"