Bundle k6 with extensions as fast and easily as possible

xk6bundler

xk6bundler is a CLI tool and GitHub Action makes bundle k6 with extensions as fast and easily as possible.

Features

  • Build for multiple target platforms
  • Create per platform .tar.gz archives for releases
  • Generate Dockerfile for Docker build/push
  • Guess reasonable default values
  • Almost drop-in xk6 replacement
  • Only one GitHub workflow file required to build and publish custom k6 bundle

For a real life example check k6-crocus and it's .github/workflows/xk6bundler.yml file

Table of Contents

Parameters

The CLI tool and GitHub Action has same parameters. The main difference is how to pass the parameters. Another difference is that using CLI tool you may specify with and platform parameters multiple times, while using GitHub action you should specify these parameters only once, but you may use a whitespace separated list of values.

The following table show parameter names, CLI option flags and environment variable names for the default value of a given parameter:

Parameter CLI Environment
name -n, --name=name XK6BUNDLER_NAME
version -v, --version=version XK6BUNDLER_VERSION
with -w, --with=extension XK6BUNDLER_WITH
platform -p, --platform=target XK6BUNDLER_PLATFORM
output -o, --output=path XK6BUNDLER_OUTPUT
archive -a, --archive=path XK6BUNDLER_ARCHIVE
k6_repo --k6-repo=repo XK6BUNDLER_K6_REPO
k6_version --k6-version=version XK6BUNDLER_K6_VERSION

name

Short name of the bundle. Optional, if missing then xk6bunder will try to guess from git remote or from current directory name.

version

Bundle version. Optional, if missing then xk6bundler will try to guess from GITHUB_REF or default to SNAPSHOT.

with

xk6 extension to add in module[@version][=replacement] format. When using CLI, it can be used multiple times to add extensions by specifying the Go module name and optionally its version, similar to go get. Module name is required, but specific version and/or local replacement are optional. Replacement path must be absolute. When using GitHub Action, it can contains whilespace separated list of modules. Optional, if missing then no xk6 extension will be bundled.

platform

Target platform in os/arch format. When using CLI, it can be used multiple times to add target platform. When using GitHub Action, it can contains whilespace separated list of target platforms. Optinal, default value is linux/amd64 windows/amd64 darwin/amd64

output

Go template of output file path. Optional, default value is dist/{{.Name}}_{{.Os}}_{{.Arch}}/k6{{.Ext}}

The following template variables available in template:

Variable Descripion
Os OS name (values defined by GOOS)
Arch hardware architecture (values defined by GOARCH)
Ext .exe on windows empty otherwise
Name bundle name
Version bundle version

You can use slim-sprig template function library as well.

archive

Go template of archive (.tar.gz) file path. Optional, default value is dist/{{.Name}}_{{.Version}}_{{.Os}}_{{.Arch}}.tar.gz

The following template variables available in template:

Variable Descripion
Os OS name (values defined by GOOS)
Arch hardware architecture (values defined by GOARCH)
Ext .exe on windows empty otherwise
Name bundle name
Version bundle version

You can use slim-sprig template function library as well.

k6_repo

Build using a k6 fork repository. The repo can be a remote repository or local directory path.

k6_version

The core k6 version to build. Optional, if missing then latest will be used.

GitHub Action

For using xk6bundler as GitHub Action, you should include a workflow step with uses: szkiba/xk6bundler@v0

- name: Build
  id: build
  uses: szkiba/xk6bundler@v0
  with:
    platform: linux/amd64 windows/amd64
    with: |
      github.com/szkiba/[email protected]
      github.com/szkiba/[email protected]
      github.com/szkiba/[email protected]

Outputs

The xk6bundler GitHub Action outputs the following variables:

name

Short name of the bundle.

version

Bundle version.

dockerfile

Generated Dockerfile path.

dockerdir

Docker context directory path. Can be use as context parameter for Docker build action (assuming build is the id of the xk6bundler step):

- name: Docker build and push
  uses: docker/build-push-action@v2
  with:
    context: ./${{ steps.build.outputs.dockerdir }}

The ./ prefix required, it will tell to Docker action that this is a local path (not an URL).

See samples/sample-dockerhub-workflow.yml for complete example.

GitHub release

The xk6bundler GitHub Action generates result by default in dist directory of the current workspace. You can publish generated archive (.tar.gz) files using any thirdpary release GitHub Action.

Sample workflow file for publishing xk6 bundle on GitHub releases page: samples/sample-workflow.yml. Put this file in to .github/workflows directory.

Docker Hub push

If target platforms include linux/amd64 then xk6bundler will generate Dockerfile next to linux/amd64 platform's output file. You can use it to build Docker image and push it for example to Docker Hub registry (or to any other).

Sample workflow file for publishing xk6 bundle on GitHub releases page and on Docker Hub registry: samples/sample-dockerhub-workflow.yml. Put this file in to .github/workflows directory.

CLI

You can install the pre-compiled binary or use Docker.

Install the pre-compiled binary

Download the pre-compiled binaries from the releases page and copy to the desired location.

Install with Go

If you have Go environment set up, you can build xk6bundler from source by running:

go get github.com/szkiba/xk6bundler/cmd/xk6bundler

Binary would be installed to $GOPATH/bin/xk6bundler.

Running with Docker

You can also use it within a Docker container. To do that, you'll need to execute the following:

docker run szkiba/xk6bundler

Verifying your installation

To verify your installation, use the xk6bundler -V command:

$ xk6bundler -V

xk6bundler/0.1.0 linux/amd64

You should see xk6bundler/VERSION in the output.

Usage

To print usage information, use the xk6bundler --help command.

Owner
Iván Szkiba
I'm a software architect with hands on programming knowledge.
Iván Szkiba
Similar Resources

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

revive Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for developme

Jan 3, 2023

A Golang tool that does static analysis, unit testing, code review and generate code quality report.

A Golang tool that does static analysis, unit testing, code review and generate code quality report.

goreporter A Golang tool that does static analysis, unit testing, code review and generate code quality report. This is a tool that concurrently runs

Jan 8, 2023

[mirror] Performance measurement, storage, and analysis.

Go performance measurement, storage, and analysis tools This subrepository holds the source for various packages and tools related to performance meas

Dec 24, 2022

A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

go-gitlab A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way NOTE Release v0.6.0 (released on 25-08-2017) no

Jan 6, 2023

octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

Jan 9, 2023

Refactoring and code transformation tool for Go.

gopatch is a tool to match and transform Go code. It is meant to aid in refactoring and restyling.

Dec 30, 2022

The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.

nilnil Checks that there is no simultaneous return of nil error and an invalid value. Installation & usage $ go install github.com/Antonboom/nilnil@la

Dec 14, 2022

Act as part of the business code and will report aqua scan report after application installed

Act as part of the business code and will report aqua scan report after application installed

starboard-report This repo aim to enrich the functionality of starboard. Starboard integrates security tools into the Kubernetes environment, so that

Nov 25, 2021
Comments
  • Fatal error while combining xk6-browser and xk6-cache

    Fatal error while combining xk6-browser and xk6-cache

    C:\Users_pseudo_>xk6bundler --with github.com/grafana/xk6-browser --with github.com/szkiba/xk6-cache 2022/06/10 12:48:21 [INFO] Temporary folder: C:\Users\ASLEIL~1\AppData\Local\Temp\buildenv_2022-06-10-1248.918629070 2022/06/10 12:48:21 [INFO] Initializing Go module 2022/06/10 12:48:21 [INFO] exec (timeout=10s): C:\Program Files\Go\bin\go.exe mod init k6 go: creating new go.mod: module k6 2022/06/10 12:48:21 [INFO] Pinning versions 2022/06/10 12:48:21 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe mod edit -require github.com/grafana/xk6-browser@latest 2022/06/10 12:48:21 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe mod tidy -compat=1.17 go: finding module for package github.com/fsnotify/fsnotify go: finding module for package gopkg.in/tomb.v1 go: found gopkg.in/tomb.v1 in gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 go: found github.com/fsnotify/fsnotify in github.com/fsnotify/fsnotify v1.5.4 2022/06/10 12:48:22 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe mod edit -require github.com/szkiba/xk6-cache@latest 2022/06/10 12:48:22 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe mod tidy -compat=1.17 go: finding module for package go.k6.io/k6/stats k6 imports github.com/szkiba/xk6-cache imports go.k6.io/k6/stats: module go.k6.io/k6@latest found (v0.38.3), but does not contain package go.k6.io/k6/stats 2022/06/10 12:48:23 [INFO] Cleaning up temporary folder: C:\Users\pseudo\AppData\Local\Temp\buildenv_2022-06-10-1248.918629070 2022/06/10 12:48:23 [FATAL] exit status 1

    I am getting the following log when trying to combine the two extensions. Any idea how to fix it? Thank you for assistance

Fast division, modulus and divisibility checks in Go for divisors known only at runtime.

fastdiv Fast division, modulus and divisibility checks for divisors known only at runtime via the method of: "Faster Remainder by Direct Computation:

Jan 8, 2023
Fast linters Runner for Go
Fast linters Runner for Go

golangci-lint Fast linters runner for Go golangci-lint is a fast Go linters runner. It runs linters in parallel, uses caching, supports yaml config, h

Jan 8, 2023
A little fast cloc(Count Lines Of Code)

gocloc A little fast cloc(Count Lines Of Code), written in Go. Inspired by tokei. Installation $ go get -u github.com/hhatto/gocloc/cmd/gocloc Usage

Jan 6, 2023
Jenkins tracer is used to record all the Jenkins job environment variables and metrics, and send them to Elasticsearch

Jenkins Tracer Jenkins tracer is used to record all the jenkins job variables like record the build duration, build variables, repository metadata, et

Apr 22, 2021
Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.
Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.

Clean Architecture checker for Golang go-cleanarch was created to keep Clean Architecture rules, like a The Dependency Rule and interaction between mo

Dec 31, 2022
Manage your repository's TODOs, tickets and checklists as config in your codebase.

tickgit ??️ tickgit is a tool to help you manage latent work in a codebase. Use the tickgit command to view pending tasks, progress reports, completio

Dec 30, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Dec 30, 2022
A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

Jan 1, 2023
Tool to populate your code with traceable and secure error codes

Essential part of any project, especially customer facing is proper and secure error handling. When error happens and customer reports it, it would be nice to know the context of the error and where it exactly occured.

Sep 28, 2022