/bin/sh: k6: command not found + Gitlab

I am using a AWS Lambda and NodeJS to do performance testing of some REST APS’s using K6. The lambda handler is triggered via an Event. so, I am invoking the K6 script from the handler.

Now, it is running fine from the local. However, when I try to run it via the Gitlab pipeline, it says “/bin/sh: k6: command not found”

Could someone please help me on this?

Welcome to the forums! My first guess is that the VM running the pipeline doesn’t have the k6 image installed.

This blogpost has an example of the k6 Docker image with a k6 pipeline.

If k6 is installed, maybe there’s a problem with the $PATH. Let me know if that helps!

1 Like

Hi @Matt thanks for responding. The Docker file has no issues. Since i am using NodeJS “package.json”, hence K6 is being installed as a part of that in the pipeline (can confirm via logs).

Oh, I don’t know anything about this, sorry. :no_mouth:

But, I’m sure that someone who has more experience with containers or nodeJS will be able to figure it out. At least we’ve eliminated the easiest solution!

1 Like

Hi @suyashnatural

Could you share the pipeline definition (.gitlab-ci.yml) and the execution logs? If you can send a bit more instructions to reproduce what you are doing, we’ll might be able to help. If the handler runs in a container/VM that has k6 installed, maybe it’s the binary missing from the PATH, as Matt mentioned. However, it’s probably best to try and reproduce your example to see what is going on, and more information will help.

You also mention it works locally, do you mean that the whole pipeline works locally (with something like GitHub - firecow/gitlab-ci-local: Tired of pushing to test your .gitlab-ci.yml?) or is it the k6 script that works locally?

Cheers!

1 Like

Hi @eyeveebe -

I am using K6 in a Lambda written in NodeJS. So, the k6 is added as a dependency in the package.json file as below:

  "dependencies": {
    "k6": "^0.0.0",
    "webpack": "^5.75.0"
  },

Now, when I did “npm install”, everything is installed, please see below:

npm show k6

k6@0.0.0 | AGPL-3.0 | deps: none | versions: 1
Dummy package for autocompleting k6 scripts.
https://github.com/loadimpact/k6#readme

dist
.tarball: https://registry.npmjs.org/k6/-/k6-0.0.0.tgz
.shasum: 8c923200be0a68c578e8f5a32be96b1d8065cc3b
.integrity: sha512-GAQSWayS2+LjbH5bkRi+pMPYyP1JSp7o+4j58ANZ762N/RH/SdlAT3CHHztnn8s/xgg8kYNM24Gd2IPo9b5W+g==

maintainers:
- liclac <emily@witch.works>

dist-tags:
latest: 0.0.0  

published over a year ago by liclac <emily@witch.works>

Now, when I build and run this project, it complains below:

/bin/sh: k6: command not found
console.log src/index.js:29
Finished With Code 127

Hi @eyeveebe -

K6 is installed as a dependency in NodeJS project as below:

"dependencies": {
    "webpack": "^5.75.0",
    "k6": "^0.0.0"
  },

So, when I do npm install, its get installed as below:

npm list
├── @aws-lambda-powertools/logger@0.10.0
├── @babel/core@7.20.5
├── @babel/preset-env@7.20.2
├── aws-sdk@2.1280.0
├── babel-jest@24.9.0
├── babel-loader@8.3.0
├── babel-plugin-transform-es2015-modules-commonjs@6.26.2
├── cross-env@6.0.3
├── eslint-config-prettier@6.15.0
├── eslint-plugin-jest@22.21.0
├── eslint@6.8.0
├── jest-junit@10.0.0
├── jest@24.9.0
├── k6@0.0.0
├── prettier@1.19.1
├── webpack-cli@5.0.1
└── webpack@5.75.0

Now when I do:
k6 run ./src/specs/test.js

it says

zsh: command not found: k6

Hmmm. I don’t want to make any assumptions about your use case, but have you tried just installing k6 as a standard binary? That might be an easier approach. You could still use the docker version in your GitLab pipeline.

Unless I’m really incorrect, k6 can’t be a dependency for a node project. k6 scripts run in the k6 binary, which is written in Go. So they can’t run in a node environment. I’d thought that your node pipeline was maybe calling k6 processes, but now I think it’s maybe trying to use k6 directly in node. If I’m off here, please let me know what incorrect assumptions I’ve made!

I’m not sure what that npm package is. It looks like it’s a “dummy package for autocomplete”.

@mat This is the package: https://www.npmjs.com/package/k6

I see, thanks. I say, start from the ground up, with the instructions in: Installation

Your system will need k6’ special binary to run k6 scripts. The scripts run on a totally different JavaScript engine.

1 Like

I see what you mean, but how does it work within the Pipeline? Since I can’t use dockerfile to install K6 from the image, I need to install “k6” as package.json only.

Also, how can I install k6 as a dev dependency of a Node.js project ??

I’d just model your pipeline off of this configuration:

loadtest-local:
  image:
    name: loadimpact/k6:latest
    entrypoint: ['']
  stage: loadtest-local
  script:
    - echo "executing local k6 in k6 container..."
    - k6 run ./loadtests/performance-test.js

As you’ll see, the pipeline itself calls k6 run. I guess you could store your scripts in the repo of the pipeline, and put all the configuration for your tests in the scripts, or through environment variables.

I need to install “k6” as package.json only.
Also, how can I install k6 as a dev dependency of a Node.js project ??

I don’t think that would work at all. k6 is really a Go application, you need to have the k6 binary.

Oh, now I found a comment about this from one of the core maintainers

k6 currently cannot be installed from npm, it’s not one of our supported installation methods, even unofficially.

That NPM package is just empty and hasn’t been touched for 6 years. Sorry if it misled you.
.

Thanks @Matt - In that case, I would need to drop k6 and need to pick up another load test tool. :frowning:

But, I still think that you can install k6 in your container with your node application.

Are you trying to do something like this?

And, can you post the full (sanitized) pipeline? My guess is that the VM that runs node could also run k6. The only thing you couldn’t do is run k6 scripts in Node, since they use different JS engines.