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:
https://github.com/mostafa/xk6-kafka

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
WORKDIR $GOPATH/src/go.k6.io/k6
ADD . .
RUN apk --no-cache add git
RUN CGO_ENABLED=0 go install -a -trimpath -ldflags "-s -w -X go.k6.io/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" 
RUN go install -trimpath github.com/k6io/xk6/cmd/xk6@latest
RUN xk6 build --with github.com/avitalique/xk6-file@latest
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
ENTRYPOINT ["k6"]

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).