Getting certificate issue on running the xk6 via docker compose with influxdb and grafana

Hello All,

I am trying to run k6 load tests tests using xk6 plugin.
I have following configuration:

./k6 version
k6 v0.46.0 ((devel), go1.23.5, darwin/arm64)
Extensions:
  github.com/ydarias/xk6-nats v0.0.0-20230914104427-9af1a8411f14, k6/x/nats [js]

docker-compose.yaml:

influxdb:
    image: influxdb:2.0-alpine
    networks:
      - k6
      - grafana
      - influxdb
    ports:
      - "8086:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=croco
      - DOCKER_INFLUXDB_INIT_PASSWORD=password1
      - DOCKER_INFLUXDB_INIT_ORG=k6io
      - DOCKER_INFLUXDB_INIT_BUCKET=demo
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=EEKpryGZk8pVDXmIuy484BKUxM5jOEDv7YNoeNZUbsNbpbPbP6kK_qY9Zsyw7zNnlZ7pHG16FYzNaqwLMBUz8g==

  grafana:
    image: grafana/grafana:8.2.6
    networks:
      - grafana
      - influxdb
    ports:
      - "3000:3000"
    environment:
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_BASIC_ENABLED=false
    volumes:
      - ./grafana:/etc/grafana/provisioning/

  k6:
    build: .
    networks:
      - k6
    ports:
      - "6565:6565"
    environment:
      - K6_OUT=xk6-influxdb=http://influxdb:8086
      - K6_INFLUXDB_ORGANIZATION=k6io
      - K6_INFLUXDB_BUCKET=demo
      - K6_INFLUXDB_INSECURE=true
      # NOTE: This is an Admin token, it's not suggested to use this configuration in production.
      # Instead, use a Token with restricted privileges.
      - K6_INFLUXDB_TOKEN=EEKpryGZk8pVDXmIuy484BKUxM5jOEDv7YNoeNZUbsNbpbPbP6kK_qY9Zsyw7zNnlZ7pHG16FYzNaqwLMBUz8g==
    volumes:
      - ./samples:/scripts

networks:
  k6:
  grafana:
  influxdb:

Dockerfile:

FROM golang:1.22-alpine3.20 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.20
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"]

I have referred this code from official github from xk6-output-influxdb

Issue:

[+] Building 1.8s (9/16)                                                                                                                                                              docker:desktop-linux
 => [k6 internal] load build definition from Dockerfile                                                                                                                                               0.0s
 => => transferring dockerfile: 489B                                                                                                                                                                  0.0s
 => WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1)                                                                                                                        0.0s
 => [k6 internal] load metadata for docker.io/library/alpine:3.20                                                                                                                                     0.0s
 => [k6 internal] load metadata for docker.io/library/golang:1.22-alpine3.20                                                                                                                          1.2s
 => [k6 auth] library/golang:pull token for registry-1.docker.io                                                                                                                                      0.0s
 => [k6 internal] load .dockerignore                                                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                                                       0.0s
 => [k6 builder 1/6] FROM docker.io/library/golang:1.22-alpine3.20@sha256:316ed04bea321c6a003f9ff2752d58454d0efa584e07d7173ce6dd9b0d50cd54                                                            0.0s
 => => resolve docker.io/library/golang:1.22-alpine3.20@sha256:316ed04bea321c6a003f9ff2752d58454d0efa584e07d7173ce6dd9b0d50cd54                                                                       0.0s
 => CACHED [k6 stage-1 1/4] FROM docker.io/library/alpine:3.20@sha256:31687a2fdd021f85955bf2d0c2682e9c0949827560e1db546358ea094f740f12                                                                0.0s
 => => resolve docker.io/library/alpine:3.20@sha256:31687a2fdd021f85955bf2d0c2682e9c0949827560e1db546358ea094f740f12                                                                                  0.0s
 => CANCELED [k6 internal] load build context                                                                                                                                                         0.5s
 => => transferring context: 2.16MB                                                                                                                                                                   0.5s
 => ERROR [k6 stage-1 2/4] RUN apk add --no-cache ca-certificates &&     adduser -D -u 12345 -g 12345 k6                                                                                              0.5s
------
 > [k6 stage-1 2/4] RUN apk add --no-cache ca-certificates &&     adduser -D -u 12345 -g 12345 k6:
0.091 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/aarch64/APKINDEX.tar.gz
0.316 207D89BDFFFF0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:
0.317 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/main: Permission denied
0.317 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/aarch64/APKINDEX.tar.gz
0.478 207D89BDFFFF0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:
0.479 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/community: Permission denied
0.479 ERROR: unable to select packages:
0.479   ca-certificates (no such package):
0.479     required by: world[ca-certificates]

failed to solve: process "/bin/sh -c apk add --no-cache ca-certificates &&     adduser -D -u 12345 -g 12345 k6" did not complete successfully: exit code: 1

Solution
I have tried the following solution, but it fails too on different error:

FROM golang:1.22-alpine as *builder*


WORKDIR $*GOPATH*/src/go.k6.io/k6


ADD . .


RUN apk add --no-cache git


RUN go install go.k6.io/xk6/cmd/xk6@latest


RUN xk6 build --with github.com/grafana/xk6-output-influxdb@latest=. --output /tmp/k6


FROM alpine:latest


RUN apk update --no-check-certificate \

&& apk add --no-check-certificate bash curl



COPY --from=*builder* /tmp/k6 /usr/bin/k6


USER root

WORKDIR /home/k6

ENTRYPOINT ["k6"]

ERROR


[+] Building 22.2s (11/15)                                                                                                                                                            docker:desktop-linux
 => [k6 internal] load build definition from Dockerfile                                                                                                                                               0.0s
 => => transferring dockerfile: 864B                                                                                                                                                                  0.0s
 => WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 2)                                                                                                                        0.0s
 => [k6 internal] load metadata for docker.io/library/alpine:latest                                                                                                                                   0.0s
 => [k6 internal] load metadata for docker.io/library/golang:1.22-alpine                                                                                                                              1.1s
 => [k6 internal] load .dockerignore                                                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                                                       0.0s
 => [k6 builder 1/6] FROM docker.io/library/golang:1.22-alpine@sha256:161858498a61ce093c8e2bd704299bfb23e5bff79aef99b6c40bb9c6a43acf0f                                                                0.0s
 => => resolve docker.io/library/golang:1.22-alpine@sha256:161858498a61ce093c8e2bd704299bfb23e5bff79aef99b6c40bb9c6a43acf0f                                                                           0.0s
 => [k6 stage-1 1/4] FROM docker.io/library/alpine:latest@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099                                                                     0.0s
 => => resolve docker.io/library/alpine:latest@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099                                                                                0.0s
 => [k6 internal] load build context                                                                                                                                                                 18.9s
 => => transferring context: 178.43MB                                                                                                                                                                18.8s
 => CACHED [k6 stage-1 2/4] RUN apk update --no-check-certificate     && apk add --no-check-certificate bash curl                                                                                     0.0s
 => CACHED [k6 builder 2/6] WORKDIR /go/src/go.k6.io/k6                                                                                                                                               0.0s
 => [k6 builder 3/6] ADD . .                                                                                                                                                                          1.4s
 => ERROR [k6 builder 4/6] RUN apk add --no-cache git                                                                                                                                                 0.7s
------                                                                                                                                                                                                     
 > [k6 builder 4/6] RUN apk add --no-cache git:                                                                                                                                                            
0.216 fetch https://dl-cdn.alpinelinux.org/alpine/v3.21/main/aarch64/APKINDEX.tar.gz                                                                                                                       
0.475 200D76AAFFFF0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:                                                            
0.479 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.21/main: Permission denied
0.479 fetch https://dl-cdn.alpinelinux.org/alpine/v3.21/community/aarch64/APKINDEX.tar.gz
0.640 200D76AAFFFF0000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:2091:
0.644 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.21/community: Permission denied
0.644 ERROR: unable to select packages:
0.644   git (no such package):
0.644     required by: world[git]
------
failed to solve: process "/bin/sh -c apk add --no-cache git" did not complete successfully: exit code: 1

Could someone please assist me on what am I doing wrong here?
Thanks in advance :slight_smile:

It should be related to an issue with alpine. I’ve opened a pull request for it Bump dockerfile dependencies by codebien · Pull Request #41 · grafana/xk6-output-influxdb · GitHub. I will let you know when this is merged.

1 Like