Skip to content
Draft
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
196 changes: 196 additions & 0 deletions .ci/pipelines/jobs/ocp-disconnected-helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#!/bin/bash

# shellcheck source=.ci/pipelines/lib/log.sh
source "$DIR"/lib/log.sh
# shellcheck source=.ci/pipelines/lib/common.sh
source "$DIR"/lib/common.sh
# shellcheck source=.ci/pipelines/utils.sh
source "$DIR"/utils.sh
# shellcheck source=.ci/pipelines/lib/testing.sh
source "$DIR"/lib/testing.sh
# shellcheck source=.ci/pipelines/playwright-projects.sh
source "$DIR"/playwright-projects.sh
# shellcheck source=.ci/pipelines/lib/disconnected.sh
source "$DIR"/lib/disconnected.sh

export INSTALL_METHOD="helm"

handle_ocp_disconnected_helm() {
export NAME_SPACE="${NAME_SPACE:-showcase-ci-disconnected}"

disconnected::require_env
disconnected::setup_auth

common::oc_login

K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//')
export K8S_CLUSTER_ROUTER_BASE

# --- Section A: Install oc-mirror ---
log::section "oc-mirror Setup"

disconnected::install_oc_mirror || {
log::error "Failed to install oc-mirror — aborting"
return 1
}

# --- Section B: Resolve chart source and pull locally ---
log::section "Chart Resolution"

local is_ga="false"
if [[ "${IMAGE_REGISTRY}" == "registry.redhat.io" ]]; then
is_ga="true"
fi

if [[ "${is_ga}" == "true" ]]; then
# GA: pull chart from charts.openshift.io
helm repo add openshift-helm-charts https://charts.openshift.io 2> /dev/null || true
helm repo update openshift-helm-charts
log::info "Pulling GA chart from charts.openshift.io (version: ${RELEASE_VERSION})"
helm pull openshift-helm-charts/redhat-developer-hub \
--version "${RELEASE_VERSION}" \
-d "${DISCONNECTED_TMPDIR}" || {
log::error "Failed to pull chart from charts.openshift.io"
return 1
}
else
# CI/upstream: pull chart from OCI registry
log::info "Pulling CI chart from ${HELM_CHART_URL} (version: ${CHART_VERSION})"
helm pull "${HELM_CHART_URL}" --version "${CHART_VERSION}" \
-d "${DISCONNECTED_TMPDIR}" || {
log::error "Failed to pull chart from ${HELM_CHART_URL}"
return 1
}
fi

CHART_LOCAL_TGZ=$(find "${DISCONNECTED_TMPDIR}" -maxdepth 1 -name '*.tgz' | head -1)
export CHART_LOCAL_TGZ

if [[ -z "${CHART_LOCAL_TGZ}" ]]; then
log::error "No chart .tgz found in ${DISCONNECTED_TMPDIR}"
return 1
fi
log::success "Chart pulled: ${CHART_LOCAL_TGZ}"

# --- Section C: Resolve PostgreSQL image from chart ---
local helm_values
helm_values=$(helm show values "${CHART_LOCAL_TGZ}" 2> /dev/null || true)

export PG_REGISTRY PG_REPO PG_TAG
PG_REGISTRY=$(echo "${helm_values}" | yq '.upstream.postgresql.image.registry' || true)
PG_REPO=$(echo "${helm_values}" | yq '.upstream.postgresql.image.repository' || true)
PG_TAG=$(echo "${helm_values}" | yq '.upstream.postgresql.image.tag' || true)
PG_REGISTRY="${PG_REGISTRY:-registry.redhat.io}"
PG_REPO="${PG_REPO:-rhel9/postgresql-15}"
PG_TAG="${PG_TAG:-latest}"

log::info "PostgreSQL image from chart: ${PG_REGISTRY}/${PG_REPO}:${PG_TAG}"

# --- Section D: Build ImageSetConfiguration ---
log::section "Image Mirroring"

local imageset_config="${DISCONNECTED_TMPDIR}/imageset-config.yaml"
disconnected::build_imageset_config "${imageset_config}" || {
log::error "Failed to build ImageSetConfiguration"
return 1
}

# --- Section E: Run oc-mirror ---
local workspace="${DISCONNECTED_TMPDIR}/oc-mirror-workspace"
disconnected::run_oc_mirror "${imageset_config}" "${workspace}" || {
log::error "oc-mirror failed — aborting"
return 1
}

# --- Section F: Patch and apply IDMS ---
log::section "Cluster Resources"

disconnected::patch_idms "${OC_MIRROR_IDMS_FILE}"

oc apply -f "${OC_MIRROR_IDMS_FILE}" || {
log::error "Failed to apply IDMS — aborting"
return 1
}
log::success "ImageDigestMirrorSet applied"

if [[ -n "${OC_MIRROR_ITMS_FILE:-}" ]]; then
oc apply -f "${OC_MIRROR_ITMS_FILE}" || {
log::error "Failed to apply ITMS — aborting"
return 1
}
log::success "ImageTagMirrorSet applied"
fi

# --- Section G: Plugin mirroring ---
log::section "Plugin Mirroring"

disconnected::fetch_script "mirror-plugins.sh" "${DISCONNECTED_TMPDIR}/mirror-plugins.sh" || {
log::error "Failed to fetch mirror-plugins.sh — aborting"
return 1
}

local plugin_index="oci://registry.access.redhat.com/rhdh/plugin-catalog-index:${RELEASE_VERSION}"
if [[ -n "${CATALOG_INDEX_IMAGE:-}" ]]; then
plugin_index="oci://${CATALOG_INDEX_IMAGE}"
fi

bash "${DISCONNECTED_TMPDIR}/mirror-plugins.sh" \
--plugin-index "${plugin_index}" \
--to-registry "${MIRROR_REGISTRY_URL}" || {
log::error "mirror-plugins.sh failed — aborting"
return 1
}

# --- Section H: Namespace + registries.conf ConfigMap ---
namespace::configure "${NAME_SPACE}"

envsubst < "${DIR}/resources/disconnected/plugin-mirror-configmap.yaml" \
| oc apply -n "${NAME_SPACE}" -f - || {
log::error "Failed to create registries.conf ConfigMap — aborting"
return 1
}
log::success "ConfigMap rhdh-plugin-mirror-conf created in ${NAME_SPACE}"

# --- Section I: Helm deployment from mirrored chart ---
log::section "Helm Deployment"

# Prefer the chart from oc-mirror workspace, fall back to the pulled tgz
local chart_install_path
chart_install_path="${OC_MIRROR_CHART_PATH:-${CHART_LOCAL_TGZ}}"
log::info "Installing chart from: ${chart_install_path}"

local helm_set_flags=(
--set global.clusterRouterBase="${K8S_CLUSTER_ROUTER_BASE}"
--set upstream.backstage.image.registry="${MIRROR_REGISTRY_URL}"
--set upstream.backstage.image.repository="${IMAGE_REPO}"
--set upstream.backstage.image.tag="${TAG_NAME}"
--set upstream.postgresql.image.registry="${MIRROR_REGISTRY_URL}"
)

if [[ -n "${CATALOG_INDEX_IMAGE:-}" ]]; then
helm_set_flags+=(
--set global.catalogIndex.image.registry="${MIRROR_REGISTRY_URL}"
--set global.catalogIndex.image.repository="${CATALOG_INDEX_REPO}"
--set global.catalogIndex.image.tag="${CATALOG_INDEX_TAG}"
)
fi

helm upgrade -i "${RELEASE_NAME}" -n "${NAME_SPACE}" \
"${chart_install_path}" \
-f "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" \
-f "${DIR}/resources/disconnected/helm-overrides.yaml" \
"${helm_set_flags[@]}" || {
log::error "Helm deployment failed"
return 1
}

log::success "RHDH deployed via Helm with mirrored images"

# --- Section J: Smoke test ---
log::section "Smoke Test"

local url="https://${RELEASE_NAME}-developer-hub-${NAME_SPACE}.${K8S_CLUSTER_ROUTER_BASE}"
testing::check_and_test "${RELEASE_NAME}" "${NAME_SPACE}" "${PW_PROJECT_SMOKE_TEST}" "${url}"

log::success "Disconnected Helm smoke test completed"
}
129 changes: 129 additions & 0 deletions .ci/pipelines/jobs/ocp-disconnected-operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

# shellcheck source=.ci/pipelines/lib/log.sh
source "$DIR"/lib/log.sh
# shellcheck source=.ci/pipelines/lib/common.sh
source "$DIR"/lib/common.sh
# shellcheck source=.ci/pipelines/utils.sh
source "$DIR"/utils.sh
# shellcheck source=.ci/pipelines/install-methods/operator.sh
source "$DIR"/install-methods/operator.sh
# shellcheck source=.ci/pipelines/lib/testing.sh
source "$DIR"/lib/testing.sh
# shellcheck source=.ci/pipelines/playwright-projects.sh
source "$DIR"/playwright-projects.sh
# shellcheck source=.ci/pipelines/lib/disconnected.sh
source "$DIR"/lib/disconnected.sh

export INSTALL_METHOD="operator"

handle_ocp_disconnected_operator() {
export NAME_SPACE="${NAME_SPACE:-showcase-disconnected}"

disconnected::require_env
disconnected::setup_auth

common::oc_login

K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//')
export K8S_CLUSTER_ROUTER_BASE

# --- Section A: Operator Mirroring + Installation ---
# Uses prepare-restricted-environment.sh from rhdh-operator, which handles
# mirroring operator/operand images and installing the operator CatalogSource.
log::section "Operator Mirroring and Installation"

disconnected::fetch_script "prepare-restricted-environment.sh" "${DISCONNECTED_TMPDIR}/prepare-restricted-environment.sh" \
|| {
log::error "Failed to fetch prepare-restricted-environment.sh — aborting"
return 1
}

local prepare_args=(
--to-registry "${MIRROR_REGISTRY_URL}"
--filter-versions "${RELEASE_VERSION}"
)
if [[ -n "${CATALOG_INDEX_IMAGE:-}" ]]; then
prepare_args=(
--to-registry "${MIRROR_REGISTRY_URL}"
--index-image "${CATALOG_INDEX_IMAGE}"
--ci-index true
--filter-versions "${RELEASE_VERSION}"
)
fi

bash "${DISCONNECTED_TMPDIR}/prepare-restricted-environment.sh" "${prepare_args[@]}" \
|| {
log::error "prepare-restricted-environment.sh failed — aborting"
return 1
}
log::success "Operator installed via prepare-restricted-environment.sh"

# --- Section B: Wait for Operator CRD ---
k8s_wait::crd "backstages.rhdh.redhat.com" 300 10 || {
log::error "Backstage CRD not available after operator installation"
return 1
}

# --- Section C: Plugin Mirroring ---
log::section "Plugin Mirroring"

disconnected::fetch_script "mirror-plugins.sh" "${DISCONNECTED_TMPDIR}/mirror-plugins.sh" \
|| {
log::error "Failed to fetch mirror-plugins.sh — aborting"
return 1
}

local plugin_index="oci://registry.access.redhat.com/rhdh/plugin-catalog-index:${RELEASE_VERSION}"
if [[ -n "${CATALOG_INDEX_IMAGE:-}" ]]; then
plugin_index="oci://${CATALOG_INDEX_IMAGE}"
fi

bash "${DISCONNECTED_TMPDIR}/mirror-plugins.sh" \
--plugin-index "${plugin_index}" \
--to-registry "${MIRROR_REGISTRY_URL}" || {
log::error "mirror-plugins.sh failed — aborting"
return 1
}

# --- Section D: Namespace + registries.conf ConfigMap ---
log::section "Cluster Resources"

namespace::configure "${NAME_SPACE}"

envsubst < "${DIR}/resources/disconnected/plugin-mirror-configmap.yaml" \
| oc apply -n "${NAME_SPACE}" -f - || {
log::error "Failed to create registries.conf ConfigMap — aborting"
return 1
}
log::success "ConfigMap rhdh-plugin-mirror-conf created in ${NAME_SPACE}"

# --- Section E: Backstage CR Deployment ---
log::section "Backstage CR Deployment"

local rendered_cr
rendered_cr=$(envsubst < "${DIR}/resources/rhdh-operator/rhdh-start.yaml")
rendered_cr=$(echo "$rendered_cr" | yq eval \
'.spec.application.extraFiles.configMaps = [
{
"name": "rhdh-plugin-mirror-conf",
"key": "rhdh-registries.conf",
"mountPath": "/etc/containers/registries.conf.d",
"containers": ["install-dynamic-plugins"]
}
]' -)

local cr_temp="${DISCONNECTED_TMPDIR}/backstage-cr-disconnected.yaml"
echo "$rendered_cr" > "${cr_temp}"

deploy_rhdh_operator "${NAME_SPACE}" "${cr_temp}"
log::success "Backstage CR deployed in ${NAME_SPACE}"

# --- Section F: Smoke Test ---
log::section "Smoke Test"

local url="https://backstage-${RELEASE_NAME}-${NAME_SPACE}.${K8S_CLUSTER_ROUTER_BASE}"
testing::check_and_test "${RELEASE_NAME}" "${NAME_SPACE}" "${PW_PROJECT_SMOKE_TEST}" "${url}"

log::success "Disconnected Operator smoke test completed"
}
Loading
Loading