Home > Software design >  How to run curl commands with k6 docker image in gitlab yml
How to run curl commands with k6 docker image in gitlab yml

Time:03-10

I want to run a curl request as a pre-request script for my K6 load tests. Here is my YML file:

  - loadtest-local

image:
  name: ubuntu:latest

loadtest-local:
  image:
    name: loadimpact/k6:latest
    entrypoint: ['']
  stage: loadtest-local
  before_script:
    - apk add --no-cache curl jq
  script:
    - echo "executing local k6 in k6 container..."
    - >
      curl google.com
    - k6 run ./tests/script.js

When I run this in my pipeline I get the following error:

$ apk add --no-cache curl jq
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

How can I add a curl request as a pre-request script in my YML?

CodePudding user response:

The k6 Docker image runs as an unprivileged user, which is why you're not able to install curl and jq.

I would suggest you to build your own custom image using loadimpact/k6 as base, or to build an image from another base that copies the k6 binary with COPY --from=loadimpact/k6:latest /usr/bin/k6 /usr/bin/k6, install anything you need in it and run that image in CI instead.

  • Related