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