Skip to content

Commit

Permalink
Add docker image for e2e testing
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Ahl <cahl@redhat.com>
  • Loading branch information
chrisahl committed Jan 13, 2022
1 parent 81cb1f6 commit aafb383
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Dockerfile.cypress
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.17-linux AS builder

# FROM cypress/included:8.4.1 as production
# The below is just a copy of the above retagged and pushed to quay.io for easier pulling
#FROM quay.io/kcormier/cypress-included:latest as production
FROM quay.io/chrisahl/cypress-included:latest as production

USER root

RUN mkdir -p /idp-mgmt-operator-ui-tests/cypress_cache
ENV CYPRESS_CACHE_FOLDER=/idp-mgmt-operator-ui-tests/cypress_cache
WORKDIR /idp-mgmt-operator-ui-tests
COPY test/e2e ./test
WORKDIR /idp-mgmt-operator-ui-tests/test

#RUN npm ci
RUN ./download-clis.sh
# Make the directory writable by non-root users
RUN chmod -R go+w /idp-mgmt-operator-ui-tests

ENTRYPOINT ["./start-cypress-tests.sh"]
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif
# Image URL to use all building/pushing image targets
export IMG ?= ${PROJECT_NAME}:${IMG_TAG}
IMG_COVERAGE ?= ${PROJECT_NAME}-coverage:${IMG_TAG}
IMG_E2E_TEST ?= ${PROJECT_NAME}-e2e-test:${IMG_TAG}
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:crdVersions=v1"

Expand Down Expand Up @@ -50,7 +51,8 @@ ARCH=$(shell uname -m | sed 's/x86_64/amd64/g')
DOCKER_USER ?=
DOCKER_PASS ?=


# For cypress E2E tests
BROWSER ?= chrome

#### UTILITIES #####

Expand Down Expand Up @@ -376,3 +378,17 @@ functional-test-full-clean:
functional-test:
@echo running functional tests
ginkgo -tags functional -v --slowSpecThreshold=30 test/functional -- -v=5

.PHONY: build-e2e-test-image
build-e2e-test-image:
@echo "Building $(IMAGE_E2E_TEST)"
docker build . \
-f Dockerfile.cypress \
-t ${IMG_E2E_TEST}

#.PHONY: run-e2e-test-image
#run-e2e-test-image:
# docker run \
# -e BROWSER=$(BROWSER) \
-v $(shell pwd)/results/:/results/ \
${IMG_E2E_TEST}
23 changes: 23 additions & 0 deletions test/e2e/download-clis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Copyright Red Hat

# Install OpenShift CLI.
echo "Installing oc and kubectl clis..."
curl -kLo oc.tar.gz https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.8.24/openshift-client-linux-4.8.24.tar.gz
mkdir oc-unpacked
tar -xzf oc.tar.gz -C oc-unpacked
chmod 755 ./oc-unpacked/oc
chmod 755 ./oc-unpacked/kubectl
mv ./oc-unpacked/oc /usr/local/bin/oc
mv ./oc-unpacked/kubectl /usr/local/bin/kubectl
rm -rf ./oc-unpacked ./oc.tar.gz



# Install jq to parse json within bash scripts
curl -o /usr/local/bin/jq http://stedolan.github.io/jq/download/linux64/jq
chmod +x /usr/local/bin/jq


echo 'set up complete'
64 changes: 64 additions & 0 deletions test/e2e/run-prow-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Copyright Red Hat

set -e

###############################################################################
# Test Setup
###############################################################################

echo $SHARED_DIR

BROWSER=chrome
BUILD_WEB_URL=https://prow.ci.openshift.org/view/gs/origin-ci-test/${JOB_NAME}/${BUILD_ID}
GIT_PULL_NUMBER=$PULL_NUMBER
GIT_REPO_SLUG=${REPO_OWNER}/${REPO_NAME}
HUB_CREDS=$(cat "${SHARED_DIR}/hub-1.json")
OCM_NAMESPACE=open-cluster-management
OCM_ROUTE=multicloud-console
# Hub cluster
export KUBECONFIG="${SHARED_DIR}/hub-1.kc"

OCM_ADDRESS=https://`oc -n $OCM_NAMESPACE get route $OCM_ROUTE -o json | jq -r '.spec.host'`
export CYPRESS_BASE_URL=$OCM_ADDRESS
export CYPRESS_OC_CLUSTER_URL=$(echo $HUB_CREDS | jq -r '.api_url')
export CYPRESS_OC_CLUSTER_USER=$(echo $HUB_CREDS | jq -r '.username')
export CYPRESS_OC_CLUSTER_PASS=$(echo $HUB_CREDS | jq -r '.password')

# Cypress env variables
#export ANSIBLE_URL=$(cat "/etc/e2e-secrets/ansible-url")
#export ANSIBLE_TOKEN=$(cat "/etc/e2e-secrets/ansible-token")
export BROWSER=$BROWSER
export BUILD_WEB_URL=$BUILD_WEB_URL
export CYPRESS_JOB_ID=$PROW_JOB_ID
export CYPRESS_RBAC_TEST=$(cat "/etc/e2e-secrets/cypress-rbac-test")
export CYPRESS_TEST_MODE=BVT
#export GITHUB_PRIVATE_URL=$(cat "/etc/e2e-secrets/github-private-url")
#export GITHUB_USER=$(cat "/etc/e2e-secrets/github-user")
#export GITHUB_TOKEN=$(cat "/etc/e2e-secrets/github-token")
export GIT_PULL_NUMBER=$PULL_NUMBER
export GIT_REPO_SLUG=$GIT_REPO_SLUG
#export HELM_PRIVATE_URL=$(cat "/etc/e2e-secrets/helm-private-url")
#export HELM_USERNAME=$(cat "/etc/e2e-secrets/github-user")
#export HELM_PASSWORD=$(cat "/etc/e2e-secrets/github-token")
#export HELM_CHART_NAME=$(cat "/etc/e2e-secrets/helm-chart-name")
#export OBJECTSTORE_PRIVATE_URL=$(cat "/etc/e2e-secrets/objectstore-private-url")
#export OBJECTSTORE_ACCESS_KEY=$(cat "/etc/e2e-secrets/objectstore-access-key")
#export OBJECTSTORE_SECRET_KEY=$(cat "/etc/e2e-secrets/objectstore-secret-key")
#export SLACK_TOKEN=$(cat "/etc/e2e-secrets/slack-token")

# Workaround for "error: x509: certificate signed by unknown authority" problem with oc login
mkdir -p ${HOME}/certificates
OAUTH_POD=$(oc -n openshift-authentication get pods -o jsonpath='{.items[0].metadata.name}')
export CYPRESS_OC_CLUSTER_INGRESS_CA=/certificates/ingress-ca.crt
oc rsh -n openshift-authentication $OAUTH_POD cat /run/secrets/kubernetes.io/serviceaccount/ca.crt > ${HOME}${CYPRESS_OC_CLUSTER_INGRESS_CA}

# managed cluster
MANAGED_CREDS=$(cat "${SHARED_DIR}/managed-1.json")
export CYPRESS_MANAGED_OCP_URL=$(echo $MANAGED_CREDS | jq -r '.api_url')
export CYPRESS_MANAGED_OCP_USER=$(echo $MANAGED_CREDS | jq -r '.username')
export CYPRESS_MANAGED_OCP_PASS=$(echo $MANAGED_CREDS | jq -r '.password')
export CYPRESS_PROW="true"

echo `Running ${CYPRESS_TEST_MODE} tests`
./start-cypress-tests.sh
68 changes: 68 additions & 0 deletions test/e2e/start-cypress-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Copyright Red Hat

echo "Initiating tests..."

if [ -z "$CYPRESS_TEST_MODE" ]; then
echo "CYPRESS_TEST_MODE not exported; setting to 'e2e' mode"
export CYPRESS_TEST_MODE='e2e'
fi

if [ -z "$BROWSER" ]; then
export BROWSER="chrome"
fi

if [[ -z $CYPRESS_MANAGED_OCP_URL || -z $CYPRESS_MANAGED_OCP_USER || -z $CYPRESS_MANAGED_OCP_PASS ]]; then
echo 'One or more variables are undefined. Copying kubeconfigs...'
cp -r ~/resources/extra-import-kubeconfigs/* ./cypress/config/import-kubeconfig
else
echo "Logging into the managed cluster using credentials and generating the kubeconfig..."
mkdir -p ./import-kubeconfig && touch ./import-kubeconfig/kubeconfig
export KUBECONFIG=$(pwd)/import-kubeconfig/kubeconfig
oc login --server=$CYPRESS_MANAGED_OCP_URL -u $CYPRESS_MANAGED_OCP_USER -p $CYPRESS_MANAGED_OCP_PASS --insecure-skip-tls-verify
unset KUBECONFIG
echo "Copying managed cluster kubeconfig to ./cypress/config/import-kubeconfig ..."
cp ./import-kubeconfig/* ./cypress/config/import-kubeconfig
fi

echo "Logging into Kube API server..."
oc login --server=$CYPRESS_OC_CLUSTER_URL -u $CYPRESS_OC_CLUSTER_USER -p $CYPRESS_OC_CLUSTER_PASS --insecure-skip-tls-verify

echo "Show nodes..."
oc get nodes


if [[ "$CLEAN_UP" == "true" ]]; then
echo "Cleaning up test resources. Tests will not run."


echo "Clean up done. Exiting."
exit 0
fi


#echo "Running tests on $CYPRESS_BASE_URL in $CYPRESS_TEST_MODE mode..."
testCode=0
#npx cypress run --config-file "./cypress.json" --browser $BROWSER
#testCode=$?

#testDirectory="/results"

if [ -d "$testDirectory" ]; then
# move test results if $testDirectory exists.
echo "Copying Mocha JSON and XML output to /results..."
cp -r ./test-output/cypress/json/* /results
cp -r ./test-output/cypress/xml/* /results

echo "Copying outputed screenshots and videos to /results..."
cp -r ./cypress/screenshots /results/screenshots
cp -r ./cypress/videos /results/videos
fi

if [[ ! -z "$SLACK_TOKEN" ]]; then
echo "Slack integration is configured; processing..."
npm run test:slack
fi

exit $testCode

0 comments on commit aafb383

Please sign in to comment.