docker

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

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.

Documentation

Overview

Package docker provides a module implementation for manipulating docker resources using Javascript

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Containers

type Containers struct {
	Client *client.Client
}

Containers is a structure with all docker containers functions

func (*Containers) Exec

func (d *Containers) Exec(containerID string, config types.ExecConfig) error

Exec works as Docker exec command

func (*Containers) Inspect

func (d *Containers) Inspect(containerID string) (types.ContainerJSON, error)

Inspect works as Docker inspect command

func (*Containers) List

func (d *Containers) List(options types.ContainerListOptions) ([]types.Container, error)

List works as Docker ps command

func (*Containers) Logs

func (d *Containers) Logs(containerID string, options types.ContainerLogsOptions) (string, error)

Logs works as Docker logs command

func (*Containers) Pause

func (d *Containers) Pause(containerID string) error

Pause works as Docker pause command

func (*Containers) SetupClient

func (d *Containers) SetupClient()

SetupClient for filling in Docker client instance

func (*Containers) Start

func (d *Containers) Start(containerID string) error

Start works as Docker start command

func (*Containers) Stop

func (d *Containers) Stop(containerID string) error

Stop works as Docker stop command

func (*Containers) Unpause

func (d *Containers) Unpause(containerID string) error

Unpause works as Docker unpause command

type Docker

type Docker struct{}

Docker is the main export of k6 docker extension

type Images

type Images struct {
	Client *client.Client
}

Images is a structure with all docker Image functions

func (*Images) Inspect

func (d *Images) Inspect(imageID string) (types.ImageInspect, error)

Inspect works as Docker image inspect

func (*Images) List

func (d *Images) List(options types.ImageListOptions) ([]types.ImageSummary, error)

List works as Docker image ls command

func (*Images) Pull

func (d *Images) Pull(refStr string, options types.ImagePullOptions) (string, error)

Pull works as Docker pull

func (*Images) Remove

func (d *Images) Remove(imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)

Remove works as Docker image rm

func (*Images) SetupClient

func (d *Images) SetupClient()

SetupClient for filling in Docker client instance

type Networks

type Networks struct {
	Client *client.Client
}

Networks is a structure with all docker Network functions

func (*Networks) Create

func (nw *Networks) Create(name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)

Create works as Docker network create

func (*Networks) List

List works as Docker network ls

func (*Networks) Remove

func (nw *Networks) Remove(networkID string) error

Remove works as Docker network remove

func (*Networks) SetupClient

func (nw *Networks) SetupClient()

SetupClient for filling in Docker client instance

type Volumes

type Volumes struct {
	Client *client.Client
}

Volumes is a structure with all docker Volume functions

func (*Volumes) Create

func (v *Volumes) Create(options volumetypes.VolumeCreateBody) (types.Volume, error)

Create works as Docker volume create

func (*Volumes) List

List works as Docker volume ls

func (*Volumes) Remove

func (v *Volumes) Remove(volumeID string, force bool) error

Remove works as Docker volume rm

func (*Volumes) SetupClient

func (v *Volumes) SetupClient()

SetupClient for filling in Docker client instance

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL