diff --git a/.github/workflows/publish-operators-for-e2e-tests.yml b/.github/workflows/publish-operators-for-e2e-tests.yml index 5d49cb4fc..0b54f3f45 100644 --- a/.github/workflows/publish-operators-for-e2e-tests.yml +++ b/.github/workflows/publish-operators-for-e2e-tests.yml @@ -73,6 +73,7 @@ jobs: uses: codeready-toolchain/toolchain-cicd/prepare-tools-action@master # Execute composite action using values from PR event + # Developer Sandbox Dashboard will be published too in this action - name: Publish current operator bundles for host & member based on PR event uses: codeready-toolchain/toolchain-cicd/publish-operators-for-e2e-tests@master if: ${{ github.event_name == 'pull_request_target' }} @@ -85,6 +86,7 @@ jobs: gh-head-ref: ${{ github.event.pull_request.head.ref }} # Execute composite action using values from PR event + # Developer Sandbox Dashboard will be published too in this action - name: Publish current operator bundles for host & member based on comment event uses: codeready-toolchain/toolchain-cicd/publish-operators-for-e2e-tests@master if: ${{ github.event_name == 'issue_comment' }} diff --git a/.gitignore b/.gitignore index 59408b5e7..e81cf59a6 100644 --- a/.gitignore +++ b/.gitignore @@ -339,10 +339,10 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# custom .env file for Developer Sandbox UI E2E tests +# custom .env file for Developer Sandbox Dashboard E2E tests testsupport/sandbox-ui/.env -# trace folder for Developer Sandbox UI E2E tests +# trace folder for Developer Sandbox Dashboard E2E tests trace/ # End of https://www.gitignore.io/api/go,vim,git,macos,linux,emacs,windows,eclipse,intellij+all,visualstudiocode \ No newline at end of file diff --git a/build/sandbox-ui/Dockerfile b/build/sandbox-ui/Dockerfile index 9ed1bd573..0b1635732 100644 --- a/build/sandbox-ui/Dockerfile +++ b/build/sandbox-ui/Dockerfile @@ -76,4 +76,4 @@ RUN yum install -y \ libX11-xcb && \ yum clean all -CMD ["make", "test-ui-e2e"] +CMD ["/bin/bash"] diff --git a/deploy/sandbox-ui/base/deployment.yaml b/deploy/sandbox-ui/base/deployment.yaml index e9cb04a8e..936753da3 100644 --- a/deploy/sandbox-ui/base/deployment.yaml +++ b/deploy/sandbox-ui/base/deployment.yaml @@ -2,7 +2,7 @@ kind: Deployment apiVersion: apps/v1 metadata: name: rhdh - namespace: ${SANDBOX_UI_NS} + namespace: ${DEVSANDBOX_DASHBOARD_NS} labels: app.kubernetes.io/instance: rhdh spec: diff --git a/deploy/sandbox-ui/base/route.yaml b/deploy/sandbox-ui/base/route.yaml index 19faf1ce2..0b98efa70 100644 --- a/deploy/sandbox-ui/base/route.yaml +++ b/deploy/sandbox-ui/base/route.yaml @@ -2,7 +2,7 @@ kind: Route apiVersion: route.openshift.io/v1 metadata: name: rhdh - namespace: ${SANDBOX_UI_NS} + namespace: ${DEVSANDBOX_DASHBOARD_NS} labels: app.kubernetes.io/instance: rhdh spec: diff --git a/deploy/sandbox-ui/base/service-accounts.yaml b/deploy/sandbox-ui/base/service-accounts.yaml index d1b9c0aa2..8504b2953 100644 --- a/deploy/sandbox-ui/base/service-accounts.yaml +++ b/deploy/sandbox-ui/base/service-accounts.yaml @@ -2,4 +2,4 @@ apiVersion: v1 kind: ServiceAccount metadata: name: rhdh - namespace: ${SANDBOX_UI_NS} \ No newline at end of file + namespace: ${DEVSANDBOX_DASHBOARD_NS} \ No newline at end of file diff --git a/deploy/sandbox-ui/base/service.yaml b/deploy/sandbox-ui/base/service.yaml index c16e47632..52bfad24a 100644 --- a/deploy/sandbox-ui/base/service.yaml +++ b/deploy/sandbox-ui/base/service.yaml @@ -2,7 +2,7 @@ kind: Service apiVersion: v1 metadata: name: rhdh - namespace: ${SANDBOX_UI_NS} + namespace: ${DEVSANDBOX_DASHBOARD_NS} labels: app.kubernetes.io/instance: rhdh spec: diff --git a/make/sandbox-ui.mk b/make/sandbox-ui.mk index a485e1e55..be0114cfb 100644 --- a/make/sandbox-ui.mk +++ b/make/sandbox-ui.mk @@ -1,235 +1,97 @@ -SANDBOX_UI_NS := sandbox-ui -SANDBOX_PLUGIN_IMAGE_NAME := sandbox-rhdh-plugin -TAG := latest -PLATFORM ?= linux/amd64 -RHDH_PLUGINS_TMP ?= $(TMPDIR)rhdh-plugins -AUTH_FILE := /tmp/auth.json -OPENID_SECRET_NAME=openid-sandbox-public-client-secret -PUSH_SANDBOX_IMAGE ?= false +DEVSANDBOX_DASHBOARD_NS := devsandbox-dashboard +IMAGE_PLATFORM ?= linux/amd64 +KUBECONFIG ?= $(HOME)/.kube/config +OPENID_SECRET_NAME := openid-sandbox-public-client-secret UI_ENVIRONMENT := ui-e2e-tests SSO_USERNAME_READ := $(shell if [ -n "$(CI)" ]; then cat /usr/local/sandbox-secrets/SSO_USERNAME 2>/dev/null || echo ""; else echo "${SSO_USERNAME}"; fi) SSO_PASSWORD_READ := $(shell if [ -n "$(CI)" ]; then cat /usr/local/sandbox-secrets/SSO_PASSWORD 2>/dev/null || echo ""; else echo "${SSO_PASSWORD}"; fi) -QUAY_NAMESPACE ?= codeready-toolchain-test -IMAGE_NAME_TO_PUSH_IN_QUAY ?= quay.io/$(QUAY_NAMESPACE)/sandbox-rhdh-plugin -IMAGE_TO_PUSH_IN_QUAY := $(shell \ - if [ -n "$(CI)$(CLONEREFS_OPTIONS)" ]; then \ - if [ -n "$(GITHUB_ACTIONS)" ]; then \ - REPOSITORY_NAME=$$(basename "$(GITHUB_REPOSITORY)"); \ - COMMIT_ID_SUFFIX=$$(echo "$(PULL_PULL_SHA)" | cut -c1-7); \ - echo "$(IMAGE_NAME_TO_PUSH_IN_QUAY):from.$${REPOSITORY_NAME}.PR$(PULL_NUMBER).$${COMMIT_ID_SUFFIX}"; \ - else \ - : "if REPO_NAME is not set, it means that the E2E tests were triggered by periodic CI job"; \ - if [ -z "$(REPO_NAME)" ]; then \ - echo "quay.io/codeready-toolchain/sandbox-rhdh-plugin:latest"; \ - else \ - AUTHOR=$$(jq -r '.refs[0].pulls[0].author' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'); \ - PULL_PULL_SHA=$${PULL_PULL_SHA:-$$(jq -r '.refs[0].pulls[0].sha' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]')}; \ - COMMIT_ID_SUFFIX=$$(echo "$${PULL_PULL_SHA}" | cut -c1-7); \ - echo "$(IMAGE_NAME_TO_PUSH_IN_QUAY):from.$$(echo $(REPO_NAME) | sed 's/\"//g').PR$(PULL_NUMBER).$${COMMIT_ID_SUFFIX}"; \ - fi; \ - fi; \ - else \ - echo "$(IMAGE_NAME_TO_PUSH_IN_QUAY):latest"; \ - fi) +PUBLISH_UI ?= false +DEPLOY_UI ?= true - -.PHONY: deploy-sandbox-ui -deploy-sandbox-ui: HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) -deploy-sandbox-ui: REGISTRATION_SERVICE_API=https://$(shell oc get route registration-service -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n')/api/v1 -deploy-sandbox-ui: HOST_OPERATOR_API=https://$(shell oc get route api -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n') -deploy-sandbox-ui: RHDH=https://rhdh-${SANDBOX_UI_NS}.$(shell oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}') -deploy-sandbox-ui: - $(MAKE) check-sso-credentials - @echo "sandbox ui will be deployed in '${SANDBOX_UI_NS}' namespace" - $(MAKE) create-namespace SANDBOX_UI_NS=${SANDBOX_UI_NS} -ifeq ($(PUSH_SANDBOX_IMAGE),true) - $(MAKE) push-sandbox-plugin -endif - oc kustomize deploy/sandbox-ui/ui-e2e-tests | REGISTRATION_SERVICE_API=${REGISTRATION_SERVICE_API} \ - HOST_OPERATOR_API=${HOST_OPERATOR_API} \ - SANDBOX_UI_NS=${SANDBOX_UI_NS} \ - SANDBOX_PLUGIN_IMAGE=${IMAGE_TO_PUSH_IN_QUAY} \ - RHDH=${RHDH} envsubst | oc apply -f - - $(MAKE) configure-oauth-idp -ifeq ($(ENVIRONMENT),ui-e2e-tests) - @echo "applying toolchainconfig changes" - @echo "HOST_NS: ${HOST_NS}" - @oc apply -f deploy/host-operator/ui-e2e-tests/toolchainconfig.yaml -n ${HOST_NS} - @echo "restarting registration-service to apply toolchainconfig changes" - @oc -n ${HOST_NS} rollout restart deploy/registration-service -else - @echo "skipping toolchainconfig changes - environment is not ui-e2e-tests" +.PHONY: get-and-publish-devsandbox-dashboard +get-and-publish-devsandbox-dashboard: +ifneq (${UI_REPO_PATH},) + $(eval UI_REPO_PATH_PARAM = -ur ${UI_REPO_PATH}) endif - @oc -n ${SANDBOX_UI_NS} rollout status deploy/rhdh - @echo "Developer Sandbox UI running at ${RHDH}" - - -check-sso-credentials: - @echo "checking SSO credentials..." - @if [ -z "$(SSO_USERNAME_READ)" ] || [ -z "$(SSO_PASSWORD_READ)" ]; then \ - if [ -n "$(CI)" ]; then \ - echo "SSO credential files not found or empty in CI environment"; \ - else \ - echo "SSO_USERNAME or SSO_PASSWORD environment variables not set"; \ - fi; \ - exit 1; \ - fi - @echo "Validating SSO credentials..." - @status=$$(curl -s -o /dev/null -w "%{http_code}" \ - -X POST "https://sso.devsandbox.dev/auth/realms/sandbox-dev/protocol/openid-connect/token" \ - -d "grant_type=password" \ - -d "client_id=sandbox-public" \ - -d "username=$(SSO_USERNAME_READ)" \ - -d "password=$(SSO_PASSWORD_READ)"); \ - if [ "$$status" != "200" ]; then \ - echo "failed trying to login to 'https://sso.devsandbox.dev/auth/realms/sandbox-dev' ($$status) — check your SSO credentials."; \ - exit 1; \ - fi - @echo "SSO credentials validated successfully" - -configure-oauth-idp: - @echo "configuring DevSandbox identity provider" - @oc create secret generic ${OPENID_SECRET_NAME} \ - --from-literal=clientSecret=dummy \ - --namespace=openshift-config - OPENID_SECRET_NAME=${OPENID_SECRET_NAME} envsubst < deploy/sandbox-ui/ui-e2e-tests/oauth-idp-patch.yaml | \ - oc patch oauths.config.openshift.io/cluster --type=merge --patch-file=/dev/stdin - -create-namespace: - @if ! oc get project ${SANDBOX_UI_NS} >/dev/null 2>&1; then \ - echo "Creating namespace ${SANDBOX_UI_NS}"; \ - oc new-project ${SANDBOX_UI_NS} >/dev/null 2>&1 || true; \ - else \ - echo "Namespace ${SANDBOX_UI_NS} already exists"; \ - fi - @oc project ${SANDBOX_UI_NS} >/dev/null 2>&1 - - -.PHONY: get-rhdh-plugins -get-rhdh-plugins: -ifeq ($(strip $(RHDH_PLUGINS_TMP)), $(TMPDIR)rhdh-plugins) -ifeq ($(GITHUB_ACTIONS),true) - @echo "using author ${AUTHOR}" - $(eval AUTHOR_LINK = https://github.com/${AUTHOR}) - @echo "detected branch ${BRANCH_NAME}" - # check if a branch with the same ref exists in the user's fork of rhdh-plugins repo - @echo "branches of ${AUTHOR_LINK}/rhdh-plugins - checking if there is a branch ${BRANCH_NAME} we could pair with." - curl ${AUTHOR_LINK}/rhdh-plugins.git/info/refs?service=git-upload-pack --output - - $(eval REMOTE_RHDH_PLUGINS_BRANCH := $(shell curl ${AUTHOR_LINK}/rhdh-plugins.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}')) - - # check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master - @echo "REMOTE_RHDH_PLUGINS_BRANCH: ${REMOTE_RHDH_PLUGINS_BRANCH}" - @$(MAKE) pair-if-needed REMOTE_RHDH_PLUGINS_BRANCH=${REMOTE_RHDH_PLUGINS_BRANCH} AUTHOR_LINK=${AUTHOR_LINK} -else - @echo "using rhdh-plugins repo from master" - @$(MAKE) clone-rhdh-plugins -endif -else - @echo "using local rhdh-plugins repo, no pairing needed: ${RHDH_PLUGINS_TMP}" +ifneq (${FORCED_TAG},) + $(eval FORCED_TAG_PARAM = -ft ${FORCED_TAG}) endif - -pair-if-needed: -ifneq ($(strip $(REMOTE_RHDH_PLUGINS_BRANCH)),) - @echo "Branch ref of the user's fork to be used for pairing: \"${REMOTE_RHDH_PLUGINS_BRANCH}\"" - git config --global user.email "devsandbox@redhat.com" - git config --global user.name "KubeSaw" - # clone - rm -rf ${RHDH_PLUGINS_TMP} - git clone --depth=1 https://github.com/redhat-developer/rhdh-plugins.git ${RHDH_PLUGINS_TMP} - # add the user's fork as remote repo - git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} remote add external ${AUTHOR_LINK}/rhdh-plugins.git - # fetch the branch - git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} fetch external ${REMOTE_RHDH_PLUGINS_BRANCH} - # merge the branch with master - git --git-dir=${RHDH_PLUGINS_TMP}/.git --work-tree=${RHDH_PLUGINS_TMP} merge --ff-only FETCH_HEAD -else - @echo "no pairing needed, using rhdh-plugins repo from master" - @$(MAKE) clone-rhdh-plugins +ifneq (${DEPLOY_LATEST},) + $(eval DEPLOY_LATEST_PARAM = -dl ${DEPLOY_LATEST}) endif + @echo "Publishing and installing the Developer Sandbox Dashboard" + scripts/ci/manage-devsandbox-dashboard.sh -pp ${PUBLISH_UI} ${UI_REPO_PATH_PARAM} -ds ${DATE_SUFFIX} -qn ${QUAY_NAMESPACE} ${FORCED_TAG_PARAM} -du ${DEPLOY_UI} -ns ${DEVSANDBOX_DASHBOARD_NS} -os ${OPENID_SECRET_NAME} -en ${UI_ENVIRONMENT} ${DEPLOY_LATEST_PARAM} -.PHONY: clone-rhdh-plugins -clone-rhdh-plugins: - rm -rf ${RHDH_PLUGINS_TMP}; \ - git clone --depth=1 https://github.com/redhat-developer/rhdh-plugins $(RHDH_PLUGINS_TMP) && \ - echo "cloned to $(RHDH_PLUGINS_TMP)" - -.PHONY: push-sandbox-plugin -push-sandbox-plugin: - $(MAKE) get-rhdh-plugins - cd $(RHDH_PLUGINS_TMP)/workspaces/sandbox && \ - rm -rf plugins/sandbox/dist-dynamic && \ - rm -rf red-hat-developer-hub-backstage-plugin-sandbox && \ - yarn install && \ - npx @janus-idp/cli@3.3.1 package package-dynamic-plugins \ - --tag $(IMAGE_TO_PUSH_IN_QUAY) \ - --platform $(PLATFORM) && \ - podman push $(IMAGE_TO_PUSH_IN_QUAY) - -.PHONY: clean-sandbox-ui -clean-sandbox-ui: HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) -clean-sandbox-ui: - @oc delete ns ${SANDBOX_UI_NS} - @oc delete secret ${OPENID_SECRET_NAME} -n openshift-config - @oc delete usersignup ${SSO_USERNAME} -n ${HOST_NS} - -.PHONY: e2e-run-sandbox-ui -e2e-run-sandbox-ui: HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) -e2e-run-sandbox-ui: RHDH=https://rhdh-${SANDBOX_UI_NS}.$(shell oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}') -e2e-run-sandbox-ui: - @echo "Installing Playwright..." +.PHONY: e2e-run-devsandbox-dashboard +e2e-run-devsandbox-dashboard: HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) +e2e-run-devsandbox-dashboard: RHDH=https://rhdh-${DEVSANDBOX_DASHBOARD_NS}.$(shell oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}') +e2e-run-devsandbox-dashboard: $(eval PWGO_VER := $(shell grep -oE "playwright-go v\S+" go.mod | sed 's/playwright-go //g')) @echo "Installing Playwright CLI version: $(PWGO_VER)" go install github.com/playwright-community/playwright-go/cmd/playwright@$(PWGO_VER) @echo "Installing Firefox browser for Playwright..." $(GOPATH)/bin/playwright install firefox - @echo "Running Developer Sandbox UI setup e2e tests..." - SANDBOX_UI_NS=${SANDBOX_UI_NS} go test "./test/e2e/sandbox-ui/setup" -v -timeout=10m -failfast + @echo "Running Developer Sandbox Dashboard setup e2e tests..." + DEVSANDBOX_DASHBOARD_NS=${DEVSANDBOX_DASHBOARD_NS} go test "./test/e2e/sandbox-ui/setup" -v -timeout=10m -failfast - @echo "Running Developer Sandbox UI e2e tests in firefox..." + @echo "Running Developer Sandbox Dashboard e2e tests in firefox..." @SSO_USERNAME=$(SSO_USERNAME_READ) SSO_PASSWORD=$(SSO_PASSWORD_READ) BASE_URL=${RHDH} BROWSER=firefox envsubst < deploy/sandbox-ui/ui-e2e-tests/.env > testsupport/sandbox-ui/.env go test "./test/e2e/sandbox-ui" -v -timeout=10m -failfast @oc delete usersignup $(SSO_USERNAME_READ) -n $(HOST_NS) - @echo "The Developer Sandbox UI e2e tests successfully finished" + @echo "The Developer Sandbox Dashboard e2e tests successfully finished" +.PHONY: test-devsandbox-dashboard-e2e +test-devsandbox-dashboard-e2e: get-and-publish-devsandbox-dashboard e2e-run-devsandbox-dashboard -.PHONY: test-ui-e2e -test-ui-e2e: - $(MAKE) deploy-sandbox-ui e2e-run-sandbox-ui ENVIRONMENT=${UI_ENVIRONMENT} +.PHONY: test-devsandbox-dashboard-e2e-local +test-devsandbox-dashboard-e2e-local: + $(MAKE) get-and-publish-devsandbox-dashboard e2e-run-devsandbox-dashboard UI_REPO_PATH=${PWD}/../devsandbox-dashboard PUBLISH_UI=true DEPLOY_UI=true -.PHONY: test-ui-e2e-local -test-ui-e2e-local: - $(MAKE) deploy-sandbox-ui e2e-run-sandbox-ui RHDH_PLUGINS_TMP=${PWD}/../rhdh-plugins ENVIRONMENT=${UI_ENVIRONMENT} PUSH_SANDBOX_IMAGE=true - - -UNIT_TEST_IMAGE_NAME=sandbox-ui-e2e-tests -UNIT_TEST_DOCKERFILE=build/sandbox-ui/Dockerfile +.PHONY: clean-devsandbox-dashboard +clean-devsandbox-dashboard: HOST_NS=$(shell oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) +clean-devsandbox-dashboard: + @oc delete ns ${DEVSANDBOX_DASHBOARD_NS} + @oc delete secret ${OPENID_SECRET_NAME} -n openshift-config + @oc delete usersignup ${SSO_USERNAME} -n ${HOST_NS} -# Build Developer Sandbox UI e2e tests image using podman -.PHONY: build-sandbox-ui-e2e-tests -build-sandbox-ui-e2e-tests: - @echo "building the $(UNIT_TEST_IMAGE_NAME) image with podman..." - podman build --platform $(PLATFORM) -t $(UNIT_TEST_IMAGE_NAME) -f $(UNIT_TEST_DOCKERFILE) . -# Run Developer Sandbox UI e2e tests image using podman -.PHONY: test-sandbox-ui-in-container -test-sandbox-ui-in-container: build-sandbox-ui-e2e-tests - @echo "pushing Developer Sandbox UI image..." - $(MAKE) push-sandbox-plugin +E2E_TEST_IMAGE_NAME=devsandbox-dashboard-e2e-tests +E2E_TEST_DOCKERFILE=build/sandbox-ui/Dockerfile + +# Build Developer Sandbox Dashboard e2e tests image using podman +.PHONY: build-devsandbox-dashboard-e2e-tests +build-devsandbox-dashboard-e2e-tests: + @echo "building the $(E2E_TEST_IMAGE_NAME) image with podman..." + podman build --platform $(IMAGE_PLATFORM) -t $(E2E_TEST_IMAGE_NAME) -f $(E2E_TEST_DOCKERFILE) . + +# Run Developer Sandbox Dashboard e2e tests image using podman +.PHONY: test-devsandbox-dashboard-in-container +test-devsandbox-dashboard-in-container: build-devsandbox-dashboard-e2e-tests +ifneq ($(UI_REPO_PATH),) + $(eval FORCED_TAG := $(DATE_SUFFIX)) + $(eval ABS_UI_REPO_PATH := $(abspath $(UI_REPO_PATH))) + @echo "Generated FORCED_TAG: $(FORCED_TAG)" + @echo "Using UI_REPO_PATH: $(ABS_UI_REPO_PATH)" + @echo "pushing Developer Dashboard image..." + $(MAKE) get-and-publish-devsandbox-dashboard PUBLISH_UI=true DEPLOY_UI=false FORCED_TAG=$(FORCED_TAG) UI_REPO_PATH=$(UI_REPO_PATH) +else + @echo "Skipping Developer Sandbox Dashboard publish - UI_REPO_PATH not set" +endif @echo "running the e2e tests in podman container..." - podman run --platform $(PLATFORM) --rm \ + podman run --platform $(IMAGE_PLATFORM) --rm \ -v $(KUBECONFIG):/root/.kube/config \ -e KUBECONFIG=/root/.kube/config \ -v ${PWD}:/root/toolchain-e2e \ -e E2E_REPO_PATH=/root/toolchain-e2e \ - -v $(RHDH_PLUGINS_TMP):/root/rhdh-plugins \ - -e RHDH_PLUGINS_TMP=/root/rhdh-plugins \ + $(if $(ABS_UI_REPO_PATH),-v $(ABS_UI_REPO_PATH):/root/devsandbox-dashboard -e UI_REPO_PATH=/root/devsandbox-dashboard) \ + $(if $(ABS_UI_REPO_PATH),-e FORCED_TAG=$(FORCED_TAG)) \ -e SSO_USERNAME=$(SSO_USERNAME) \ -e SSO_PASSWORD=$(SSO_PASSWORD) \ -e QUAY_NAMESPACE=$(QUAY_NAMESPACE) \ - -e TMP=/tmp/ \ - -e RUNNING_IN_CONTAINER=true \ - $(UNIT_TEST_IMAGE_NAME) + -e DEPLOY_UI=true \ + -e PUBLISH_UI=false \ + $(E2E_TEST_IMAGE_NAME) make test-devsandbox-dashboard-e2e diff --git a/make/test.mk b/make/test.mk index 622459451..8bf9800c4 100644 --- a/make/test.mk +++ b/make/test.mk @@ -49,9 +49,9 @@ ifeq ($(CI),true) # if we are running on CI, we want to run the ui e2e tests in the toolchain-e2e presubmit and periodic CI jobs # if REPO_NAME is not set, it means that the e2e tests were triggered by the periodic CI job ifeq ($(filter-out toolchain-e2e,$(REPO_NAME)),) - $(MAKE) test-ui-e2e + $(MAKE) test-devsandbox-dashboard-e2e @echo "UI E2E tests successfully finished" - @echo "To clean the Developer Sandbox UI run 'make clean-sandbox-ui'" + @echo "To clean the Developer Sandbox Dashboard run 'make clean-devsandbox-dashboard'" endif endif @@ -294,7 +294,9 @@ deploy-single-member-e2e-latest: .PHONY: publish-current-bundles-for-e2e ## Target that is supposed to be called from CI - it builds & publishes the current operator bundles -publish-current-bundles-for-e2e: get-and-publish-operators +publish-current-bundles-for-e2e: PUBLISH_UI=true +publish-current-bundles-for-e2e: DEPLOY_UI=false +publish-current-bundles-for-e2e: get-and-publish-operators get-and-publish-devsandbox-dashboard .PHONY: get-and-publish-operators get-and-publish-operators: PUBLISH_OPERATOR=true diff --git a/scripts/ci/manage-devsandbox-dashboard.sh b/scripts/ci/manage-devsandbox-dashboard.sh new file mode 100755 index 000000000..9b3d1188e --- /dev/null +++ b/scripts/ci/manage-devsandbox-dashboard.sh @@ -0,0 +1,224 @@ +#!/usr/bin/env bash + +user_help () { + echo "Publishes Developer Sandbox Dashboard to quay and deploys it to an OpenShift cluster" + echo "options:" + echo "-pp, --publish-ui Builds and pushes the UI to quay" + echo "-qn, --quay-namespace Quay namespace the images should be pushed to" + echo "-ur, --ui-repo-path Path to the UI repo" + echo "-du, --deploy-ui Deploys the UI to the OpenShift cluster" + echo "-ds, --date-suffix Date suffix to be added to some resources that are created" + echo "-ft, --forced-tag Forces a tag to be set to all built images. In the case deployment the tag is used for index image in the created CatalogSource" + echo "-ns, --namespace Namespace to deploy the Developer Sandbox Dashboard" + echo "-os, --openid-secret OpenID secret name" + echo "-en, --environment Environment name" + echo "-dl, --deploy-latest Deploys the latest version of the Developer Sandbox Dashboard" + echo "-h, --help To show this help text" + echo "" + exit 0 +} + +read_arguments() { + if [[ $# -lt 2 ]] + then + user_help + fi + + while [[ $# -gt 0 ]]; do + local arg="$1" + case "$arg" in + -h|--help) + user_help + ;; + -pp|--publish-ui) + shift + PUBLISH_UI=$1 + shift + ;; + -qn|--quay-namespace) + shift + QUAY_NAMESPACE=$1 + shift + ;; + -ur|--ui-repo-path) + shift + UI_REPO_PATH=$1 + shift + ;; + -du|--deploy-ui) + shift + DEPLOY_UI=$1 + shift + ;; + -ds|--date-suffix) + shift + DATE_SUFFIX=$1 + shift + ;; + -ft|--forced-tag) + shift + FORCED_TAG=$1 + shift + ;; + -ns|--namespace) + shift + DEVSANDBOX_DASHBOARD_NS=$1 + shift + ;; + -os|--openid-secret) + shift + OPENID_SECRET_NAME=$1 + shift + ;; + -en|--environment) + shift + ENVIRONMENT=$1 + shift + ;; + *) + echo "$1 is not a recognized flag!" >> /dev/stderr + user_help + exit -1 + ;; + esac + done +} + +check_sso_credentials() { + echo "checking SSO credentials..." + + if [[ -z "${SSO_USERNAME_READ}" ]] || [[ -z "${SSO_PASSWORD_READ}" ]]; then + if [[ -n "${CI}" ]]; then + echo "SSO credential files not found or empty in CI environment" + else + echo "SSO_USERNAME or SSO_PASSWORD environment variables not set" + fi + exit 1 + fi + + echo "Validating SSO credentials..." + + status=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "https://sso.devsandbox.dev/auth/realms/sandbox-dev/protocol/openid-connect/token" \ + -d "grant_type=password" \ + -d "client_id=sandbox-public" \ + -d "username=${SSO_USERNAME_READ}" \ + -d "password=${SSO_PASSWORD_READ}") + + if [[ "${status}" != "200" ]]; then + echo "failed trying to login to 'https://sso.devsandbox.dev/auth/realms/sandbox-dev' (${status}) — check your SSO credentials." + exit 1 + fi + + echo "SSO credentials validated successfully" +} + +configure_oauth_idp() { + echo "configuring DevSandbox identity provider" + + oc create secret generic ${OPENID_SECRET_NAME} \ + --from-literal=clientSecret=dummy \ + --namespace=openshift-config \ + --dry-run=client -o yaml | oc apply -f - + + OPENID_SECRET_NAME=${OPENID_SECRET_NAME} envsubst < deploy/sandbox-ui/ui-e2e-tests/oauth-idp-patch.yaml | \ + oc patch oauths.config.openshift.io/cluster --type=merge --patch-file=/dev/stdin +} + +create_namespace() { + if ! oc get project ${DEVSANDBOX_DASHBOARD_NS} >/dev/null 2>&1; then + echo "Creating namespace ${DEVSANDBOX_DASHBOARD_NS}" + oc new-project ${DEVSANDBOX_DASHBOARD_NS} >/dev/null 2>&1 || true + else + echo "Namespace ${DEVSANDBOX_DASHBOARD_NS} already exists" + fi + oc project ${DEVSANDBOX_DASHBOARD_NS} >/dev/null 2>&1 +} + +set -e + +read_arguments "$@" + +if [[ -n "${CI}" ]]; then + set -ex +else + set -e +fi + +source scripts/ci/manage-operator.sh + +# Global variables for the script +DEFAULT_SANDBOX_PLUGIN_IMAGE="quay.io/codeready-toolchain/sandbox-rhdh-plugin:latest" + + +if [[ "${DEPLOY_LATEST}" != "true" ]] && [[ -n "${CI}${UI_REPO_PATH}" ]] && [[ $(echo ${REPO_NAME} | sed 's/"//g') != "release" ]]; then + REPOSITORY_NAME=devsandbox-dashboard + PROVIDED_REPOSITORY_PATH=${UI_REPO_PATH} + get_repo + set_tags + + IMAGE_LOC=quay.io/${QUAY_NAMESPACE}/sandbox-rhdh-plugin:${TAGS} + + if [[ ${PUBLISH_UI} == "true" ]]; then + echo "Going to push Developer Sandbox Dashboard image..." + # workaround since our image is still named sandbox-rhdh-plugin + REPOSITORY_NAME=sandbox-rhdh-plugin + push_image + fi +else + echo "Running in local mode without setting the UI_REPO_PATH, using sandbox-rhdh-plugin image" + IMAGE_LOC="${DEFAULT_SANDBOX_PLUGIN_IMAGE}" +fi + +if [[ ${DEPLOY_UI} == "true" ]]; then + # Get the HOST_NS (host operator namespace) + HOST_NS=$(oc get projects -l app=host-operator --output=name -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort | tail -n 1) + + # Get the Registration Service API URL + REGISTRATION_SERVICE_API="https://$(oc get route registration-service -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n')/api/v1" + + # Get the Host Operator API URL + HOST_OPERATOR_API="https://$(oc get route api -n ${HOST_NS} -o custom-columns=":spec.host" | tr -d '\n')" + + # Get the RHDH URL + RHDH="https://rhdh-${DEVSANDBOX_DASHBOARD_NS}.$(oc get ingress.config.openshift.io/cluster -o jsonpath='{.spec.domain}')" + + echo "Developer Sandbox Dashboard will be deployed in '${DEVSANDBOX_DASHBOARD_NS}' namespace" + + SSO_USERNAME_READ=$(if [[ -n "${CI}" ]]; then cat /usr/local/sandbox-secrets/SSO_USERNAME 2>/dev/null || echo ""; else echo "${SSO_USERNAME}"; fi) + SSO_PASSWORD_READ=$(if [[ -n "${CI}" ]]; then cat /usr/local/sandbox-secrets/SSO_PASSWORD 2>/dev/null || echo ""; else echo "${SSO_PASSWORD}"; fi) + + # Call check-sso-credentials + check_sso_credentials + + # Create namespace + create_namespace + + # Apply kustomize with envsubst + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + + oc kustomize ${REPO_ROOT}/deploy/sandbox-ui/${ENVIRONMENT} | \ + REGISTRATION_SERVICE_API=${REGISTRATION_SERVICE_API} \ + HOST_OPERATOR_API=${HOST_OPERATOR_API} \ + DEVSANDBOX_DASHBOARD_NS=${DEVSANDBOX_DASHBOARD_NS} \ + SANDBOX_PLUGIN_IMAGE=${IMAGE_LOC} \ + RHDH=${RHDH} envsubst | oc apply -f - + + # Configure OAuth IDP + configure_oauth_idp + + # Conditionally apply toolchainconfig changes + if [[ "${ENVIRONMENT}" == "ui-e2e-tests" ]]; then + echo "applying toolchainconfig changes" + oc apply -f ${REPO_ROOT}/deploy/host-operator/ui-e2e-tests/toolchainconfig.yaml -n ${HOST_NS} + echo "restarting registration-service to apply toolchainconfig changes" + oc -n ${HOST_NS} rollout restart deploy/registration-service + else + echo "skipping toolchainconfig changes - environment is not ui-e2e-tests" + fi + + # Wait for RHDH deployment to be ready + oc -n ${DEVSANDBOX_DASHBOARD_NS} rollout status deploy/rhdh --timeout 5m + echo "Developer Sandbox Dashboard running at ${RHDH}" +fi diff --git a/test/e2e/sandbox-ui/README.md b/test/e2e/sandbox-ui/README.md index 4d864b41a..12353906e 100644 --- a/test/e2e/sandbox-ui/README.md +++ b/test/e2e/sandbox-ui/README.md @@ -1,6 +1,6 @@ -# Developer Sandbox UI E2E Tests +# Developer Sandbox Dashboard E2E Tests -The UI E2E tests are executed against the Developer Sandbox UI running in OpenShift. +The UI E2E tests are executed against the Developer Sandbox Dashboard running in OpenShift. *Prerequisites*: @@ -9,45 +9,29 @@ The UI E2E tests are executed against the Developer Sandbox UI running in OpenSh 2. Ensure you are using Node.js version 22 - to easily manage it, you can run `nvm use 22` 3. Ensure you have `yarn` installed -4. Make sure you can log in at using your SSO_USERNAME and SSO_PASSWORD -5. Make sure you have toolchain resources deployed on your cluster (you can run `make prepare-and-deploy-e2e`) +4. Make sure you can log in at using your `SSO_USERNAME` and `SSO_PASSWORD`. You can contact the [Developer Sandbox team](devsandbox@redhat.com) to obtain the test user credentials. +5. Make sure you have toolchain resources deployed on your cluster (you can run `make prepare-and-deploy-e2e` or if you are on apple chipset build and deploy all projects from locally with `make prepare-and-deploy-e2e-local PLATFORM=linux/arm64`) +6. If you want to test the Developer Sandbox Dashboard from your local devsandbox-dashboard repository, it's required that you create a repository called `sandbox-rhdh-plugin` in your quay organization and make it public -### Running UI E2E Tests locally +## Running UI E2E Tests locally -`make test-ui-e2e SSO_USERNAME=${SSO_USERNAME} SSO_PASSWORD=${SSO_PASSWORD} PUSH_SANDBOX_IMAGE=true` +`make test-devsandbox-dashboard-e2e SSO_USERNAME=${SSO_USERNAME} SSO_PASSWORD=${SSO_PASSWORD}` -If you want to run and test the Developer Sandbox UI from your local rhdh-plugins repo, run `make test-ui-e2e-local SSO_USERNAME=${SSO_USERNAME} SSO_PASSWORD=${SSO_PASSWORD}` +If you want to run and test the Developer Sandbox Dashboard from your local devsandbox-dashboard repository, run `make test-devsandbox-dashboard-e2e-local SSO_USERNAME=${SSO_USERNAME} SSO_PASSWORD=${SSO_PASSWORD}` For now, the UI E2E tests are running only through the Firefox browser. -### Running UI E2E Tests in Container +## Running UI E2E Tests in Container -`make test-sandbox-ui-in-container SSO_USERNAME= SSO_PASSWORD= HOST_NS=` +`make test-devsandbox-dashboard-in-container SSO_USERNAME= SSO_PASSWORD=` -### Running UI E2E Tests against dev/stage/prod +If you want to use your local devsandbox-dashboard, please: +1. Set the `QUAY_NAMESPACE` environment variable to your quay username: `export QUAY_NAMESPACE=` +2. Run `make test-devsandbox-dashboard-in-container SSO_USERNAME= SSO_PASSWORD= UI_REPO_PATH=${PWD}/../devsandbox-dashboard` -If you want to run the UI E2E tests against dev/stage/prod, please follow the next steps: +## Deploy Developer Sandbox Dashboard in E2E mode -- have a new Red Hat account or an account that was deactivated -- fill `testsupport/sandbox-ui/.env`, note that to run the UI E2E tests against dev/stage/prod, you need to set the ENVIRONMENT to dev. - -``` -SSO_USERNAME= -SSO_PASSWORD= -BASE_URL=https://sandbox.redhat.com/ -ENVIRONMENT=dev -BROWSER=firefox -``` - -- run `go test "./test/e2e/sandbox-ui" -v -timeout=10m -failfast -count=1` - -`make test-sandbox-ui-in-container SSO_USERNAME= SSO_PASSWORD=` - -### Deploy Developer Sandbox UI in E2E mode - -`make deploy-sandbox-ui HOST_NS=` - -Please note that OCP cluster does not have a valid CA, so when accessing the Developer Sandbox UI, you need to: +Please note that OCP cluster does not have a valid CA, so when accessing the Developer Sandbox Dashboard, you need to: - accept to proceed unsafely @@ -57,7 +41,7 @@ Please note that OCP cluster does not have a valid CA, so when accessing the Dev ![registration-service](https://github.com/user-attachments/assets/6c2f7446-1de2-4701-ace7-2d6796f49eeb) -### Clean Developer Sandbox UI +## Clean Developer Sandbox Dashboard -`make clean-sandbox-ui HOST_NS= SSO_USERNAME=` +`make clean-devsandbox-dashboard SSO_USERNAME=` diff --git a/test/e2e/sandbox-ui/homepage_test.go b/test/e2e/sandbox-ui/homepage_test.go index 460cb50e8..593b82558 100644 --- a/test/e2e/sandbox-ui/homepage_test.go +++ b/test/e2e/sandbox-ui/homepage_test.go @@ -12,7 +12,7 @@ import ( ) // TestHomepage tests the homepage layout and welcome text -// when the user accesses the Developer Sandbox UI for the first time +// when the user accesses the Developer Sandbox Dashboard for the first time func TestHomepage(t *testing.T) { page := sandboxui.Setup(t, "test-homepage") diff --git a/test/e2e/sandbox-ui/setup/setup_test.go b/test/e2e/sandbox-ui/setup/setup_test.go index a2028ee03..52bc99f71 100644 --- a/test/e2e/sandbox-ui/setup/setup_test.go +++ b/test/e2e/sandbox-ui/setup/setup_test.go @@ -7,6 +7,6 @@ import ( ) func TestSetup(t *testing.T) { - // check Developer Sandbox UI is up and running - testsupport.WaitForSandboxUI(t) + // check Developer Sandbox Dashboard is up and running + testsupport.WaitForDevSandboxDashboard(t) } diff --git a/testsupport/init.go b/testsupport/init.go index 5c4f9731e..7fb8ce722 100644 --- a/testsupport/init.go +++ b/testsupport/init.go @@ -302,9 +302,9 @@ func IsSecondMemberMode(t *testing.T) bool { return secondMemberMode == "true" } -// WaitForSandboxUI waits for the Developer Sandbox UI to be ready. -func WaitForSandboxUI(t *testing.T) { - ns := os.Getenv("SANDBOX_UI_NS") +// WaitForDevSandboxDashboard waits for the Developer Sandbox Dashboard to be ready. +func WaitForDevSandboxDashboard(t *testing.T) { + ns := os.Getenv("DEVSANDBOX_DASHBOARD_NS") require.NotEmpty(t, ns) initOnce.Do(func() {