Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions workspaces/x2a/plugins/x2a/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
],
"supported-versions": "1.49.4"
},
"scalprum": {
"name": "red-hat-developer-hub.backstage-plugin-x2a",
"exposedModules": {
"PluginRoot": "./src/index.ts"
}
},
"sideEffects": false,
"scripts": {
"start": "backstage-cli package start",
Expand Down
75 changes: 67 additions & 8 deletions workspaces/x2a/scripts/build-dynamic-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#
# Build x2a dynamic plugins and package them as OCI images.
#
# Usage: ./scripts/build-dynamic-plugins.sh [--push] [--tag <tag>] [--registry <registry>] [--report]
# Usage: ./scripts/build-dynamic-plugins.sh [--plugin <dir>] [--push] [--tag <tag>] [--registry <registry>] [--report]
#
# Options:
# --plugin <dir> Build/package only one plugin (e.g. x2a)
# --push Push built images to the registry after packaging
# --tag <tag> Additional tag to apply to images (e.g., nightly, latest)
# --registry <registry> Image registry prefix (default: quay.io/x2ansible)
Expand All @@ -24,7 +25,10 @@

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKSPACE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
RHDH_CLI_VERSION="${RHDH_CLI_VERSION:-2.1.2}"
RHDH_CLI_VERSION="${RHDH_CLI_VERSION:-1.10.8}"
RHDH_CLI_WEBPACK_VERSION="${RHDH_CLI_WEBPACK_VERSION:-5.105.4}"
RHDH_CLI_PREFIX="${XDG_CACHE_HOME:-${HOME}/.cache}/x2a-rhdh-cli/${RHDH_CLI_VERSION}-webpack-${RHDH_CLI_WEBPACK_VERSION}"
RHDH_CLI_BIN="${RHDH_CLI_PREFIX}/node_modules/@red-hat-developer-hub/cli/bin/rhdh-cli"
EMBED_COMMON="@red-hat-developer-hub/backstage-plugin-x2a-common"
EMBED_NODE="@red-hat-developer-hub/backstage-plugin-x2a-node"
IMAGE_REGISTRY="quay.io/x2ansible"
Expand All @@ -40,6 +44,12 @@
["x2a-mcp-extras"]="${EMBED_COMMON} ${EMBED_NODE}"
)

declare -A PLUGIN_EXPORT_ARGS=(
["x2a"]="--no-generate-module-federation-assets"
["x2a-dcr"]="--no-generate-module-federation-assets"
)
SELECTED_PLUGINS=()

declare -A PLUGIN_IMAGES=(
["x2a"]="red-hat-developer-hub-backstage-plugin-x2a"
["x2a-backend"]="red-hat-developer-hub-backstage-plugin-x2a-backend"
Expand All @@ -58,7 +68,7 @@

check_prerequisites() {
local missing=()
for cmd in node yarn npx podman; do
for cmd in node yarn npm podman; do
if ! command -v "$cmd" &>/dev/null; then
missing+=("$cmd")
fi
Expand Down Expand Up @@ -120,6 +130,24 @@
yarn --cwd "$WORKSPACE_DIR" install
}

install_rhdh_cli() {
if [[ -x "$RHDH_CLI_BIN" ]]; then
return
fi

log "Installing RHDH CLI ${RHDH_CLI_VERSION} with Webpack ${RHDH_CLI_WEBPACK_VERSION}"
mkdir -p "$RHDH_CLI_PREFIX"
cat > "${RHDH_CLI_PREFIX}/package.json" <<EOF
{"private":true,"dependencies":{"@red-hat-developer-hub/cli":"${RHDH_CLI_VERSION}"},"overrides":{"webpack":"${RHDH_CLI_WEBPACK_VERSION}"}}
EOF
npm install --prefix "$RHDH_CLI_PREFIX" --no-audit --no-fund

if [[ ! -x "$RHDH_CLI_BIN" ]]; then
echo "ERROR: RHDH CLI was not installed at $RHDH_CLI_BIN" >&2
exit 1
fi
}

build_workspace() {
log "Building all workspace packages"
yarn --cwd "$WORKSPACE_DIR" build:all
Expand Down Expand Up @@ -152,9 +180,20 @@
embed_args+=(--embed-package "$pkg")
done

local export_args=()
if [[ -n "${PLUGIN_EXPORT_ARGS[$plugin_dir]:-}" ]]; then
read -r -a export_args <<< "${PLUGIN_EXPORT_ARGS[$plugin_dir]}"
fi

log "Exporting dynamic plugin: ${plugin_dir}"
(cd "$plugin_path" && npx "@red-hat-developer-hub/cli@${RHDH_CLI_VERSION}" plugin export \
"${embed_args[@]}")
(cd "$plugin_path" && node "$RHDH_CLI_BIN" plugin export \
--clean "${embed_args[@]}" "${export_args[@]}")

if [[ -n "${PLUGIN_EXPORT_ARGS[$plugin_dir]:-}" ]] &&
[[ ! -s "${plugin_path}/dist-dynamic/dist-scalprum/plugin-manifest.json" ]]; then
echo "ERROR: Scalprum export is missing dist-dynamic/dist-scalprum/plugin-manifest.json for ${plugin_dir}" >&2
exit 1
fi
}

package_plugin() {
Expand All @@ -166,7 +205,7 @@
local image_tag="${IMAGE_REGISTRY}/${image_name}:${version}"

log "Packaging plugin image: ${image_tag}"
(cd "$plugin_path" && npx "@red-hat-developer-hub/cli@${RHDH_CLI_VERSION}" plugin package \
(cd "$plugin_path" && node "$RHDH_CLI_BIN" plugin package \
-t "$image_tag")

if [[ -n "$CUSTOM_TAG" ]]; then
Expand Down Expand Up @@ -225,6 +264,18 @@
REPORT_ONLY=true
shift
;;
--plugin)
if [[ -z "${2:-}" ]]; then
echo "ERROR: --plugin requires a plugin directory (e.g. x2a)" >&2
exit 1
fi
if [[ -z "${PLUGIN_IMAGES[$2]:-}" ]]; then

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Assign this positional parameter to a local variable.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AaGBro-jiQv5uoYsKhrp&open=AaGBro-jiQv5uoYsKhrp&pullRequest=5398
echo "ERROR: unknown plugin: $2" >&2

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Assign this positional parameter to a local variable.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AaGBro-jiQv5uoYsKhrq&open=AaGBro-jiQv5uoYsKhrq&pullRequest=5398
exit 1
fi
SELECTED_PLUGINS+=("$2")
shift 2
;;
*)
echo "ERROR: unknown argument: $1" >&2
exit 1
Expand All @@ -244,8 +295,16 @@
check_prerequisites
install_dependencies
build_workspace
install_rhdh_cli

for plugin_dir in "${!PLUGIN_IMAGES[@]}"; do
local plugin_dirs=()
if [[ ${#SELECTED_PLUGINS[@]} -gt 0 ]]; then
plugin_dirs=("${SELECTED_PLUGINS[@]}")
else
plugin_dirs=("${!PLUGIN_IMAGES[@]}")
fi

for plugin_dir in "${plugin_dirs[@]}"; do
export_plugin "$plugin_dir"
package_plugin "$plugin_dir"
done
Expand All @@ -254,7 +313,7 @@
podman images --filter "reference=${IMAGE_REGISTRY}/*"

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