Xk6 docker build failed

Try to build xk6 docker by using the file:

FROM golang:1.20-alpine3.17 as builder
WORKDIR $GOPATH/src/go.k6.io/k6
ADD . .
RUN apk --no-cache add git
RUN go install go.k6.io/xk6/cmd/xk6@latest
RUN xk6 build --with github.com/grafana/xk6-output-influxdb=. --output /tmp/k6

FROM alpine:3.17
RUN apk add --no-cache ca-certificates && \
    adduser -D -u 12345 -g 12345 k6
COPY --from=builder /tmp/k6 /usr/bin/k6

USER 12345
WORKDIR /home/k6
ENTRYPOINT ["k6"]

just run with docker build --tag "xk6-image-test" .

2023/06/13 17:55:44 [INFO] Temporary folder: /tmp/buildenv_2023-06-13-1755.2619543946
2023/06/13 17:55:44 [INFO] Initializing Go module
2023/06/13 17:55:44 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init k6 
go: creating new go.mod: module k6
2023/06/13 17:55:44 [INFO] Replace github.com/grafana/xk6-output-influxdb => /go/src/go.k6.io/k6
2023/06/13 17:55:44 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -replace github.com/grafana/xk6-output-influxdb=/go/src/go.k6.io/k6 
2023/06/13 17:55:44 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: warning: "all" matched no packages
2023/06/13 17:55:44 [INFO] Pinning versions
2023/06/13 17:55:44 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: finding module for package github.com/grafana/xk6-output-influxdb
k6 imports
        github.com/grafana/xk6-output-influxdb: module github.com/grafana/xk6-output-influxdb@latest found (v0.4.0, replaced by /go/src/go.k6.io/k6), but does not contain package github.com/grafana/xk6-output-influxdb
2023/06/13 17:55:44 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-06-13-1755.2619543946
2023/06/13 17:55:44 [FATAL] exit status 1

Any ideas? Thanks.

Hi @jason

Welcome to the community forum :wave:

I did try to run this locally, and it worked for me. Cloning the repo and then just running the build command.

$ git clone git@github.com:grafana/xk6-output-influxdb.git

$ cd xk6-output-influxdb

$ docker build --tag "xk6-image-test" .
 => [internal] load build definition from Dockerfile                                                                               0.1s
 => => transferring dockerfile: 451B                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                  0.0s
 => => transferring context: 2B                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/alpine:3.17                                                                     3.1s
 => [internal] load metadata for docker.io/library/golang:1.20-alpine3.17                                                          3.1s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                      0.0s
 => [auth] library/golang:pull token for registry-1.docker.io                                                                      0.0s
 => [internal] load build context                                                                                                  0.0s
 => => transferring context: 253.79kB                                                                                              0.0s
 => [builder 1/6] FROM docker.io/library/golang:1.20-alpine3.17@sha256:eeac93eabed1bf149737c9dcf5c20aeebc76e549cb275c41a86737f489  4.1s
 => => resolve docker.io/library/golang:1.20-alpine3.17@sha256:eeac93eabed1bf149737c9dcf5c20aeebc76e549cb275c41a86737f4895cc8bf    0.0s
 => => sha256:e400b76ba09597af744b844e82b0161e34fca49b288e7e96e72a0b5242668344 96.08MB / 96.08MB                                   2.4s
 => => sha256:eeac93eabed1bf149737c9dcf5c20aeebc76e549cb275c41a86737f4895cc8bf 1.65kB / 1.65kB                                     0.0s
 => => sha256:265fbf20eed8f3636a05d64e4da57127357ac835223bb62c5f7f6cf5d39bafe3 1.16kB / 1.16kB                                     0.0s
 => => sha256:4dc008c8e4eced622cd8cd1f529b1f6ab178fa64ec5f93df60d8a7004ab8e5a2 5.12kB / 5.12kB                                     0.0s
 => => sha256:edb6bdbacee93be93e930669f43e2e922c8594676aa342a70e2221361fd1914d 3.26MB / 3.26MB                                     0.3s
 => => sha256:5f9638ab26593704cd91284834993087a524142173e0782a07140496471d1385 286.37kB / 286.37kB                                 0.3s
 => => extracting sha256:edb6bdbacee93be93e930669f43e2e922c8594676aa342a70e2221361fd1914d                                         54.6s
 => => sha256:90e6192274078b2b73dbaf263a4854e57998c9ecebbb3bd3f79c57232c160864 154B / 154B                                         0.5s
 => => extracting sha256:5f9638ab26593704cd91284834993087a524142173e0782a07140496471d1385                                          0.1s
 => => extracting sha256:e400b76ba09597af744b844e82b0161e34fca49b288e7e96e72a0b5242668344                                          1.5s
 => => extracting sha256:90e6192274078b2b73dbaf263a4854e57998c9ecebbb3bd3f79c57232c160864                                          0.0s
 => [stage-1 1/4] FROM docker.io/library/alpine:3.17@sha256:e95676db9e4a4f16f6cc01a8915368f82b018cc07aba951c1bd1db586c081388       0.5s
 => => resolve docker.io/library/alpine:3.17@sha256:e95676db9e4a4f16f6cc01a8915368f82b018cc07aba951c1bd1db586c081388               0.0s
 => => sha256:e95676db9e4a4f16f6cc01a8915368f82b018cc07aba951c1bd1db586c081388 1.64kB / 1.64kB                                     0.0s
 => => sha256:f465359a4d1abc7defe7b9774a1077b2ccff79bc64aeab71a7296d13aa504a9a 528B / 528B                                         0.0s
 => => sha256:779605e5fbc087db31393c064dfca0962114a34da8c552e41d30e720aec08885 1.49kB / 1.49kB                                     0.0s
 => => sha256:edb6bdbacee93be93e930669f43e2e922c8594676aa342a70e2221361fd1914d 3.26MB / 3.26MB                                     0.3s
 => => extracting sha256:edb6bdbacee93be93e930669f43e2e922c8594676aa342a70e2221361fd1914d                                          0.2s
 => [stage-1 2/4] RUN apk add --no-cache ca-certificates &&     adduser -D -u 12345 -g 12345 k6                                    2.0s 
 => [builder 2/6] WORKDIR /go/src/go.k6.io/k6                                                                                      0.3s 
 => [builder 3/6] ADD . .                                                                                                          0.1s 
 => [builder 4/6] RUN apk --no-cache add git                                                                                       0.8s 
 => [builder 5/6] RUN go install go.k6.io/xk6/cmd/xk6@latest                                                                       4.5s 
 => [builder 6/6] RUN xk6 build --with github.com/grafana/xk6-output-influxdb=. --output /tmp/k6                                  45.0s 
 => [stage-1 3/4] COPY --from=builder /tmp/k6 /usr/bin/k6                                                                          0.1s 
 => [stage-1 4/4] WORKDIR /home/k6                                                                                                 0.0s 
 => exporting to image                                                                                                             0.1s 
 => => exporting layers                                                                                                            0.1s 
 => => writing image sha256:3e39efbc4ed8ce7528930e4b8e4a032cc526098ab1ca68c29d97d28e85bab426                                       0.0s
 => => naming to docker.io/library/xk6-image-test  

$ docker image ls
                      
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
xk6-image-test   latest    3e39efbc4ed8   23 seconds ago   43.6MB

$ docker run xk6-image-test version
k6 v0.43.1 ((devel), go1.20.5, linux/arm64)
Extensions:
  github.com/grafana/xk6-output-influxdb (devel), xk6-influxdb [output]

Based on your shared output, are you instead running xk6 build --with github.com/grafana/xk6-output-influxdb? Locally running this also worked in my case.

$ xk6 build --with github.com/grafana/xk6-output-influxdb

2023/06/20 10:25:20 [INFO] Temporary folder: /xk6-output-influxdb/buildenv_2023-06-20-1025.1609116281
2023/06/20 10:25:20 [INFO] Initializing Go module
2023/06/20 10:25:20 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init k6 
go: creating new go.mod: module k6
2023/06/20 10:25:21 [INFO] Pinning versions
2023/06/20 10:25:21 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -require github.com/grafana/xk6-output-influxdb@latest 
2023/06/20 10:25:21 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
go: downloading github.com/grafana/xk6-output-influxdb v0.4.0
2023/06/20 10:25:22 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
2023/06/20 10:25:22 [INFO] Writing main module: /xk6-output-influxdb/buildenv_2023-06-20-1025.1609116281/main.go
2023/06/20 10:25:22 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
2023/06/20 10:25:22 [INFO] Build environment ready
2023/06/20 10:25:22 [INFO] Building k6
2023/06/20 10:25:22 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17 
2023/06/20 10:25:22 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /xk6-output-influxdb/k6 -ldflags=-w -s -trimpath 
2023/06/20 10:25:45 [INFO] Build complete: ./k6
2023/06/20 10:25:45 [INFO] Cleaning up temporary folder: /xk6-output-influxdb/buildenv_2023-06-20-1025.1609116281

xk6 has now produced a new k6 binary which may be different than the command on your system path!

$ ./k6 version
k6 v0.43.1 ((devel), go1.19.3, darwin/amd64)
Extensions:
  github.com/grafana/xk6-output-influxdb v0.4.0, xk6-influxdb [output]

We can better help if we know where it fails for you, building the dockerfile, or creating the k6 binary with the extension. If the latter, I would check the prerequisites. Or better use k6’s guide to build a k6 binary using Docker.

I hope this helps :bowing_woman:

Cheers!