Building custom k6 container image

Our performance tests project is complex, we have +40 .js files, csv feeder files and use custom extensions, so we need to bundle all of that in a single image.

We want things to be version controlled, deploy performance tests in a cloud-native way and the image to be compatible with official k6 image.

# Build the k6 binary with the extension
FROM golang:1.20 as builder

RUN go install
# Update when changing this
RUN xk6 build v0.43.0 \
  --with \

FROM grafana/k6:0.43.0
COPY --from=builder /go/k6 /usr/bin/k6


COPY resources/ /opt/resources/
COPY tests/ /opt/tests/
COPY src/ /opt/

ENTRYPOINT ["/opt/"]

Our simplified looks like this:


k6 run --paused \
    --out influxdb=http://influxdb:8086/k6 \
    --no-color \

You can of course bundle this command in the container image under ENTRYPOINT, but I pass over 20 environment flags here, so I want this to be in a separate file.