diff --git a/.ci/openshift-ci/build/Dockerfile b/.ci/openshift-ci/build/Dockerfile index aab4e8a42a..eb900d18b8 100644 --- a/.ci/openshift-ci/build/Dockerfile +++ b/.ci/openshift-ci/build/Dockerfile @@ -24,8 +24,7 @@ ADD . /che-plugin-registry WORKDIR /che-plugin-registry # Install build tools -# hadolint ignore=DL3041 -RUN dnf install -y -q --allowerasing --nobest nodejs-devel nodejs-libs \ +RUN dnf install -y -q --allowerasing --nobest nodejs-devel nodejs-libs psmisc python3-pip jq golang httpd-tools \ # already installed or installed as deps: openssl openssl-devel ca-certificates make cmake cpp gcc gcc-c++ zlib zlib-devel brotli brotli-devel python3 nodejs-packaging && \ dnf update -y && dnf clean all && \ @@ -34,7 +33,7 @@ RUN dnf install -y -q --allowerasing --nobest nodejs-devel nodejs-libs \ echo -n "npm version: "; npm -v; \ echo -n "yarn version: "; yarn -v; -# Build repo +# Generate editors' metadata RUN ./build.sh --skip-oci-image --skip-digest-generation FROM ghcr.io/eclipse/openvsx-server:d7fba39 AS openvsx-server @@ -103,6 +102,7 @@ COPY --from=ubi-builder /mnt/rootfs/ / # Add UTF-8 for the database RUN localedef -f UTF-8 -i en_US en_US.UTF-8 && \ usermod -a -G apache,root,postgres postgres + USER postgres ENV LC_ALL=en_US.UTF-8 \ LANG=en_US.UTF-8 \ diff --git a/.ci/openshift-ci/common-functions.sh b/.ci/openshift-ci/common-functions.sh index 5857a4728e..9ba1a29b61 100755 --- a/.ci/openshift-ci/common-functions.sh +++ b/.ci/openshift-ci/common-functions.sh @@ -1,47 +1,47 @@ #!/bin/bash - # -# Copyright (c) 2021 Red Hat, Inc. +# Copyright (c) 2023 Red Hat, Inc. # This program and the accompanying materials are made # available under the terms of the Eclipse Public License 2.0 # which is available at https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 # +# Contributors: +# Red Hat, Inc. - initial API and implementation +# -################################ !!! IMPORTANT !!! ################################ -########### THIS JOB USE openshift ci operators workflows to run ##################### -########## More info about how it is configured can be found here: https://docs.ci.openshift.org/docs/how-tos/testing-operator-sdk-operators ############# -####################################################################################################################################################### - -# exit immediately when a command fails set -e # only exit with zero if all commands of the pipeline exit successfully set -o pipefail -export RAM_MEMORY=8192 -export TEST_POD_NAMESPACE="plugin-registry-test" -export PLUGIN_REGISTRY_IMAGE=${CHE_PLUGIN_REGISTRY} -export TEST_CONTAINER_NAME="plugins-test" -export ARTIFACTS_DIR=${ARTIFACT_DIR:-"/tmp/artifacts-che"} -export TESTS_STATUS=() -export TEST_RESULT="PASSED" -# turn off telemetry -mkdir -p "${HOME}"/.config/chectl -echo "{\"segment.telemetry\":\"off\"}" > "${HOME}"/.config/chectl/config.json +export CHE_NAMESPACE=${CHE_NAMESPACE:-"eclipse-che"} +export ARTIFACTS_DIR=${ARTIFACT_DIR:-"/tmp/artifacts"} +export CHE_FORWARDED_PORT="8081" +export OCP_ADMIN_USER_NAME=${OCP_ADMIN_USER_NAME:-"admin"} +export OCP_NON_ADMIN_USER_NAME=${OCP_NON_ADMIN_USER_NAME:-"user"} +export OCP_LOGIN_PASSWORD=${OCP_LOGIN_PASSWORD:-"passw"} +export ADMIN_CHE_NAMESPACE=${OCP_ADMIN_USER_NAME}"-che" +export USER_CHE_NAMESPACE=${OCP_NON_ADMIN_USER_NAME}"-che" +export GIT_PROVIDER_USERNAME=${GIT_PROVIDER_USERNAME:-"chepullreq1"} +export PUBLIC_REPO_WORKSPACE_NAME=${PUBLIC_REPO_WORKSPACE_NAME:-"public-repo-wksp-testname"} +export PUBLIC_PROJECT_NAME=${PUBLIC_PROJECT_NAME:-"public-repo"} +export YAML_FILE_NAME=${YAML_FILE_NAME:-"devfile.yaml"} provisionOpenShiftOAuthUser() { - htpasswd -c -B -b users.htpasswd user user + echo -e "[INFO] Provisioning Openshift OAuth user" + htpasswd -c -B -b users.htpasswd "${OCP_ADMIN_USER_NAME}" "${OCP_LOGIN_PASSWORD}" + htpasswd -b users.htpasswd "${OCP_NON_ADMIN_USER_NAME}" "${OCP_LOGIN_PASSWORD}" oc create secret generic htpass-secret --from-file=htpasswd="users.htpasswd" -n openshift-config oc apply -f ".ci/openshift-ci/htpasswdProvider.yaml" - oc adm policy add-cluster-role-to-user cluster-admin user + oc adm policy add-cluster-role-to-user cluster-admin "${OCP_ADMIN_USER_NAME}" echo -e "[INFO] Waiting for htpasswd auth to be working up to 5 minutes" CURRENT_TIME=$(date +%s) ENDTIME=$((CURRENT_TIME + 300)) while [ "$(date +%s)" -lt $ENDTIME ]; do - if oc login -u user -p user --insecure-skip-tls-verify=false; then + if oc login -u="${OCP_ADMIN_USER_NAME}" -p="${OCP_LOGIN_PASSWORD}" --insecure-skip-tls-verify=false; then break fi sleep 10 @@ -55,19 +55,15 @@ createGithubSecret() { createCustomResourcesFile() { cat > custom-resources.yaml <<-END +apiVersion: org.eclipse.che/v2 spec: - auth: - updateAdminPassword: false - server: - pluginRegistryImage: ${PLUGIN_REGISTRY_IMAGE} - pluginRegistryPullPolicy: IfNotPresent - customCheProperties: - CHE_LIMITS_USER_WORKSPACES_RUN_COUNT: '-1' - CHE_LIMITS_WORKSPACE_IDLE_TIMEOUT: '900000' - CHE_INFRA_KUBERNETES_WORKSPACE__UNRECOVERABLE__EVENTS: 'Failed Scheduling,Failed to pull image' - CHE_WORKSPACE_SIDECAR_IMAGE__PULL__POLICY: IfNotPresent - CHE_WORKSPACE_PLUGIN__BROKER_PULL__POLICY: IfNotPresent - CHE_INFRA_KUBERNETES_PVC_JOBS_IMAGE_PULL__POLICY: IfNotPresent + components: + pluginRegistry: + openVSXURL: '' + deployment: + containers: + - image: '${PLUGIN_REGISTRY_IMAGE}' + imagePullPolicy: Always END echo "Generated custom resources file" @@ -75,150 +71,161 @@ END } deployChe() { - chectl server:deploy --che-operator-cr-patch-yaml=custom-resources.yaml --platform=openshift --batch + chectl server:deploy --che-operator-cr-patch-yaml=custom-resources.yaml \ + --platform=openshift \ + --telemetry=off \ + --batch } -patchTestPodConfig(){ - TEST_USERSTORY="$1" - TEST_POD_NAME="$2" - E2E_OPENSHIFT_TOKEN="$(oc whoami -t)" - - # obtain the basic test pod config - cat .ci/openshift-ci/plugins-test-pod.yaml > plugins-test-pod.yaml - - # Patch the basic test pod config - ECLIPSE_CHE_URL=https://$(oc get route -n "eclipse-che" che -o jsonpath='{.status.ingress[0].host}') - sed -i "s@CHE_URL@${ECLIPSE_CHE_URL}@g" plugins-test-pod.yaml - sed -i "s@TEST_USERSTORY@${TEST_USERSTORY}@g" plugins-test-pod.yaml - sed -i "s@POD_NAME@${TEST_POD_NAME}@g" plugins-test-pod.yaml - sed -i "s@OCP_TOKEN@${E2E_OPENSHIFT_TOKEN}@g" plugins-test-pod.yaml - sed -i "s@GH_USERNAME@${GH_USERNAME}@g" plugins-test-pod.yaml - sed -i "s@GH_PASSWORD@${GH_PASSWORD}@g" plugins-test-pod.yaml - - cat plugins-test-pod.yaml +# this command starts port forwarding between the local machine and the che-host service in the OpenShift cluster. +forwardPortToService() { + oc port-forward service/che-host ${CHE_FORWARDED_PORT}:8080 -n "${CHE_NAMESPACE}" & + sleep 3s } -downloadTestResults() { - TEST_USERSTORY="$1" - TEST_POD_NAME="$2" - mkdir -p /tmp/e2e - oc rsync -n ${TEST_POD_NAMESPACE} "${TEST_POD_NAME}":/tmp/e2e/report/ /tmp/e2e -c download-reports - oc exec -n ${TEST_POD_NAMESPACE} "${TEST_POD_NAME}" -c download-reports -- touch /tmp/e2e/done +getPluginRegistryURL() { + PLUGIN_REGISTRY_URL=$(oc get checlusters.org.eclipse.che -n "${CHE_NAMESPACE}" "${CHE_NAMESPACE}" -o=jsonpath='{.status.pluginRegistryURL}') + echo "[INFO] Plugin registry URL: ${PLUGIN_REGISTRY_URL}" +} - mkdir -p "${ARTIFACTS_DIR}" - cp -r /tmp/e2e "${ARTIFACTS_DIR}/${TEST_USERSTORY}" - rm -rf /tmp/e2e +killProcessByPort() { + fuser -k ${CHE_FORWARDED_PORT}/tcp +} - chectl server:logs --chenamespace="eclipse-che" --directory="${ARTIFACTS_DIR}/${TEST_USERSTORY}" - oc get checluster -o yaml -n "eclipse-che" > "${ARTIFACTS_DIR}/${TEST_USERSTORY}/che-cluster.yaml" +requestProvisionNamespace() { + CLUSTER_ACCESS_TOKEN=$(oc whoami -t) - TEST_POD_EXIT_CODE=$(oc logs -n ${TEST_POD_NAMESPACE} "${TEST_POD_NAME}" -c ${TEST_CONTAINER_NAME} | grep EXIT_CODE) + curl -i -X 'POST' \ + http://localhost:${CHE_FORWARDED_PORT}/api/kubernetes/namespace/provision \ + -H 'accept: application/json' \ + -H "Authorization: Bearer ${CLUSTER_ACCESS_TOKEN}" \ + -d '' +} - echo "The ${TEST_USERSTORY} pod exit code: ${TEST_POD_EXIT_CODE}" +initUserNamespace() { + OCP_USER_NAME=$1 - if [[ ${TEST_POD_EXIT_CODE} == "+ EXIT_CODE=1" ]]; then - echo "[ERROR] The ${TEST_USERSTORY} plugin test failed." - STATUS_MESSAGE="${TEST_USERSTORY}-------FAILED" - TESTS_STATUS+=("$STATUS_MESSAGE") - TEST_RESULT="FAILED" + echo "[INFO] Initialize user namespace" + oc login -u="${OCP_USER_NAME}" -p="${OCP_LOGIN_PASSWORD}" --insecure-skip-tls-verify=true + if requestProvisionNamespace | grep "HTTP/1.1 200"; then + echo "[INFO] Request provision user namespace returned 'HTTP/1.1 200' status code." else - STATUS_MESSAGE="${TEST_USERSTORY}-------PASSED" - TESTS_STATUS+=("${STATUS_MESSAGE}") + echo "[ERROR] Request provision user namespace returned wrong status code. Expected: HTTP/1.1 200" + exit 1 fi - } -finishReport() { - # report test results - - echo "" - echo "" - echo "==================== FINISH REPORT ========================" - echo "" - - for RESULT in "${TESTS_STATUS[@]}"; do - echo " ${RESULT}" - done - - if [[ ${TEST_RESULT} == "FAILED" ]]; then - echo "" - echo "[ERROR] The plugin tests failed." - echo "" - echo "===========================================================" - echo "" - echo "" - +provisionNamespace() { + if requestProvisionNamespace | grep "HTTP/1.1 200"; then + echo "[INFO] Request provision user namespace returned 'HTTP/1.1 200' status code." + else + echo "[ERROR] Request provision user namespace returned wrong status code. Expected: HTTP/1.1 200" exit 1 - fi - - echo "The plugin tests successfuly passed." - echo "" - echo "===========================================================" - echo "" - echo "" - - exit 0 - } -cleanUpAfterTest(){ - TEST_POD_NAME="$1" - - # delete test pod - oc delete pod -n "${TEST_POD_NAMESPACE}" "${TEST_POD_NAME}" +testProjectIsCloned() { + PROJECT_NAME=$1 + OCP_USER_NAMESPACE=$2 - # get token - chectl auth:login -n eclipse-che - - # get workspace ID - WORKSPACE_ID=$(chectl workspace:list -n eclipse-che | grep "${TEST_POD_NAME}" | awk '{print $1}') - echo "Workspace ID: ${WORKSPACE_ID}" - - # stop workspace - chectl workspace:stop -n eclipse-che "${WORKSPACE_ID}" - - # delete workspace - chectl workspace:delete -n eclipse-che "${WORKSPACE_ID}" + WORKSPACE_POD_NAME=$(oc get pods -n "${OCP_USER_NAMESPACE}" | grep workspace | awk '{print $1}') + if oc exec -it -n "${OCP_USER_NAMESPACE}" "${WORKSPACE_POD_NAME}" -- test -f /projects/"${PROJECT_NAME}"/"${YAML_FILE_NAME}"; then + echo "[INFO] Project file /projects/${PROJECT_NAME}/${YAML_FILE_NAME} exists." + else + echo "[INFO] Project file /projects/${PROJECT_NAME}/${YAML_FILE_NAME} is absent." + return 1 + fi } -runTest() { - TEST_USERSTORY="$1" - TEST_POD_NAME="$2" +runTestWorkspaceWithGitRepoUrlAndCustomEditor() { + WS_NAME=$1 + PROJECT_NAME=$2 + GIT_REPO_URL=$3 + OCP_USER_NAMESPACE=$4 + EDITOR_ID=$5 + + EDITOR_URL=$PLUGIN_REGISTRY_URL/plugins/$EDITOR_ID/devfile.yaml + echo "[INFO] Editor URL: ${EDITOR_URL}" + + oc project "${OCP_USER_NAMESPACE}" + cat .ci/openshift-ci/devfile-test.yaml > devfile-test.yaml + + # patch the devfile-test.yaml file + sed -i "s#ws-name#${WS_NAME}#g" devfile-test.yaml + sed -i "s#project-name#${PROJECT_NAME}#g" devfile-test.yaml + sed -i "s#git-repo-url#${GIT_REPO_URL}#g" devfile-test.yaml + + # download editor.yaml file from local plugin registry with no tls verification + curl -k -o ./editor.yaml "${EDITOR_URL}" + cat editor.yaml + + mkdir -p /tmp/npm-cache + export npm_config_cache=/tmp/npm-cache + npm install -g --prefix /tmp/generator @eclipse-che/che-devworkspace-generator@latest + # generate devworkspace-test.yaml file + node /tmp/generator/lib/node_modules/@eclipse-che/che-devworkspace-generator/lib/entrypoint.js \ + --devfile-path:./devfile-test.yaml \ + --editor-path:./editor.yaml \ + --output-file:./devworkspace-test.yaml + + cat devworkspace-test.yaml + + # run the workspace + oc apply -f devworkspace-test.yaml -n "${OCP_USER_NAMESPACE}" + oc wait -n "${OCP_USER_NAMESPACE}" --for=condition=Ready dw "${WS_NAME}" --timeout=360s + echo "[INFO] Test workspace is run" +} - patchTestPodConfig "${TEST_USERSTORY}" "${TEST_POD_NAME}" +deleteTestWorkspace() { + WS_NAME=$1 + OCP_USER_NAMESPACE=$2 - # Create the test pod - oc apply -f plugins-test-pod.yaml + oc delete dw "${WS_NAME}" -n "${OCP_USER_NAMESPACE}" +} - # wait for the pod to start - while true; do - sleep 3 - PHASE=$(oc get pod -n ${TEST_POD_NAMESPACE} "${TEST_POD_NAME}" \ - --template='{{ .status.phase }}') - if [[ ${PHASE} == "Running" ]]; then - break - fi - done +# Catch the finish of the job and write logs in artifacts. +catchFinish() { + local RESULT=$? + killProcessByPort + if [ "$RESULT" != "0" ]; then + set +e + collectEclipseCheLogs + set -e + fi - # wait for the test to finish - oc logs -n ${TEST_POD_NAMESPACE} "${TEST_POD_NAME}" -c ${TEST_CONTAINER_NAME} -f + [[ "${RESULT}" != "0" ]] && echo "[ERROR] Job failed." || echo "[INFO] Job completed successfully." + exit $RESULT +} - # just to sleep - sleep 3 +collectEclipseCheLogs() { + mkdir -p "${ARTIFACTS_DIR}"/che-logs - downloadTestResults "${TEST_USERSTORY}" "${TEST_POD_NAME}" - cleanUpAfterTest "${TEST_POD_NAME}" || echo "Cleanup after test has failed" + # Collect all Eclipse Che logs and cluster CR + chectl server:logs -n "$CHE_NAMESPACE" --directory "${ARTIFACTS_DIR}"/che-logs --telemetry off + oc get checluster -o yaml -n "$CHE_NAMESPACE" > "${ARTIFACTS_DIR}/che-cluster.yaml" } -createTestPodNamespace(){ - oc create namespace $TEST_POD_NAMESPACE +testStartWorkspace() { + WS_NAME=$1 + PROJECT_NAME=$2 + GIT_REPO_URL=$3 + OCP_USER_NAMESPACE=$4 + EDITOR_ID=$5 + + runTestWorkspaceWithGitRepoUrlAndCustomEditor "${WS_NAME}" "${PROJECT_NAME}" "${GIT_REPO_URL}" "${OCP_USER_NAMESPACE}" "${EDITOR_ID}" + echo "[INFO] Check the public repository is cloned" + testProjectIsCloned "${PROJECT_NAME}" "${OCP_USER_NAMESPACE}" || \ + { echo "[ERROR] Project file /projects/${PROJECT_NAME}/${YAML_FILE_NAME} should be present." && exit 1; } + deleteTestWorkspace "${WS_NAME}" "${OCP_USER_NAMESPACE}" } -setupTestEnvironment(){ +setupTestEnvironment() { + OCP_USER_NAME=$1 + provisionOpenShiftOAuthUser - createGithubSecret createCustomResourcesFile deployChe - createTestPodNamespace + forwardPortToService + getPluginRegistryURL + provisionNamespace } diff --git a/.ci/openshift-ci/devfile-test.yaml b/.ci/openshift-ci/devfile-test.yaml new file mode 100644 index 0000000000..215735b6bd --- /dev/null +++ b/.ci/openshift-ci/devfile-test.yaml @@ -0,0 +1,8 @@ +schemaVersion: 2.2.0 +metadata: + name: ws-name +projects: + - name: project-name + git: + remotes: + origin: git-repo-url diff --git a/.ci/openshift-ci/github-conf.yaml b/.ci/openshift-ci/github-conf.yaml deleted file mode 100644 index 2d9c7fe05a..0000000000 --- a/.ci/openshift-ci/github-conf.yaml +++ /dev/null @@ -1,14 +0,0 @@ -kind: Secret -apiVersion: v1 -metadata: - name: github-oauth-config - namespace: eclipse-che - labels: - app.kubernetes.io/part-of: che.eclipse.org - app.kubernetes.io/component: oauth-scm-configuration - annotations: - che.eclipse.org/oauth-scm-server: github -type: Opaque -data: - id: M2I4NTM4Y2FhNjEwOTBiYjY2NTU= - secret: ZGVkOTA5NmVhZDBkNDkyOTNlZDJhNTVmMzZkMzgwMmIxNzM4MDUyNg== diff --git a/.ci/openshift-ci/htpasswdProvider.yaml b/.ci/openshift-ci/htpasswdProvider.yaml index 6818e49b5b..1bfe61860d 100644 --- a/.ci/openshift-ci/htpasswdProvider.yaml +++ b/.ci/openshift-ci/htpasswdProvider.yaml @@ -4,9 +4,9 @@ metadata: name: cluster spec: identityProviders: - - name: htpasswd - mappingMethod: claim - type: HTPasswd - htpasswd: - fileData: - name: htpass-secret + - name: htpasswd + mappingMethod: claim + type: HTPasswd + htpasswd: + fileData: + name: htpass-secret diff --git a/.ci/openshift-ci/nightly-test.sh b/.ci/openshift-ci/nightly-test.sh deleted file mode 100755 index 44bc826d72..0000000000 --- a/.ci/openshift-ci/nightly-test.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2021 Red Hat, Inc. -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# - -################################ !!! IMPORTANT !!! ################################ -########### THIS JOB USE openshift ci operators workflows to run ##################### -########## More info about how it is configured can be found here: https://docs.ci.openshift.org/docs/how-tos/testing-operator-sdk-operators ############# -####################################################################################################################################################### - -# exit immediately when a command fails -set -e -# only exit with zero if all commands of the pipeline exit successfully -set -o pipefail - -# import common test functions -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -# shellcheck source=./.ci/openshift-ci/common-functions.sh -source "${SCRIPT_DIR}"/common-functions.sh - -# runTests() { -# runTest "InstallPluginUsingUI" "install-plugin-test" -# runTest "JavaPlugin" "java11-plugin-test" -# runTest "PhpPlugin" "php-plugin-test" -# runTest "PythonPlugin" "python-plugin-test" -# runTest "TypescriptPlugin" "typescript-debug-plugins" -# runTest "VscodeKubernetesPlugin" "nodejs-24lop" -# runTest "VscodeShellcheckPlugin" "nodejs-zmecm" -# runTest "VscodeValePlugin" "che-docs-test" -# runTest "VscodeXmlPlugin" "xml-plugin-test" -# runTest "VscodeYamlPlugin" "nodejs-zmecm" -# runTest "GitHubPullRequestPlugin" "github-pr-plugin" -# } - -setupTestEnvironment -# runTests -finishReport diff --git a/.ci/openshift-ci/plugins-test-pod.yaml b/.ci/openshift-ci/plugins-test-pod.yaml deleted file mode 100644 index 426437efee..0000000000 --- a/.ci/openshift-ci/plugins-test-pod.yaml +++ /dev/null @@ -1,77 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: POD_NAME - namespace: plugin-registry-test -spec: - volumes: - - name: test-run-results - - name: dshm - emptyDir: - medium: Memory - containers: - # container containing the tests - - name: plugins-test - image: quay.io/eclipse/che-e2e:next - imagePullPolicy: Always - env: - - name: TS_GITHUB_USERNAME - value: GH_USERNAME - - name: TS_GITHUB_PASSWORD - value: GH_PASSWORD - - name: E2E_OPENSHIFT_TOKEN - value: OCP_TOKEN - - name: TS_SELENIUM_OCP_USERNAME - value: 'user' - - name: TS_SELENIUM_OCP_PASSWORD - value: 'user' - - name: TS_SELENIUM_VALUE_OPENSHIFT_OAUTH - value: 'true' - - name: TS_SELENIUM_USERNAME - value: 'admin' - - name: TS_SELENIUM_PASSWORD - value: 'admin' - - name: TS_OCP_LOGIN_PAGE_PROVIDER_TITLE - value: 'htpasswd' - - name: TEST_SUITE - value: test-plugin-ci - - name: USERSTORY - value: TEST_USERSTORY - - name: NODE_TLS_REJECT_UNAUTHORIZED - value: '0' - - name: TS_SELENIUM_BASE_URL - value: CHE_URL - - name: TS_SELENIUM_LOG_LEVEL - value: DEBUG - - name: TS_SELENIUM_MULTIUSER - value: 'true' - - name: TS_SELENIUM_VALUE_TLS_SUPPORT - value: 'true' - - name: TS_SELENIUM_W3C_CHROME_OPTION - value: 'true' - volumeMounts: - - name: test-run-results - mountPath: /tmp/e2e/report/ - - name: dshm - mountPath: /dev/shm - resources: - requests: - memory: "4Gi" - cpu: "2000m" - limits: - memory: "8Gi" - cpu: "4000m" -# Download results - - name: download-reports - image: quay.io/ohrimenko1988/rsync:latest - imagePullPolicy: IfNotPresent - volumeMounts: - - name: test-run-results - mountPath: /tmp/e2e/report/ - command: ["sh"] - args: - [ - "-c", - "while true; if [[ -f /tmp/done ]]; then exit 0; fi; do sleep 1; done", - ] - restartPolicy: Never diff --git a/.ci/openshift-ci/smoke-test.sh b/.ci/openshift-ci/smoke-test.sh index 5f2c368ccb..747d20f3bc 100755 --- a/.ci/openshift-ci/smoke-test.sh +++ b/.ci/openshift-ci/smoke-test.sh @@ -1,34 +1,32 @@ #!/bin/bash # -# Copyright (c) 2021 Red Hat, Inc. +# Copyright (c) 2023 Red Hat, Inc. # This program and the accompanying materials are made # available under the terms of the Eclipse Public License 2.0 # which is available at https://www.eclipse.org/legal/epl-2.0/ # # SPDX-License-Identifier: EPL-2.0 # - -################################ !!! IMPORTANT !!! ################################ -########### THIS JOB USE openshift ci operators workflows to run ##################### -########## More info about how it is configured can be found here: https://docs.ci.openshift.org/docs/how-tos/testing-operator-sdk-operators ############# -####################################################################################################################################################### +# Contributors: +# Red Hat, Inc. - initial API and implementation +# # exit immediately when a command fails -set -e +set -ex # only exit with zero if all commands of the pipeline exit successfully set -o pipefail +export PUBLIC_REPO_URL=${PUBLIC_REPO_URL:-"https://github.com/chepullreq1/public-repo.git"} +export CHE_CODE_EDITOR_ID=che-incubator/che-code/latest + # import common test functions SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -# shellcheck source=./.ci/openshift-ci/common-functions.sh +# shellcheck disable=SC1091,SC1090 source "${SCRIPT_DIR}"/common-functions.sh -runTests() { - runTest "VscodeYamlPlugin" "nodejs-zmecm" - runTest "TypescriptPlugin" "typescript-debug-plugins" -} +trap "catchFinish" EXIT SIGINT + +setupTestEnvironment "${OCP_NON_ADMIN_USER_NAME}" -# should be reworked in case of https://github.com/eclipse/che/issues/21210 -# setupTestEnvironment -# runTests -# finishReport +# test starting workspace with che-code editor +testStartWorkspace "${PUBLIC_REPO_WORKSPACE_NAME}" "${PUBLIC_PROJECT_NAME}" "${PUBLIC_REPO_URL}" "${ADMIN_CHE_NAMESPACE}" "${CHE_CODE_EDITOR_ID}" diff --git a/.github/workflows/happy-path.yaml b/.github/workflows/happy-path.yaml deleted file mode 100644 index b8ce3fe30f..0000000000 --- a/.github/workflows/happy-path.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (c) 2021 Red Hat, Inc. -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# - -# che-plugin-registry Happy Path workflow -name: Happy Path - -on: - pull_request: - paths: - - '**/*' - - '!sidecars/**' - push: - paths: - - '**/*' - - '!sidecars/**' - -jobs: - happy-path: - runs-on: ubuntu-22.04 - steps: - - name: Clone source code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Clone source code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - name: Cache yarn dependencies - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: image-build - run: | - export SKIP_FORMAT=true - export SKIP_LINT=true - export SKIP_TEST=true - docker pull quay.io/eclipse/che-plugin-registry:next - # save locally built image - docker save -o docker-image.tar quay.io/eclipse/che-plugin-registry:happy-path - - name: Start minikube - id: run-minikube - uses: che-incubator/setup-minikube-action@next - with: - minikube-version: v1.21.0 - - name: load-image-minikube-registry - id: load-image-minikube-registry - run: | - # load image in the docker registry - eval $(minikube docker-env) - docker load --input=docker-image.tar - # display images - docker images - - name: Deploy Eclipse Che - id: deploy-che - uses: che-incubator/che-deploy-action@next - with: - # use custom image built by this PR - plugin-registry-image: quay.io/eclipse/che-plugin-registry:happy-path - - name: Run Happy Path tests - id: run-happy-path-tests - uses: che-incubator/happy-path-tests-action@next - with: - che-url: ${{ steps.deploy-che.outputs.che-url }} diff --git a/.github/workflows/smoke-test-pr-check.yaml b/.github/workflows/smoke-test-pr-check.yaml new file mode 100644 index 0000000000..55a3de6e89 --- /dev/null +++ b/.github/workflows/smoke-test-pr-check.yaml @@ -0,0 +1,133 @@ +# +# Copyright (c) 2023 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +name: Smoke Test + +# Trigger the workflow on pull request +on: + pull_request: + paths-ignore: + - '**/*.md' + - devfile.yaml + - '.ci/*' +env: + LOCAL_TEST_DIR: /tmp +jobs: + smoke-test: + runs-on: ubuntu-22.04 + steps: + + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Build plugin registry image + run: | + # eval $(minikube docker-env) + BUILDER=docker SKIP_FORMAT=true SKIP_LINT=true SKIP_TEST=true ./build.sh --tag next + docker save -o /tmp/che-plugin-registry-next.tar quay.io/eclipse/che-plugin-registry:next + + - name: Display docker images + run: | + docker images + + - name: Cleanup docker images + run: | + docker system prune -af + + - name: Disk free + run: | + df -h + + - name: Start minikube + id: run-minikube + uses: che-incubator/setup-minikube-action@next + with: + minikube-version: v1.31.0 + + - name: Install chectl + run: bash <(curl -sL https://www.eclipse.org/che/chectl/) --channel=next + + - name: Check that plugin registry image is present in the image list + run: minikube image list --format table + + - name: Deploy Che + run: | + # + # load plugin registry image from /tmp/che-plugin-registry-next.tar + # + eval $(minikube docker-env) && docker load -i /tmp/che-plugin-registry-next.tar && rm /tmp/che-plugin-registry-next.tar + minikube image list --format table + + # + # deploy Che + # + chectl server:deploy \ + --batch \ + --platform minikube \ + --k8spodwaittimeout=140000 \ + --k8spodreadytimeout=140000 \ + --che-operator-cr-patch-yaml "${GITHUB_WORKSPACE}/build/dev/github-minikube-checluster-patch.yaml" + + - name: Run smoke test + run: | + docker run \ + --shm-size=2048m \ + -p 5920:5920 \ + --network="host" \ + -e TS_SELENIUM_LOAD_PAGE_TIMEOUT=60000 \ + -e TS_SELENIUM_USERNAME=che@eclipse.org \ + -e TS_SELENIUM_PASSWORD=admin \ + -e TS_SELENIUM_BASE_URL=https://$(kubectl get ingress che -n eclipse-che -o jsonpath='{.spec.rules[0].host}') \ + -e DELETE_WORKSPACE_ON_FAILED_TEST=true \ + -e TS_SELENIUM_START_WORKSPACE_TIMEOUT=120000 \ + -e NODE_TLS_REJECT_UNAUTHORIZED=0 \ + -e VIDEO_RECORDING=true \ + -e TS_SELENIUM_LOG_LEVEL=TRACE \ + -e TS_WAIT_LOADER_PRESENCE_TIMEOUT=120000 \ + -e TS_COMMON_DASHBOARD_WAIT_TIMEOUT=30000 \ + -v ${LOCAL_TEST_DIR}/tests/e2e/report:/tmp/e2e/report:Z \ + -v ${LOCAL_TEST_DIR}/tests/e2e/video:/tmp/ffmpeg_report:Z \ + -e USERSTORY=SmokeTest \ + -e TS_SELENIUM_VALUE_OPENSHIFT_OAUTH=false \ + -e TEST_REPO=https://github.com/che-incubator/quarkus-api-example?df=smoke-test.devfile.yaml \ + quay.io/mmusiien/che-e2e:smoke-test + + - name: Bump logs + if: always() + run: | + NS=admin-che + TARGET_DIR="/tmp/devworkspace-happy-path-artifacts/${NS}-info" + mkdir -p "$TARGET_DIR" + for POD in $(kubectl get pods -o name -n ${NS}); do + for CONTAINER in $(kubectl get -n ${NS} ${POD} -o jsonpath="{.spec.containers[*].name}"); do + echo "[INFO] Downloading logs $POD/$CONTAINER in $NS" + # container name includes `pod/` prefix. remove it + LOGS_FILE=$TARGET_DIR/$(echo ${POD}-${CONTAINER}.log | sed 's|pod/||g') + kubectl logs ${POD} -c ${CONTAINER} -n ${NS} > $LOGS_FILE || true + done + done + echo "[INFO] Bumping events in namespace ${NS}" + kubectl get events -n $NS > $TARGET_DIR/events.log || true + + - name: Store e2e artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: e2e-artifacts + path: /tmp/tests + + - name: Store k8s logs + if: always() + uses: actions/upload-artifact@v3 + with: + name: k8s-logs + path: /tmp/devworkspace-happy-path-artifacts/admin-che-info diff --git a/build/dev/github-minikube-checluster-patch.yaml b/build/dev/github-minikube-checluster-patch.yaml new file mode 100644 index 0000000000..528bb56308 --- /dev/null +++ b/build/dev/github-minikube-checluster-patch.yaml @@ -0,0 +1,77 @@ +# +# Copyright (c) 2023 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +apiVersion: org.eclipse.che/v2 +spec: + components: + pluginRegistry: + deployment: + containers: + - imagePullPolicy: IfNotPresent + resources: + request: + cpu: '10m' + limits: + cpu: '10m' + devfileRegistry: + deployment: + containers: + - resources: + request: + cpu: '10m' + limits: + cpu: '10m' + cheServer: + deployment: + containers: + - resources: + limits: + cpu: '300m' + request: + cpu: '300m' + dashboard: + deployment: + containers: + - resources: + request: + cpu: '40m' + limits: + cpu: '40m' + networking: + auth: + gateway: + deployment: + containers: + - name: gateway + resources: + request: + cpu: '20m' + limits: + cpu: '20m' + - name: configbump + resources: + request: + cpu: '20m' + limits: + cpu: '20m' + - name: oauth-proxy + resources: + request: + cpu: '20m' + limits: + cpu: '20m' + - name: kube-rbac-proxy + resources: + request: + cpu: '20m' + limits: + cpu: '20m'