1# Read more about the feature here: https://docs.gitlab.com/ee/user/project/merge_requests/browser_performance_testing.html 2 3browser_performance: 4 stage: performance 5 image: docker:19.03.12 6 allow_failure: true 7 variables: 8 DOCKER_TLS_CERTDIR: "" 9 SITESPEED_IMAGE: sitespeedio/sitespeed.io 10 SITESPEED_VERSION: 14.1.0 11 SITESPEED_OPTIONS: '' 12 services: 13 - docker:19.03.12-dind 14 script: 15 - | 16 if ! docker info &>/dev/null; then 17 if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then 18 export DOCKER_HOST='tcp://localhost:2375' 19 fi 20 fi 21 - export CI_ENVIRONMENT_URL=$(cat environment_url.txt) 22 - mkdir gitlab-exporter 23 # Busybox wget does not support proxied HTTPS, get the real thing. 24 # See https://gitlab.com/gitlab-org/gitlab/-/issues/287611. 25 - (env | grep -i _proxy= 2>&1 >/dev/null) && apk --no-cache add wget 26 - wget -O gitlab-exporter/index.js https://gitlab.com/gitlab-org/gl-performance/raw/1.1.0/index.js 27 - mkdir sitespeed-results 28 - | 29 function propagate_env_vars() { 30 CURRENT_ENV=$(printenv) 31 32 for VAR_NAME; do 33 echo $CURRENT_ENV | grep "${VAR_NAME}=" > /dev/null && echo "--env $VAR_NAME " 34 done 35 } 36 - | 37 if [ -f .gitlab-urls.txt ] 38 then 39 sed -i -e 's@^@'"$CI_ENVIRONMENT_URL"'@' .gitlab-urls.txt 40 docker run \ 41 $(propagate_env_vars \ 42 auto_proxy \ 43 https_proxy \ 44 http_proxy \ 45 no_proxy \ 46 AUTO_PROXY \ 47 HTTPS_PROXY \ 48 HTTP_PROXY \ 49 NO_PROXY \ 50 ) \ 51 --shm-size=1g --rm -v "$(pwd)":/sitespeed.io $SITESPEED_IMAGE:$SITESPEED_VERSION --plugins.add ./gitlab-exporter --cpu --outputFolder sitespeed-results .gitlab-urls.txt $SITESPEED_OPTIONS 52 else 53 docker run \ 54 $(propagate_env_vars \ 55 auto_proxy \ 56 https_proxy \ 57 http_proxy \ 58 no_proxy \ 59 AUTO_PROXY \ 60 HTTPS_PROXY \ 61 HTTP_PROXY \ 62 NO_PROXY \ 63 ) \ 64 --shm-size=1g --rm -v "$(pwd)":/sitespeed.io $SITESPEED_IMAGE:$SITESPEED_VERSION --plugins.add ./gitlab-exporter --cpu --outputFolder sitespeed-results "$CI_ENVIRONMENT_URL" $SITESPEED_OPTIONS 65 fi 66 - mv sitespeed-results/data/performance.json browser-performance.json 67 artifacts: 68 paths: 69 - sitespeed-results/ 70 reports: 71 browser_performance: browser-performance.json 72 rules: 73 - if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")' 74 when: never 75 - if: '$BROWSER_PERFORMANCE_DISABLED' 76 when: never 77 - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH' 78