From e1e42f2b12fcae8270be770b855015d852c26b98 Mon Sep 17 00:00:00 2001 From: kkanova Date: Mon, 10 Jun 2019 13:00:26 +0200 Subject: [PATCH 1/4] Add dockerfile to execute E2E Che 7 typescript tests. Signed-off-by: kkanova --- dockerfiles/e2e/Dockerfile | 47 +++++++++++++++++++++++++++ dockerfiles/e2e/README.md | 48 ++++++++++++++++++++++++++++ dockerfiles/e2e/docker-entrypoint.sh | 25 +++++++++++++++ dockerfiles/e2e/google-chrome.repo | 6 ++++ 4 files changed, 126 insertions(+) create mode 100644 dockerfiles/e2e/Dockerfile create mode 100644 dockerfiles/e2e/README.md create mode 100755 dockerfiles/e2e/docker-entrypoint.sh create mode 100644 dockerfiles/e2e/google-chrome.repo diff --git a/dockerfiles/e2e/Dockerfile b/dockerfiles/e2e/Dockerfile new file mode 100644 index 0000000000..255e81c410 --- /dev/null +++ b/dockerfiles/e2e/Dockerfile @@ -0,0 +1,47 @@ +# Copyright (c) 2019 Red Hat, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html + +FROM library/centos:centos7 + +ENV LANG=en_US.utf8 \ + DISPLAY=:99 \ + FABRIC8_USER_NAME=fabric8 + +COPY google-chrome.repo /etc/yum.repos.d/google-chrome.repo +RUN yum install --assumeyes epel-release && \ + yum update --assumeyes && \ + yum install --assumeyes google-chrome-stable && \ + yum install --assumeyes \ + xorg-x11-server-Xvfb \ + git \ + unzip \ + centos-release-scl && \ + yum install --assumeyes nodejs && \ + npm install -g typescript && \ + yum install jq --assumeyes && \ + yum install x11vnc --assumeyes && \ + yum clean all --assumeyes && \ + rm -rf /var/cache/yum && \ + # Get compatible versions of chrome and chromedriver + chrome_version=$(google-chrome --version | grep -oiE "[0-9]*\.[0-9]*\.[0-9]*") && \ + chromedriver_version=$(curl -s -g https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chrome_version}) && \ + $(curl -sS -g https://chromedriver.storage.googleapis.com/${chromedriver_version}/chromedriver_linux64.zip > chromedriver_linux64.zip) && \ + unzip chromedriver_linux64.zip && mv chromedriver /usr/bin/chromedriver && chmod +x /usr/bin/chromedriver && rm chromedriver_linux64.zip && \ + # Clone e2e from eclipse/che repo. + cd root && \ + git init && \ + git remote add upstream https://github.com/eclipse/che.git && \ + git config core.sparsecheckout true && \ + echo "e2e/*" >> .git/info/sparse-checkout && \ + git pull --depth=1 upstream master && \ + # Download all dependencies for e2e tests + cd e2e && \ + npm --silent i + +WORKDIR /root/ +COPY docker-entrypoint.sh /root/ + +ENTRYPOINT ["/root/docker-entrypoint.sh"] \ No newline at end of file diff --git a/dockerfiles/e2e/README.md b/dockerfiles/e2e/README.md new file mode 100644 index 0000000000..f4c7d7be2f --- /dev/null +++ b/dockerfiles/e2e/README.md @@ -0,0 +1,48 @@ +# End-to-end typescript tests for Che 7 + +## Table Of Content + +* [Requirements](#requirements) +* [What are these tests meant for](#what-are-these-tests-meant-for) +* [How to run it](#how-to-run-it) + +##Requirements +To run these tests you need to have running Che instance. You can execute tests directly using ` npm ` but if you like to use this Docker image, you need to have +installed Docker on your machine. + +## What are these tests meant for +These tests serves for testing Che 7 happy path. You can see description about these tests here: https://github.com/eclipse/che/tree/master/e2e. + +## How to run it +The easiest way is to run them via Docker. To build&run locally you have go to this folder and execute following command: + +``` +docker build -t che7_tests . +``` +This command builds docker +image named ` che7_tests `. +Once image is build, you can run the tests inside this docker image. You have to set URL of running Che and increase shared memory size (low shared memory makes chrome driver crash). + +``` +docker run --shm-size=256m -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +``` + +If you want to gather screenshots of fallen tests, you have to mount a volume to the docker file. Create a folder, when you want to have the screenshots saved. Then run +a command: + +``` +docker run --shm-size=256m -v /full/path/to/your/folder:/root/e2e/report:Z -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +``` + +###Debugging +####Running own code +If you have done some changes locally and you want to test them, you can mount your code directly to the Docker. If you do so, your mounted code will be executed instead of the code from master. + +``` +docker run --shm-size=256m -v /full/path/to/your/e2e/folder:/root/local_tests:Z -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +``` + +NOTE: If you want to run your own code and gather screenshots, you have to change the mount from ` /root/e2e/report:Z ` to ` /root/local_tests/report:Z `. + +####Watching Chrome +If you want to see what is going on in chrome inside a docker, you can use VNC. When running a docker, you can see API where you can connect. This API is on the first line of output and can look like that: ` You can wath localy using VNC with IP: 172.17.0.2 `. Then you can easily join VNC using this API: ` 172.17.0.2:0 `. \ No newline at end of file diff --git a/dockerfiles/e2e/docker-entrypoint.sh b/dockerfiles/e2e/docker-entrypoint.sh new file mode 100755 index 0000000000..542e8fd383 --- /dev/null +++ b/dockerfiles/e2e/docker-entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ -z $TS_SELENIUM_BASE_URL ]; then + echo "TS_SELENIUM_BASE_URL is not set!"; + exit 1 +fi + +chromedriver & +/usr/bin/Xvfb :1 -screen 0 1920x1080x24 +extension RANDR > /dev/null 2>&1 & +x11vnc -display :1.0 > /dev/null 2>&1 & +export DISPLAY=:1.0 + +hostname=$(hostname -I) +echo "You can wath localy using VNC with IP: $hostname" + +if mount | grep 'local_tests'; then + echo "The local scripts are mounted. Executing local scripts." + cd local_tests + npm i +else + echo "Executing e2e tests from master branch." + cd e2e +fi + +npm run test \ No newline at end of file diff --git a/dockerfiles/e2e/google-chrome.repo b/dockerfiles/e2e/google-chrome.repo new file mode 100644 index 0000000000..7045b11c32 --- /dev/null +++ b/dockerfiles/e2e/google-chrome.repo @@ -0,0 +1,6 @@ +[google-chrome] +name=google-chrome +baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch +enabled=1 +gpgcheck=1 +gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub \ No newline at end of file From 791b014b64e53ce5ccee5f9d8c6e5931993694cf Mon Sep 17 00:00:00 2001 From: kkanova Date: Wed, 19 Jun 2019 08:55:50 +0200 Subject: [PATCH 2/4] Add source code from current branch, not clone from master. Signed-off-by: kkanova --- dockerfiles/e2e/Dockerfile | 10 ++-------- dockerfiles/e2e/README.md | 19 +++++++++---------- dockerfiles/e2e/build.sh | 27 +++++++++++++++++++++++++++ dockerfiles/e2e/docker-entrypoint.sh | 6 +++--- 4 files changed, 41 insertions(+), 21 deletions(-) create mode 100755 dockerfiles/e2e/build.sh diff --git a/dockerfiles/e2e/Dockerfile b/dockerfiles/e2e/Dockerfile index 255e81c410..a6c3202a22 100644 --- a/dockerfiles/e2e/Dockerfile +++ b/dockerfiles/e2e/Dockerfile @@ -11,6 +11,7 @@ ENV LANG=en_US.utf8 \ FABRIC8_USER_NAME=fabric8 COPY google-chrome.repo /etc/yum.repos.d/google-chrome.repo +COPY e2e /root/e2e RUN yum install --assumeyes epel-release && \ yum update --assumeyes && \ yum install --assumeyes google-chrome-stable && \ @@ -30,15 +31,8 @@ RUN yum install --assumeyes epel-release && \ chromedriver_version=$(curl -s -g https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chrome_version}) && \ $(curl -sS -g https://chromedriver.storage.googleapis.com/${chromedriver_version}/chromedriver_linux64.zip > chromedriver_linux64.zip) && \ unzip chromedriver_linux64.zip && mv chromedriver /usr/bin/chromedriver && chmod +x /usr/bin/chromedriver && rm chromedriver_linux64.zip && \ - # Clone e2e from eclipse/che repo. - cd root && \ - git init && \ - git remote add upstream https://github.com/eclipse/che.git && \ - git config core.sparsecheckout true && \ - echo "e2e/*" >> .git/info/sparse-checkout && \ - git pull --depth=1 upstream master && \ # Download all dependencies for e2e tests - cd e2e && \ + cd /root/e2e && \ npm --silent i WORKDIR /root/ diff --git a/dockerfiles/e2e/README.md b/dockerfiles/e2e/README.md index f4c7d7be2f..5697490443 100644 --- a/dockerfiles/e2e/README.md +++ b/dockerfiles/e2e/README.md @@ -14,35 +14,34 @@ installed Docker on your machine. These tests serves for testing Che 7 happy path. You can see description about these tests here: https://github.com/eclipse/che/tree/master/e2e. ## How to run it -The easiest way is to run them via Docker. To build&run locally you have go to this folder and execute following command: +The easiest way is to run them via Docker. To build locally you have go to ` dockerfiles ` folder and execute following command: ``` -docker build -t che7_tests . +./e2e/build.sh ``` -This command builds docker -image named ` che7_tests `. -Once image is build, you can run the tests inside this docker image. You have to set URL of running Che and increase shared memory size (low shared memory makes chrome driver crash). +This command builds docker image named ` eclipse/che-e2e:nightly `. This image is build nightly and pushed to registry, so you don't have to build that image locally. +You can run the tests inside this docker image. You have to set URL of running Che and increase shared memory size (low shared memory makes chrome driver crash). ``` -docker run --shm-size=256m -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +docker run --shm-size=256m -e THEIA_SELENIUM_BASE_URL=$URL eclipse/che-e2e:nightly ``` If you want to gather screenshots of fallen tests, you have to mount a volume to the docker file. Create a folder, when you want to have the screenshots saved. Then run a command: ``` -docker run --shm-size=256m -v /full/path/to/your/folder:/root/e2e/report:Z -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +docker run --shm-size=256m -v /full/path/to/your/folder:/root/e2e/report:Z -e THEIA_SELENIUM_BASE_URL=$URL eclipse/che-e2e:nightly ``` ###Debugging ####Running own code -If you have done some changes locally and you want to test them, you can mount your code directly to the Docker. If you do so, your mounted code will be executed instead of the code from master. +If you have done some changes locally and you want to test them, you can mount your code directly to the Docker. If you do so, your mounted code will be executed instead of the code that is already in an image. ``` -docker run --shm-size=256m -v /full/path/to/your/e2e/folder:/root/local_tests:Z -e THEIA_SELENIUM_BASE_URL=$URL che7_tests +docker run --shm-size=256m -v /full/path/to/your/e2e/folder:/root/local_tests:Z -e THEIA_SELENIUM_BASE_URL=$URL eclipse/che-e2e:nightly ``` NOTE: If you want to run your own code and gather screenshots, you have to change the mount from ` /root/e2e/report:Z ` to ` /root/local_tests/report:Z `. ####Watching Chrome -If you want to see what is going on in chrome inside a docker, you can use VNC. When running a docker, you can see API where you can connect. This API is on the first line of output and can look like that: ` You can wath localy using VNC with IP: 172.17.0.2 `. Then you can easily join VNC using this API: ` 172.17.0.2:0 `. \ No newline at end of file +If you want to see what is going on in chrome inside a docker, you can use VNC. When running a docker, you can see API where you can connect. This API is on the first line of output and can look like that: ` You can watch locally using VNC with IP: 172.17.0.2 `. Then you can easily join VNC using this API: ` 172.17.0.2:0 `. diff --git a/dockerfiles/e2e/build.sh b/dockerfiles/e2e/build.sh new file mode 100755 index 0000000000..012be060af --- /dev/null +++ b/dockerfiles/e2e/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Copyright (c) 2017 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 +# + +base_dir=$(cd "$(dirname "$0")"; pwd) +. "${base_dir}"/../build.include + +E2E_DIR="${base_dir}/../../e2e" +LOCAL_E2E_DIR="${base_dir}/e2e" + +if [ -d $LOCAL_E2E_DIR ]; then + rm -rf $LOCAL_E2E_DIR +fi + +echo "Copying source code ${E2E_DIR} --> ${LOCAL_E2E_DIR}" +cp -r "${E2E_DIR}" "${LOCAL_E2E_DIR}" + +init --name:e2e "$@" +build + +# cleanup +rm -rf $LOCAL_E2E_DIR diff --git a/dockerfiles/e2e/docker-entrypoint.sh b/dockerfiles/e2e/docker-entrypoint.sh index 542e8fd383..1623129c99 100755 --- a/dockerfiles/e2e/docker-entrypoint.sh +++ b/dockerfiles/e2e/docker-entrypoint.sh @@ -11,14 +11,14 @@ x11vnc -display :1.0 > /dev/null 2>&1 & export DISPLAY=:1.0 hostname=$(hostname -I) -echo "You can wath localy using VNC with IP: $hostname" +echo "You can watch locally using VNC with IP: $hostname" if mount | grep 'local_tests'; then - echo "The local scripts are mounted. Executing local scripts." + echo "The local code is mounted. Executing local code." cd local_tests npm i else - echo "Executing e2e tests from master branch." + echo "Executing e2e tests from an image." cd e2e fi From 168aa3e6b1cdc1bfce0b0692d61d4edd4be5cc5e Mon Sep 17 00:00:00 2001 From: kkanova Date: Tue, 2 Jul 2019 09:11:12 +0200 Subject: [PATCH 3/4] Keeping docker layers the same Signed-off-by: kkanova --- dockerfiles/e2e/Dockerfile | 17 ++++++++++------- dockerfiles/e2e/docker-entrypoint.sh | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dockerfiles/e2e/Dockerfile b/dockerfiles/e2e/Dockerfile index a6c3202a22..9aa84f4a68 100644 --- a/dockerfiles/e2e/Dockerfile +++ b/dockerfiles/e2e/Dockerfile @@ -9,9 +9,9 @@ FROM library/centos:centos7 ENV LANG=en_US.utf8 \ DISPLAY=:99 \ FABRIC8_USER_NAME=fabric8 - + COPY google-chrome.repo /etc/yum.repos.d/google-chrome.repo -COPY e2e /root/e2e + RUN yum install --assumeyes epel-release && \ yum update --assumeyes && \ yum install --assumeyes google-chrome-stable && \ @@ -30,12 +30,15 @@ RUN yum install --assumeyes epel-release && \ chrome_version=$(google-chrome --version | grep -oiE "[0-9]*\.[0-9]*\.[0-9]*") && \ chromedriver_version=$(curl -s -g https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chrome_version}) && \ $(curl -sS -g https://chromedriver.storage.googleapis.com/${chromedriver_version}/chromedriver_linux64.zip > chromedriver_linux64.zip) && \ - unzip chromedriver_linux64.zip && mv chromedriver /usr/bin/chromedriver && chmod +x /usr/bin/chromedriver && rm chromedriver_linux64.zip && \ - # Download all dependencies for e2e tests - cd /root/e2e && \ + unzip chromedriver_linux64.zip && mv chromedriver /usr/bin/chromedriver && chmod +x /usr/bin/chromedriver && rm chromedriver_linux64.zip + +COPY e2e/package.json e2e/package-lock.json /root/e2e/ +RUN cd /root/e2e && \ npm --silent i -WORKDIR /root/ +COPY e2e /root/e2e COPY docker-entrypoint.sh /root/ -ENTRYPOINT ["/root/docker-entrypoint.sh"] \ No newline at end of file +WORKDIR /root/ + +ENTRYPOINT ["/root/docker-entrypoint.sh"] diff --git a/dockerfiles/e2e/docker-entrypoint.sh b/dockerfiles/e2e/docker-entrypoint.sh index 1623129c99..1450d0b898 100755 --- a/dockerfiles/e2e/docker-entrypoint.sh +++ b/dockerfiles/e2e/docker-entrypoint.sh @@ -22,4 +22,4 @@ else cd e2e fi -npm run test \ No newline at end of file +npm run test From 337c4bf063eea0fce6b9b92bf92e25f56642c53d Mon Sep 17 00:00:00 2001 From: kkanova Date: Tue, 2 Jul 2019 09:40:19 +0200 Subject: [PATCH 4/4] Address minor changes. Signed-off-by: kkanova --- dockerfiles/e2e/docker-entrypoint.sh | 11 ++++++++--- dockerfiles/e2e/google-chrome.repo | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dockerfiles/e2e/docker-entrypoint.sh b/dockerfiles/e2e/docker-entrypoint.sh index 1450d0b898..6b4e778f90 100755 --- a/dockerfiles/e2e/docker-entrypoint.sh +++ b/dockerfiles/e2e/docker-entrypoint.sh @@ -1,6 +1,11 @@ #!/bin/bash +# Copyright (c) 2019 Red Hat, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html -if [ -z $TS_SELENIUM_BASE_URL ]; then +if [ -z "$TS_SELENIUM_BASE_URL" ]; then echo "TS_SELENIUM_BASE_URL is not set!"; exit 1 fi @@ -15,11 +20,11 @@ echo "You can watch locally using VNC with IP: $hostname" if mount | grep 'local_tests'; then echo "The local code is mounted. Executing local code." - cd local_tests + cd local_tests || exit npm i else echo "Executing e2e tests from an image." - cd e2e + cd e2e || exit fi npm run test diff --git a/dockerfiles/e2e/google-chrome.repo b/dockerfiles/e2e/google-chrome.repo index 7045b11c32..3103e30c71 100644 --- a/dockerfiles/e2e/google-chrome.repo +++ b/dockerfiles/e2e/google-chrome.repo @@ -3,4 +3,4 @@ name=google-chrome baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch enabled=1 gpgcheck=1 -gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub \ No newline at end of file +gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub