K6 load tests — Part VI
Containerization
A sample load test is added in the earlier sections of the series. GitHub repository - https://github.com/KavitaJadhav/k6_learning. Checkout commit ff1a928ee2d0d077165086c671b3b73377045a88.
Next, dockerize the test suit to run in the CI environment. Add Dockerfile to use golang:alpine image and install k6 inside it.
FROM golang:1.20-alpine as builder
WORKDIR /app
RUN go install go.k6.io/xk6/cmd/xk6@v0.9.2
RUN xk6 build
FROM alpine
WORKDIR /home/k6
COPY --from=builder /app /bin/
Next, build the image locally with the command:
docker build . -t k6_learning
Run a new container with the image built locally with the command:
docker run -i -v $(pwd):/home/k6 k6_learning \
k6 run v1/test.k6.io/test.js \
--config v1/test.k6.io/load-test-config.json \
--out json=summary/test.json \
-e ENVIRONMENT='uat'
Here, to increase the readability, the command is split across multiple lines. This is the print outcome along with test details and progress, which can be optimised with --quiet and --log-output options.
docker run -i -v $(pwd):/home/k6 k6_learning \
k6 run v1/test.k6.io/test.js \
--quiet --log-output=none \
--config v1/test.k6.io/load-test-config.json \
--out json=summary/test.json \
-e ENVIRONMENT='uat'
Next, integrate the SQL plugin to read from the database. Continued in Part VII.
Note: Subsequent parts of the series are available here.
Happy Testing!