CI and Docker
A load test belongs in a pipeline: it runs the same command every time, leaves a report as an artifact and fails the build when the result is worse than the budget. The two files below are the whole of it, and neither runs in this container: there is no network, no Docker and no CI service here, so they are shown and marked as not run.
The workflow
A GitHub Actions workflow checks out the plan, installs a JDK and JMeter, runs the same jmeter -n command as every page of this course, and lets the check script decide whether the job failed. The report is uploaded whichever way the run went.
.github/workflows/load-test.yml
name: load test
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 1"
jobs:
jmeter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
- name: Install JMeter
run: |
curl -fsSLO https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.6.3.tgz
tar -xzf apache-jmeter-5.6.3.tgz
- name: Run the plan
run: |
apache-jmeter-5.6.3/bin/jmeter -n -t plan.jmx -l results.jtl -j jmeter.log -e -o report
python3 check_jtl.py results.jtl 500
- uses: actions/upload-artifact@v4
if: always()
with:
name: jmeter-report
path: report
grep -n "jmeter -n" .github/workflows/load-test.yml
23: apache-jmeter-5.6.3/bin/jmeter -n -t plan.jmx -l results.jtl -j jmeter.log -e -o report
The line the grep prints is the contract: the CI command is the local command, so a plan that passes on a laptop is the plan the pipeline runs. What CI adds is a machine that is not the developer's, a schedule and a history of the reports.
The container
The image has a JRE and JMeter and nothing else: the plan, the data and the check script are copied into it. It is also the answer to a distributed run, where every server must have the same plan and the same plugins.
Dockerfile
FROM eclipse-temurin:21-jre-alpine
ARG JMETER_VERSION=5.6.3
RUN apk add --no-cache curl \
&& curl -fsSL "https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-${JMETER_VERSION}.tgz" \
| tar -xz -C /opt \
&& mv "/opt/apache-jmeter-${JMETER_VERSION}" /opt/jmeter
WORKDIR /test
COPY plan.jmx users.csv check_jtl.py ./
ENTRYPOINT ["/opt/jmeter/bin/jmeter"]
docker build -t jmeter-course .
docker run --rm -v "$PWD/report:/test/report" jmeter-course -n -t plan.jmx -l results.jtl -e -o report
Both commands are marked as not run: this container has no Docker daemon and no network to build the image from. The Dockerfile is the whole image, and a reader with Docker runs the two commands in a folder that holds the plan, the CSV and the check script.
The files of the folder
| File | Why it is there |
|---|---|
| plan.jmx | the plan, with its variables |
| users.csv | the data a loop reads, committed with the plan |
| check_jtl.py | the gate on errors and the latency budget |
| load-test.yml | the schedule, the JDK and the two commands |
| Dockerfile | the same run inside an image |
Related
- A Python check of a .jtl: the script the workflow runs after JMeter.
- Distributed mode: the other reason to put every server in the same image.
- The command line: every flag the two files use.
Article author: Arthur Isaev