Not everyone loves the Go programming language as myself...I get that. If you're just looking to be able to use k6 OSS with some available extensions and don't want to mess with setting up a Go(lang) environment, then this gist is for you!
This will provide a couple resources to make it simple to create your own customized version of k6 and execute tests all within Docker.
It should come as no surprise that you will need Docker installed!
The extension ecosystem for k6 requires building a custom executable binary containing the extended functionality you desire. As the k6 engine is written with the Go programming language, you would typically need to have a Go compiler installed in your system to create the new version of k6. Not a Herculean effort, but not something everyone wants to mess with. Docker provides the opportunity to have an ephemeral build environment to do the specialized work so you can just focus on your load tests written in Javascript.
Pull down the attached Dockerfile, script_vars.env, and docker-run.sh files into your project directory. This project directory is expected to contain your *.js
Javascript file(s) either either in the same directory or any child directory.
Once you've gone through the available extensions and decided which features you'd like to include, open the Dockerfile
to begin updating the --with ...
selections. Official Grafana extensions will start with github.com/grafana/
then the extension name, e.g. xk6-sql
. Community extensions will be similar, but will have a different organization name, e.g. github.com/szkiba/xk6-dashboard
for the xk6-dashboard.
The fiddly part will be modifying the
Dockerfile
---I'm sorry, there's really no way around it, but it should be straightforward. We'll be changing, or adding more lines like the--with ...
. You'll see that the section has been called out.Even better, you can easily create this command using the bundle builder!
Congratulations! You're ready build. From same directory containing your Dockerfile
, open the Terminal and run the following Docker command:
docker build -t k6-extended:latest .
This may take a couple (or few) minutes initially, but this will download the Go environment within a Docker image, then install the xk6
utility and your desired extensions, compiles the whole thing, then builds a Docker image containing your custom k6 binary.
Now you can run scripts from your local project using your extended version of k6 via Docker. The docker-run.sh script makes this easy-peasy if you're on a Mac or Linux system. If you're on Windows, I'm afraid I don't have a docker-run.bat
version for you at this time.
Just run ./docker-run.sh <RELATIVE PATH TO YOUR SCRIPT>
.