elastic / xk6-output-elasticsearch

Apache License 2.0
20 stars 10 forks source link

Unable to build a docker image using Dockerfile #28

Closed haileypark-kr closed 8 months ago

haileypark-kr commented 8 months ago

I am trying to build a docker image using Dockerfile you provided.

But I got an error like below...

[+] Building 3.3s (14/16)                                                                                                                                                                                                docker:desktop-linux
 => [internal] load build definition from xk6-es-Dockerfile                                                                                                                                                                              0.0s
 => => transferring dockerfile: 488B                                                                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/golang:1.20-alpine                                                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/alpine:3.17                                                                                                                                                                           2.5s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                                                                                                                            0.0s
 => [stage-1 1/4] FROM docker.io/library/alpine:3.17@sha256:53cf9478b76f4c8fae126acbdfb79bed6e69e628faff572ebe4a029d3d247d98                                                                                                             0.0s
 => [builder 1/6] FROM docker.io/library/golang:1.20-alpine                                                                                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                                                        0.0s
 => => transferring context: 679B                                                                                                                                                                                                        0.0s
 => CACHED [stage-1 2/4] RUN apk add --no-cache ca-certificates &&     adduser -D -u 12345 -g 12345 k6                                                                                                                                   0.0s
 => CACHED [builder 2/6] WORKDIR /go/src/go.k6.io/k6                                                                                                                                                                                     0.0s
 => CACHED [builder 3/6] ADD . .                                                                                                                                                                                                         0.0s
 => CACHED [builder 4/6] RUN apk --no-cache add git                                                                                                                                                                                      0.0s
 => CACHED [builder 5/6] RUN CGO_ENABLED=0 go install go.k6.io/xk6/cmd/xk6@latest                                                                                                                                                        0.0s
 => ERROR [builder 6/6] RUN CGO_ENABLED=0 xk6 build --with github.com/elastic/xk6-output-elasticsearch=. --output /tmp/k6                                                                                                                0.7s
------
 > [builder 6/6] RUN CGO_ENABLED=0 xk6 build --with github.com/elastic/xk6-output-elasticsearch=. --output /tmp/k6:
0.236 2024/03/20 09:47:56 [INFO] Temporary folder: /tmp/buildenv_2024-03-20-0947.3224696936
0.236 2024/03/20 09:47:56 [INFO] Initializing Go module
0.236 2024/03/20 09:47:56 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init k6
0.240 go: creating new go.mod: module k6
0.242 2024/03/20 09:47:56 [INFO] Replace github.com/elastic/xk6-output-elasticsearch => /go/src/go.k6.io/k6
0.242 2024/03/20 09:47:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -replace github.com/elastic/xk6-output-elasticsearch=/go/src/go.k6.io/k6
0.247 2024/03/20 09:47:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17
0.253 go: warning: "all" matched no packages
0.254 2024/03/20 09:47:56 [INFO] Pinning versions
0.255 2024/03/20 09:47:56 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy -compat=1.17
0.264 go: finding module for package github.com/elastic/xk6-output-elasticsearch
0.684 k6 imports
0.684   github.com/elastic/xk6-output-elasticsearch: module github.com/elastic/xk6-output-elasticsearch@latest found (v0.3.0, replaced by /go/src/go.k6.io/k6), but does not contain package github.com/elastic/xk6-output-elasticsearch
0.686 2024/03/20 09:47:57 [INFO] Cleaning up temporary folder: /tmp/buildenv_2024-03-20-0947.3224696936
0.687 2024/03/20 09:47:57 [FATAL] exit status 1
------
xk6-es-Dockerfile:6
--------------------
   4 |     RUN apk --no-cache add git
   5 |     RUN CGO_ENABLED=0 go install go.k6.io/xk6/cmd/xk6@latest
   6 | >>> RUN CGO_ENABLED=0 xk6 build --with github.com/elastic/xk6-output-elasticsearch=. --output /tmp/k6
   7 |
   8 |     FROM alpine:3.17
--------------------
ERROR: failed to solve: process "/bin/sh -c CGO_ENABLED=0 xk6 build --with github.com/elastic/xk6-output-elasticsearch=. --output /tmp/k6" did not complete successfully: exit code: 1

I am using docker v4.24.2. Let me know if I have to give you any further information about my environments.

danielmitterdorfer commented 8 months ago

Thanks for the reproduction steps. Upon first glance this looks related to https://github.com/elastic/xk6-output-elasticsearch/issues/22 although here you do provide a build context (I suspect that in the other issue this was not the case but did not receive any feedback).

As a first step, can you please try to build the image as follows and check if this succeeds?

git clone git@github.com:elastic/xk6-output-elasticsearch.git
cd xk6-output-elasticsearch
docker build -f ./Dockerfile .

If that works for you, can you please also share the contents of xk6-es-Dockerfile? Is this a custom file that you've created or is this a copy of our Dockerfile? Note that our Dockerfile requires that is placed at the root of the project directory:

https://github.com/elastic/xk6-output-elasticsearch/blob/b1fd152cc079e14cf49579b11837ccf6f6854bbe/Dockerfile#L3

haileypark-kr commented 8 months ago

Thank you for your reply.

The xk6-es-Dockerfile file was exactly same as your dockerfile, but I didn't build inside the repository. I missed the ADD statement in the Dockerfile. I tried cloning this repository and building inside it, and I succeded :) Thank you a lot.

I have another question.. Do you support Elasticsearch 7.x versions? When I try to connect xk6-output-elasticsearch with elasticseach 7.10.2 version, I got an error like time="2024-03-21T08:23:04Z" level=error msg="could not create the 'output-elasticsearch' output: the client noticed that the server is not Elasticsearch and we do not support this unknown product". I used docker run --rm --network elastic -e K6_ELASTICSEARCH_URL=http://es:9200 -i xk6-es run -o output-elasticsearch --tag testid=$(date "+%Y%m%d-%H%M%S") - <k6-scripts/script.js to run the test.

danielmitterdorfer commented 8 months ago

I have another question.. Do you support Elasticsearch 7.x versions?

No, at the moment we depend on the Elasticsearch 8.x client:

https://github.com/elastic/xk6-output-elasticsearch/blob/b1fd152cc079e14cf49579b11837ccf6f6854bbe/go.mod#L6

I can look into what options we have to support both versions. But as this is a new ask, can you please raise a new issue for that?