Commit 24402a40 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'gy-add-load-perf-docker-options' into 'master'

Add docker options for Load Perf testing

Closes #238149

See merge request gitlab-org/gitlab!39977
parents e9e499ad f750c21f
...@@ -152,17 +152,20 @@ The CI/CD YAML configuration example above works for testing against static envi ...@@ -152,17 +152,20 @@ The CI/CD YAML configuration example above works for testing against static envi
but it can be extended to work with [review apps](../../../ci/review_apps) or but it can be extended to work with [review apps](../../../ci/review_apps) or
[dynamic environments](../../../ci/environments) with a few extra steps. [dynamic environments](../../../ci/environments) with a few extra steps.
The best approach is to capture the dynamic URL into a custom environment variable that The best approach is to capture the dynamic URL in a [`.env` file](https://docs.docker.com/compose/env-file/)
is then [inherited](../../../ci/variables/README.md#inherit-environment-variables) as a job artifact to be shared, then use a custom environment variable we've provided named `K6_DOCKER_OPTIONS`
by the `load_performance` job. The k6 test script to be run should then be configured to to configure the k6 Docker container to use the file. With this, k6 can then use any
use that environment URL, such as: ``http.get(`${__ENV.ENVIRONMENT_URL`})``. environment variables from the `.env` file in scripts using standard JavaScript,
such as: ``http.get(`${__ENV.ENVIRONMENT_URL`})``.
For example: For example:
1. In the `review` job: 1. In the `review` job:
1. Capture the dynamic URL and save it into a `.env` file, e.g. `echo "ENVIRONMENT_URL=$CI_ENVIRONMENT_URL" >> review.env`. 1. Capture the dynamic URL and save it into a `.env` file, e.g. `echo "ENVIRONMENT_URL=$CI_ENVIRONMENT_URL" >> review.env`.
1. Set the `.env` file to be an [`artifacts:reports:dotenv` report](../../../ci/variables/README.md#inherit-environment-variables). 1. Set the `.env` file to be a [job artifact](../../../ci/pipelines/job_artifacts.md#job-artifacts).
1. Set the `load_performance` job to depend on the review job, so it inherits the environment variable. 1. In the `load_performance` job:
1. Set it to depend on the review job, so it inherits the env file.
1. Set the `K6_DOCKER_OPTIONS` variable with the [Docker cli option for env files](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file), for example `--env-file review.env`.
1. Configure the k6 test script to use the environment variable in it's steps. 1. Configure the k6 test script to use the environment variable in it's steps.
Your `.gitlab-ci.yml` file might be similar to: Your `.gitlab-ci.yml` file might be similar to:
...@@ -184,15 +187,16 @@ review: ...@@ -184,15 +187,16 @@ review:
- run_deploy_script - run_deploy_script
- echo "ENVIRONMENT_URL=$CI_ENVIRONMENT_URL" >> review.env - echo "ENVIRONMENT_URL=$CI_ENVIRONMENT_URL" >> review.env
artifacts: artifacts:
reports: paths:
dotenv: - review.env
review.env
rules: rules:
- if: '$CI_COMMIT_BRANCH' # Modify to match your pipeline rules, or use `only/except` if needed. - if: '$CI_COMMIT_BRANCH' # Modify to match your pipeline rules, or use `only/except` if needed.
load_performance: load_performance:
dependencies: dependencies:
- review - review
variables:
K6_DOCKER_OPTIONS: '--env-file review.env'
rules: rules:
- if: '$CI_COMMIT_BRANCH' # Modify to match your pipeline rules, or use `only/except` if needed. - if: '$CI_COMMIT_BRANCH' # Modify to match your pipeline rules, or use `only/except` if needed.
``` ```
---
title: Add docker options for Load Perf testing
merge_request: 39977
author:
type: fixed
...@@ -8,6 +8,7 @@ load_performance: ...@@ -8,6 +8,7 @@ load_performance:
K6_VERSION: 0.27.0 K6_VERSION: 0.27.0
K6_TEST_FILE: github.com/loadimpact/k6/samples/http_get.js K6_TEST_FILE: github.com/loadimpact/k6/samples/http_get.js
K6_OPTIONS: '' K6_OPTIONS: ''
K6_DOCKER_OPTIONS: ''
services: services:
- docker:19.03.11-dind - docker:19.03.11-dind
script: script:
...@@ -17,7 +18,7 @@ load_performance: ...@@ -17,7 +18,7 @@ load_performance:
export DOCKER_HOST='tcp://localhost:2375' export DOCKER_HOST='tcp://localhost:2375'
fi fi
fi fi
- docker run --rm -v "$(pwd)":/k6 -w /k6 $K6_IMAGE:$K6_VERSION run $K6_TEST_FILE --summary-export=load-performance.json $K6_OPTIONS - docker run --rm -v "$(pwd)":/k6 -w /k6 $K6_DOCKER_OPTIONS $K6_IMAGE:$K6_VERSION run $K6_TEST_FILE --summary-export=load-performance.json $K6_OPTIONS
artifacts: artifacts:
reports: reports:
load_performance: load-performance.json load_performance: load-performance.json
......
...@@ -14,10 +14,11 @@ load_performance: ...@@ -14,10 +14,11 @@ load_performance:
K6_VERSION: 0.27.0 K6_VERSION: 0.27.0
K6_TEST_FILE: github.com/loadimpact/k6/samples/http_get.js K6_TEST_FILE: github.com/loadimpact/k6/samples/http_get.js
K6_OPTIONS: '' K6_OPTIONS: ''
K6_DOCKER_OPTIONS: ''
services: services:
- docker:stable-dind - docker:stable-dind
script: script:
- docker run --rm -v "$(pwd)":/k6 -w /k6 $K6_IMAGE:$K6_VERSION run $K6_TEST_FILE --summary-export=load-performance.json $K6_OPTIONS - docker run --rm -v "$(pwd)":/k6 -w /k6 $K6_DOCKER_OPTIONS $K6_IMAGE:$K6_VERSION run $K6_TEST_FILE --summary-export=load-performance.json $K6_OPTIONS
artifacts: artifacts:
reports: reports:
load_performance: load-performance.json load_performance: load-performance.json
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment