Building Dockerfile for xk6-browser


I have been working on writing a Dockerfile so that I can run a xk6-browser test that I have written, but am having a lot of trouble with getting the Dockerfile to build and run properly. To create my Dockerfile, I have referenced this forum post: Then to build my Dockerfile I have been running: docker build -t testing-xk6 . . However, each time I run into the following issue:

<b>[#9]( 76.94 cp: omitting directory 'k6'
executor failed running [/bin/sh -c apk --no-cache add git && go install -trimpath []( && xk6 build --output /k6 --with []( && cp k6 "$GOPATH"/bin/k6]: exit code: 1</b>

I tried to add “-r” to the line cp k6 "$GOPATH"/bin/k6 in my Dockerfile (see below) and it seemed to work (as in the Dockerfile successfully built), however now I am running into the following issue when trying to run my test in the container:

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "k6": executable file not found in $PATH: unknown.

I am running my test with the command:
docker run --rm -i -v /Users/jlombardi/testingxk6/k6:/k6 testing-xk6 k6 run loginPageBrowserTest.js

Since I am still running into errors, I am not sure that my fix with adding “-r” actually fixed anything :frowning: My Dockerfile is pasted below. Thanks so much in advance.

FROM golang:1.18-alpine as builder
COPY . .

RUN apk --no-cache add git &&\
    go install -trimpath &&\
    xk6 build --with &&\
    cp -r k6 "$GOPATH"/bin/k6

RUN apk add chromium 

FROM alpine:3.15
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 [""]

Hi @jill.lombardi !

I quickly drafted the PR Docker example by olegbespalov · Pull Request #556 · grafana/xk6-browser · GitHub, which has an example of the Dockerfile.

Feel free to try and say if that works for you :relaxed:

Let me know if that answers,