From 88769c1852a5bf37cca871c2035cc7293155b597 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 12:51:13 +0100 Subject: [PATCH 01/12] ci: run e2e tests --- .ci/Jenkinsfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index c808f6a6..a4479d8b 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -105,6 +105,22 @@ pipeline { } } + stage('E2e Test') { + steps { + withGithubNotify(context: 'E2e Test') { + cleanup() + withNodeEnv(){ + dir("${BASE_DIR}"){ + sh(label: 'install dependencies',script: 'npm i') + dir("__tests__/e2e"){ + sh(label: 'run e2e tests',script: 'npm run test') + } + } + } + } + } + } + /** Publish Docker images. */ From 2c0960ef3aa20f52f694623a8013c59b8e1110cc Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 13:11:29 +0100 Subject: [PATCH 02/12] test: shot the script output --- __tests__/e2e/scripts/setup.sh | 3 +-- __tests__/e2e/scripts/test.sh | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/__tests__/e2e/scripts/setup.sh b/__tests__/e2e/scripts/setup.sh index 4c9cc48c..452d9e36 100755 --- a/__tests__/e2e/scripts/setup.sh +++ b/__tests__/e2e/scripts/setup.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -xe # variables @@ -32,4 +32,3 @@ echo "${bold}Starting elasticsearch , kibana and synthetics docker${normal}" echo "" # newline STACK_VERSION=7.10.0 docker-compose --file docker-compose.yml up --remove-orphans > ${TMP_DIR}/docker-logs.log 2>&1 & - diff --git a/__tests__/e2e/scripts/test.sh b/__tests__/e2e/scripts/test.sh index 8254a384..7ecfbe1a 100755 --- a/__tests__/e2e/scripts/test.sh +++ b/__tests__/e2e/scripts/test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -xe # formatting @@ -22,5 +22,3 @@ echo "✅ Setup completed successfully. Running e2e tests..." ################################################## npx @elastic/synthetics uptime.journey.ts - - From f2fea1b448c210bb0b15848775ac57322530de09 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 16:38:36 +0100 Subject: [PATCH 03/12] test: format only on local environments --- __tests__/e2e/scripts/setup.sh | 8 +++++--- __tests__/e2e/scripts/test.sh | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/__tests__/e2e/scripts/setup.sh b/__tests__/e2e/scripts/setup.sh index 452d9e36..7bd24f34 100755 --- a/__tests__/e2e/scripts/setup.sh +++ b/__tests__/e2e/scripts/setup.sh @@ -10,9 +10,11 @@ if [ $? -ne 0 ]; then exit 1 fi -# formatting -bold=$(tput bold) -normal=$(tput sgr0) +if [ -z "${JENKINS_URL}" ]; then + # formatting + bold=$(tput bold) + normal=$(tput sgr0) +fi # paths E2E_DIR="./" diff --git a/__tests__/e2e/scripts/test.sh b/__tests__/e2e/scripts/test.sh index 7ecfbe1a..f825f524 100755 --- a/__tests__/e2e/scripts/test.sh +++ b/__tests__/e2e/scripts/test.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash set -xe - -# formatting -bold=$(tput bold) -normal=$(tput sgr0) - +if [ -z "${JENKINS_URL}" ]; then + # formatting + bold=$(tput bold) + normal=$(tput sgr0) +fi # Wait for synthetics docker to start ################################################## echo "" # newline echo "${bold}Waiting for synthetics docker to start...${normal}" -until [ "`docker inspect -f {{.State.Running}} synthetics`" == "true" ]; do +until [ "$(docker inspect -f {{.State.Running}} synthetics)" == "true" ]; do sleep 0.1; done; From 8ae9674f276e0bd97ff619fbfbc80d251d20cf86 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 17:25:35 +0100 Subject: [PATCH 04/12] test: I need to debug it on site --- .ci/Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index a4479d8b..4c9980c5 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -111,6 +111,7 @@ pipeline { cleanup() withNodeEnv(){ dir("${BASE_DIR}"){ + sh('sleep 3600') sh(label: 'install dependencies',script: 'npm i') dir("__tests__/e2e"){ sh(label: 'run e2e tests',script: 'npm run test') From 85f1d2ba8fe827a8315968de4895d010a79c72ea Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 18:37:40 +0100 Subject: [PATCH 05/12] test: run Node.js native --- .ci/Jenkinsfile | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 4c9980c5..1a2fca89 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -109,9 +109,8 @@ pipeline { steps { withGithubNotify(context: 'E2e Test') { cleanup() - withNodeEnv(){ + withNodeNativeEnv(){ dir("${BASE_DIR}"){ - sh('sleep 3600') sh(label: 'install dependencies',script: 'npm i') dir("__tests__/e2e"){ sh(label: 'run e2e tests',script: 'npm run test') @@ -190,7 +189,7 @@ def cleanup(){ unstash 'source' } -def withNodeEnv(Map args=[:], Closure body){ +def withNodeInDockerEnv(Map args=[:], Closure body){ docker.image("${NODE_DOCKER_IMAGE}").inside(" --security-opt seccomp=${SECCOMP_FILE}"){ withEnv(["HOME=${WORKSPACE}"]) { body() @@ -198,6 +197,22 @@ def withNodeEnv(Map args=[:], Closure body){ } } +def withNodeEnv(Map args=[:], Closure body){ + withEnv(["HOME=${WORKSPACE}"]) { + sh(label: 'install Node.js', script: ''' + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash + export NVM_DIR="${HOME}/.nvm" + [ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh" + nvm install --lts + nvm version | head -n1 > .nvm-node-version + ''') + def node_version = readFile(file: '.nvm-node-version').trim() + withEnv(["PATH+NVM=${HOME}/.nvm/versions/node/${node_version}/bin"]){ + body() + } + } +} + def pushDockerImage(){ dir("${BASE_DIR}"){ dockerLogin(secret: "${env.DOCKERELASTIC_SECRET}", From 84a907a0f968378b870c3f1293043be843d4dadf Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 18:37:58 +0100 Subject: [PATCH 06/12] ci: sleep 10 seconds on CI --- __tests__/e2e/scripts/test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/__tests__/e2e/scripts/test.sh b/__tests__/e2e/scripts/test.sh index f825f524..c8d005db 100755 --- a/__tests__/e2e/scripts/test.sh +++ b/__tests__/e2e/scripts/test.sh @@ -5,6 +5,9 @@ if [ -z "${JENKINS_URL}" ]; then # formatting bold=$(tput bold) normal=$(tput sgr0) + SLEEP_TIME="0.1" +else + SLEEP_TIME="10" fi # Wait for synthetics docker to start @@ -12,7 +15,7 @@ fi echo "" # newline echo "${bold}Waiting for synthetics docker to start...${normal}" until [ "$(docker inspect -f {{.State.Running}} synthetics)" == "true" ]; do - sleep 0.1; + sleep ${SLEEP_TIME}; done; echo "✅ Setup completed successfully. Running e2e tests..." From 8ab027e863a2c553cb9db0318426d186c76eb43d Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 18:39:08 +0100 Subject: [PATCH 07/12] fix: typo --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 1a2fca89..00fa7e09 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -202,7 +202,7 @@ def withNodeEnv(Map args=[:], Closure body){ sh(label: 'install Node.js', script: ''' curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash export NVM_DIR="${HOME}/.nvm" - [ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh" + [ -s "${NVM_DIR}/nvm.sh" ] && \\. "${NVM_DIR}/nvm.sh" nvm install --lts nvm version | head -n1 > .nvm-node-version ''') From 95519a3d438ecb23b6e0ce82c19d8e09c369afe4 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 18:48:03 +0100 Subject: [PATCH 08/12] fix: do not stash nvm .git folder --- .ci/Jenkinsfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 00fa7e09..4ed87bff 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -49,7 +49,7 @@ pipeline { } } } - stash allowEmpty: true, name: 'source', useDefaultExcludes: false, excludes: ".npm/_cacache/**" + stash allowEmpty: true, name: 'source', useDefaultExcludes: false, excludes: ".npm/_cacache/**,.nvm/.git/**" } } /** @@ -109,7 +109,7 @@ pipeline { steps { withGithubNotify(context: 'E2e Test') { cleanup() - withNodeNativeEnv(){ + withNodeEnv(){ dir("${BASE_DIR}"){ sh(label: 'install dependencies',script: 'npm i') dir("__tests__/e2e"){ @@ -200,7 +200,11 @@ def withNodeInDockerEnv(Map args=[:], Closure body){ def withNodeEnv(Map args=[:], Closure body){ withEnv(["HOME=${WORKSPACE}"]) { sh(label: 'install Node.js', script: ''' - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash + set +x + if [ -z "$(command -v nvm)" ]; then + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash + fi + export NVM_DIR="${HOME}/.nvm" [ -s "${NVM_DIR}/nvm.sh" ] && \\. "${NVM_DIR}/nvm.sh" nvm install --lts From 2285de50851d605b2d78caac8f8e36c0ad761888 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 19:28:08 +0100 Subject: [PATCH 09/12] fix: silect curl --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 4ed87bff..d1afd905 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -202,7 +202,7 @@ def withNodeEnv(Map args=[:], Closure body){ sh(label: 'install Node.js', script: ''' set +x if [ -z "$(command -v nvm)" ]; then - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash + curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash fi export NVM_DIR="${HOME}/.nvm" From 19c36e53461588b4c3bde5bd7bf27b833370bc38 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 19:28:31 +0100 Subject: [PATCH 10/12] fix: disable strict permission checks --- __tests__/e2e/docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/__tests__/e2e/docker-compose.yml b/__tests__/e2e/docker-compose.yml index 0b148e9b..75bb447a 100644 --- a/__tests__/e2e/docker-compose.yml +++ b/__tests__/e2e/docker-compose.yml @@ -53,8 +53,7 @@ services: ELASTICSEARCH_URL: http://elasticsearch:9200 ELASTICSEARCH_HOSTS: http://elasticsearch:9200 command: - -E output.elasticsearch.hosts=["elasticsearch:9200"] - + -E output.elasticsearch.hosts=["elasticsearch:9200"] --strict.perms=false --environment container networks: - elastic From c713501c222103cedb1f49bb13e38afea25423fd Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 20:36:25 +0100 Subject: [PATCH 11/12] fix: permissions feat: set 10 min timeout --- .ci/Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index d1afd905..7949bea6 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -112,8 +112,13 @@ pipeline { withNodeEnv(){ dir("${BASE_DIR}"){ sh(label: 'install dependencies',script: 'npm i') + sh(label: 'set permissions', script: ''' + chmod -R ugo+rw examples + ''') dir("__tests__/e2e"){ - sh(label: 'run e2e tests',script: 'npm run test') + timeout(time: 10, unit: 'MINUTES') { + sh(label: 'run e2e tests',script: 'npm run test') + } } } } From 0899ed339dc0be2c3764ca784dc32d3b73acb657 Mon Sep 17 00:00:00 2001 From: kuisathaverat Date: Wed, 25 Nov 2020 21:11:54 +0100 Subject: [PATCH 12/12] chore: remove npm --- .ci/Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 7949bea6..a2662b5a 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -111,7 +111,6 @@ pipeline { cleanup() withNodeEnv(){ dir("${BASE_DIR}"){ - sh(label: 'install dependencies',script: 'npm i') sh(label: 'set permissions', script: ''' chmod -R ugo+rw examples ''')