I used the XK6 browser locally to run some additional size comparison on some images, it works great. However in our pipeline it runs with a Dockerfile. I have a question on how that would translate to a Dockerfile(it works for Prometheus XK6). I added the xk6-browser line to it, but I am running into an error.
I used the following Dockerfile
FROM golang:1.17-alpine as builder
WORKDIR "$GOPATH"/src/go.k6.io/k6
COPY . .
RUN apk --no-cache add git &&\
go install -trimpath go.k6.io/xk6/cmd/xk6@latest &&\
xk6 build --with github.com/grafana/xk6-output-prometheus-remote@latest &&\
xk6 build --with github.com/grafana/xk6-browser &&\
cp k6 "$GOPATH"/bin/k6
FROM alpine:3.13
RUN apk add --no-cache ca-certificates && \
adduser -D -u 12345 -g 12345 k6
COPY --from=builder /go/bin/k6 /usr/bin/k6
USER 12345
CMD [""]
However, when I try to run the command
docker run --rm -i -v "$PWD:/app" xk6_browser_image ./xk6-browser run /app/tests/sometest/sometest.js
It gives the following error, I also tried with quotes and without but no luck.
Thanks for the reply @ankur .
I tried your solution but this will just run k6 and not xk6-browser.
time="2022-09-06T11:49:17Z" level=error msg="Exception raised in test \"TEST NAME\". Failing the test and continuing. \nlaunching browser: exec: no command" source=console
This is locally, you see browser specific items below the green.
Is creating a single binary (called k6) that is combining k6 with xk6-output-prometheus-remote and xk6-browser. So the command I suggested earlier should work with browser tests as long as the browser is installed in the docker image.
Looking at the error message you’re now getting, the important part in that error message is:
This is telling you (and noted that the logging message isn’t perfectly clear) that it can’t launch the browser, and looking back at your dockerfile I can see that there isn’t one being installed in the image. You should be able to install chromium with apk add chromium and then run the tests. It’s worth noting here that some of the options (such as headless: false when launching a new browser) will not work in a GUI-less distro such as Alpine.
Would build a k6 binary containing the Prometheus extension, and then overwrite it with a binary containing the xk6-browser extension. So the resulting binary would be able to run xk6-browser scripts, but not use the Prometheus output.
Instead, if you want to combine both extensions in a single binary, you can pass --with more than once, so the command should be: