Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 95f025a

Browse files
committed
Tweaking instructions for running against docker
Changes bring Dockerfile more in line with that of k6 itself.
1 parent c1026c9 commit 95f025a

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.idea/
12
.DS_Store
23
k6

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ COPY --from=builder /tmp/k6 /usr/bin/k6
1717
USER 12345
1818
WORKDIR /home/k6
1919

20-
# By default, the image is setup for running js scripts.
21-
ENTRYPOINT ["k6", "run"]
20+
ENTRYPOINT ["k6"]

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,26 @@ This repo includes a [docker-compose.yml](./docker-compose.yml) file that starts
6060
Clone the repo to get started and follow these steps:
6161

6262
1. Start the docker compose environment.
63-
```shell
64-
docker-compose up -d
65-
```
63+
```shell
64+
docker-compose up -d
65+
```
6666

6767
> Some users have encountered failures for the k6 build portion. A workaround may be to disable the _"Use Docker Compose V2"_ checkbox in the _General_ section of Docker Desktop settings.
6868

69-
```shell
70-
# Output
71-
Creating xk6-output-prometheus-remote_grafana_1 ... done
72-
Creating xk6-output-prometheus-remote_prometheus_1 ... done
73-
Creating xk6-output-prometheus-remote_k6_1 ... done
74-
```
75-
76-
2. Use the k6 Docker image to run the k6 script and send metrics to the Prometheus container started on the previous step. The [test.js](./example/test.js) sets a [test-wide tag](https://k6.io/docs/using-k6/tags-and-groups/#test-wide-tags) with a unique identifier to segment the metrics into discrete test runs for Grafana dashboards.
77-
```shell
78-
docker-compose run --rm k6 -<example/test.js
79-
```
69+
```shell
70+
# Output
71+
Creating xk6-output-prometheus-remote_grafana_1 ... done
72+
Creating xk6-output-prometheus-remote_prometheus_1 ... done
73+
Creating xk6-output-prometheus-remote_k6_1 ... done
74+
```
75+
76+
2. Use the k6 Docker image to run the k6 script and send metrics to the Prometheus container started on the previous step. You must [set the `testid` tag](https://k6.io/docs/using-k6/tags-and-groups/#test-wide-tags) with a unique identifier to segment the metrics into discrete test runs for the Grafana dashboards.
77+
```shell
78+
docker-compose run --rm k6 run -<example/test.js --tag testid=<SOME-ID>
79+
```
80+
For convenience, the `docker-run.sh` can be used to simply:
81+
```shell
82+
./docker-run.sh example/test.js
83+
```
8084

8185
3. Visit http://localhost:3000/ to view results in Grafana.

docker-run.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env zsh
2+
3+
#
4+
# This script simply executes a provided JavaScript test using
5+
# the local environment established with the `docker-compose`.
6+
#
7+
# Each execution is provided a unique tag to differentiate
8+
# discrete test runs within the Grafana dashboard.
9+
#
10+
11+
set -e
12+
13+
if [ $# -ne 1 ]; then
14+
echo "Usage: ./docker-run.sh <SCRIPT_NAME>"
15+
exit 1
16+
fi
17+
18+
SCRIPT_NAME=$1
19+
TAG_NAME="$(basename -s .js $SCRIPT_NAME)-$(date +%s)"
20+
21+
docker-compose run --rm k6 run -<$SCRIPT_NAME --tag testid=$TAG_NAME

0 commit comments

Comments
 (0)