How do I install extensions when I'm running the k6 docker image?

I’m using the loadimpact/k6 docker image and I’m trying to install this kafka extension from:

I’m in a mess trying to build a custom image with this extension and I can’t get it working. Is there a simple way to get this working? I’m using Gitlab.

I want to be able to install one of these extensions without needing to make a custom k6 image.

Relevant github issue I opened with my Dockerfile and failure:

What issues are you encountering exactly? Maybe GitHub - szkiba/xk6bundler: Bundle k6 with extensions as fast and easily as possible from @szkiba will be of help to you?

Hello, Ryan.
This might come very late, but I’ve had the same question earlier and in conclusion decided to just create docker image with prebuilt binary, sample:

FROM golang:1.16-alpine as builder
ADD . .
RUN apk --no-cache add git
RUN CGO_ENABLED=0 go install -a -trimpath -ldflags "-s -w -X$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" 
RUN go install -trimpath
RUN xk6 build --with
RUN 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

#no volumes because I initiate those in docker-compose separately, this is just for image
USER 12345

Most of the code in this Dockerfile was taken from original Dockerfile which you can get from k6 github.
Also you might get an error with “latest” version, but you can always get current(or your preferred) version from github of both k6 and modules (if you want to use ones already published).