Code Monkey home page Code Monkey logo

xk6-docker's Introduction

⚠️ Deprecated!!!

This extension was originally created as a proof of concept. At this time, there are no maintainers available to support this extension.

USE AT YOUR OWN RISK!


xk6-docker

A k6 extension for using of Docker CLI in testing. Built for k6 using xk6.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
$ go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
$ xk6 build --with github.com/grafana/xk6-docker@latest

Example

import containers from 'k6/x/docker/containers';

export default function () {
  containers.list().forEach((container) => {
    console.log(container.id.substring(0, 10));
  });
}

Result output:

$ ./k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ../xk6-docker/script.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] 32c2786ccb
INFO[0000] 738b15d70f
INFO[0000] 5813101144
INFO[0000] b1fda43ce2

running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=9.64ms min=9.64ms med=9.64ms max=9.64ms p(90)=9.64ms p(95)=9.64ms
     iterations...........: 1   25.017512/s

Inspect examples folder for more details.

xk6-docker's People

Contributors

javaducky avatar lxkuz avatar mstoykov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xk6-docker's Issues

Maybe we should allow the user to configure this by supplying a config object as well and not strictly enforce config through env vars?

Maybe we should allow the user to configure this by supplying a config object as well and not strictly enforce config through env vars?

I'm thinking that if an object is supplied as the argument to the function, we should treat that as a client config object, if not - default to FromEnv. If we decide to go for this, it could be good if we also cover it with a unit test for each of the paths.

Originally posted by @simskij in #1 (comment)

Private registries

Is it possible to pull/push images from/to private registries?

I understand it uses Moby Golang SDK and there is an ImagePullOptions parameter used to "basic-auth", but I struggled for the last few hours and all I get are unauthorized messages.

Here is a small snippet:

import images from 'k6/x/docker/images';
import encoding from 'k6/encoding';

export default function () {
  const registryAuth = encoding.b64encode(JSON.stringify({
    username: 'myUsername',
    password: 'myPassword'
  }), "url")

  const imageName = 'privateRegistry/myImage'
  const imagePullOptions = {
    RegistryAuth: registryAuth
  }

  const result = images.pull(imageName, imagePullOptions)

 console.log(`Image pulling result: ${result}`)
}

Is anything missing?

Add `docker run` support

This case turned into a more difficult task as Docker API doesn't have "run" from the box.
So we should:

  • Create container with custom command we have from "docker run"
  • Start container
    It may be worth to pull the image if we don't have it as docker run does.
    The solution somehow should look like this:
/ RunContainer works as Docker run command
func (d *Containers) RunContainer(ImageName string, options container.Config) error {
	// _, err := d.cli.ImagePull(d.ctx, ImageName, types.ImagePullOptions{})
	// if err != nil {
	// 	panic(err)
	// }

	resp, err := d.cli.ContainerCreate(d.ctx, &options, nil, nil, nil, "")

	if err != nil {
		return err
	}

	if err := d.StartContainer(resp.ID, types.ContainerStartOptions{}); err != nil {
		return err
	}

	statusCh, errCh := d.cli.ContainerWait(d.ctx, resp.ID, container.WaitConditionNotRunning)
	select {
	case err := <-errCh:
		if err != nil {
			return err
		}
	case <-statusCh:
	}
	return nil
}

Update for Extensions Compliance

The xk6-docker extension has fallen a bit behind the minimum requirements for extensions to be listed in the registry:

  • needs to be updated to at least v0.41

For Official extensions, we should have automated CI with linting enabled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.