GithubHelp home page GithubHelp logo

docker-locust's Introduction

pulls stars

I wanted the image to:

  • use Python 3.x
  • use the latest version of Locust
  • be as small as possible
  • be simple to use
  • take Locust scripts by means of mounting a volume

Most of the images found on docker hub was old (1-2 yo) so I decided to give it a try.

This one is based on python image for alpine, installs locustio package and required dependencies. It weighs about 130MB.

Repository structure and images tagging

The git project is organized so it can maintain many versions of the image. Tagging "system" was chosen to easily distinguish between the versions.

Repository structure

Folder structure looks like this:

   .
   |-- locust version a
   |   |--- python version x
   |   |    |--  OS version 1
   |   |    `--  OS version 2
   |   `--- python version y
   |        |---  OS version 1
   |        `---  OS version 2
   |-- locust version b
   ...

Where:

  • locust version is a specific version of locust (i.e. 0.10.0)
  • python version is a specific version of python (i.e. 3.6)
  • OS version 1 is a specific version of the operating system (i.e. alpine3.9)

Tagging structure

The tagging reflects the directory structure and contains information about all the components:

  • locust version
  • python version
  • OS version

For example, for locust 0.10.0 that runs on Python 3.6 on Alpine 3.9 the dockerfile is placed in:

   \
   |--- 0.10.0
   | `-- python3.6
   |   `-- alpine3.9

The tag for this image will be: grubykarol/locust:0.10.0-python3.6-alpine3.9.

Usage

published images on docker hub: https://hub.docker.com/r/grubykarol/locust

The image does not include locust scripts during a build. It assumes, the scripts will be supplied on runtime by mounting a volume (to /locust path).

This gives the ability to use the exact same image for different deployments. There is no need to build your image that would inherit from this one and only include test scripts (although it's also possible).

Pulling the image

Pull the latest stable version:

docker pull grubykarol/locust

Or choose locust, python and OS (Operating System) version you want and pull and the image that is tagged accordingly (see: Tagging structure):

docker pull grubykarol/locust:1.2.3-python3.9-alpine3.12

Running the image

The image uses the following environment variables to configure its behavior:

Variable Description Default Example
LOCUST_FILE Sets the --locustfile option. locustfile.py
ATTACKED_HOST The URL to test. Required. - http://example.com
LOCUST_MODE Set the mode to run in. Can be standalone, master or worker. standalone master
LOCUST_MASTER Locust master IP or hostname. Required for worker mode. - 127.0.0.1
LOCUST_MASTER_BIND_PORT Locust master port for communication with workers. Used in distributed mode.
For master: which port master should bind to.
For worker: port to connect on master.
5557 6666
LOCUST_OPTS Additional locust CLI options. - "-c 10 -r 10"

Standalone

Basic run, with folder (path in $MY_SCRIPTS) holding locustfile.py:

docker run --rm --name standalone --hostname standalone -e ATTACKED_HOST=http://standalone:8089 -p 8089:8089 -d -v $MY_SCRIPTS:/locust grubykarol/locust

or, with additional runtime options (in this example, for running without the UI):

docker run --rm --name standalone --hostname standalone -e ATTACKED_HOST=http://example.com -e "LOCUST_OPTS=--no-web" -d -v $MY_SCRIPTS:/locust grubykarol/locust

Master-worker

Run master:

docker run --name master --hostname master \
 -p 8089:8089 -p 5557:5557 -p 5558:5558 \
 -v $MY_SCRIPTS:/locust \
 -e ATTACKED_HOST=http://master:8089 \
 -e LOCUST_MODE=master \
 --rm -d grubykarol/locust

and some workers:

docker run --name worker0 \
 --link master --env NO_PROXY=master \
 -v $MY_SCRIPTS:/locust \
 -e ATTACKED_HOST=http://master:8089 \
 -e LOCUST_MODE=worker \
 -e LOCUST_MASTER=master \
 --rm -d grubykarol/locust

docker run --name worker1 \
 --link master --env NO_PROXY=master \
 -v $MY_SCRIPTS:/locust \
 -e ATTACKED_HOST=http://master:8089 \
 -e LOCUST_MODE=worker \
 -e LOCUST_MASTER=master \
 --rm -d grubykarol/locust

For the real brave, Windows PowerShell version:

Basic run:

docker run --rm --name standalone `
 -e ATTACKED_HOST=http://localhost:8089 `
 -v c:\locust-scripts:/locust `
 -p 8089:8089 -d `
 grubykarol/locust

Run master:

docker run --name master --hostname master `
 -p 8089:8089 -p 5557:5557 -p 5558:5558 `
 -v c:\locust-scripts:/locust `
 -e ATTACKED_HOST='http://master:8089' `
 -e LOCUST_MODE=master `
 --rm -d grubykarol/locust

Run worker:

docker run --name worker0 `
 --link master --env NO_PROXY=master `
 -v c:\locust-scripts:/locust `
 -e ATTACKED_HOST=http://master:8089 `
 -e LOCUST_MODE=worker `
 -e LOCUST_MASTER=master `
 --rm -d grubykarol/locust

Examples

Other simple examples are collected in examples directory. They include some docker-compose files to run locust standalone or distributed. See the folder for details.

Building the image

Choose Locust, Python and OS (Operating System) version you want by going into desired directory (see: Repository structure)

docker build -t grubykarol/locust:1.2.3-python3.9-alpine3.12 .

or, if behind a proxy (and the proxies are defined in HTTP(S)_PROXY variables:

docker build --build-arg HTTP_PROXY=$http_proxy --build-arg HTTPS_PROXY=$https_proxy -t grubykarol/locust:1.2.3-python3.9-alpine3.12 .

There is also a simple and messy bash script -- build-all.sh -- for development purposes. It's able to build all the images or images for selected locust version.

docker-locust's People

Contributors

emilorol avatar gustavobgama avatar karol-brejna-i avatar lkwg82 avatar metabsd avatar youngkih avatar

Stargazers

 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

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-locust's Issues

Problem with running 0.10.x version of the images in distributed mode

When running in distributed mode, you'll get the following error:

master        | [2019-04-17 18:18:36,124] master/INFO/stdout: 1000 records read
master        | [2019-04-17 18:18:36,124] master/INFO/stdout:
master        | [2019-04-17 18:18:36,125] master/INFO/root: Waiting for slaves to be ready, 0 of 1 connected
master        | [2019-04-17 18:18:36,200] master/INFO/locust.runners: Client b'81269be90ff9_24c41e4b061f4e37acde0753d38cca38' reported as ready. Currently 1 clients ready to swarm.
master        | [2019-04-17 18:18:37,126] master/INFO/locust.runners: Sending hatch jobs to 1 ready clients
master        | [2019-04-17 18:18:37,127] master/INFO/stdout: on_master_start_hatching
master        | [2019-04-17 18:18:37,127] master/INFO/stdout:
master        | [2019-04-17 18:18:37,127] master/ERROR/stderr: Traceback (most recent call last):
master        | [2019-04-17 18:18:37,127] master/ERROR/stderr: File "/usr/local/bin/locust", line 10, in <module>
master        | [2019-04-17 18:18:37,128] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,128] master/ERROR/stderr: sys.exit(main())
master        | [2019-04-17 18:18:37,128] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,128] master/ERROR/stderr: File "/usr/local/lib/python3.6/site-packages/locust/main.py", line 505, in main
master        | [2019-04-17 18:18:37,129] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,129] master/ERROR/stderr: runners.locust_runner.start_hatching(options.num_clients, options.hatch_rate)
master        | [2019-04-17 18:18:37,129] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,129] master/ERROR/stderr: File "/usr/local/lib/python3.6/site-packages/locust/runners.py", line 310, in start_hatching
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr: self.server.send_to_client(Message("hatch", data, client.id))
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr: File "/usr/local/lib/python3.6/site-packages/locust/rpc/zmqrpc.py", line 15, in send_to_client
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr: self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr:
master        | [2019-04-17 18:18:37,130] master/ERROR/stderr: AttributeError
master        | [2019-04-17 18:18:37,131] master/ERROR/stderr: :
master        | [2019-04-17 18:18:37,131] master/ERROR/stderr: 'bytes' object has no attribute 'encode'
master        | [2019-04-17 18:18:37,131] master/ERROR/stderr:
master exited with code 1

Images for version 0.9 and 0.11 work OK.

To reproduce

Use for example "grubykarol/locust:0.10.0-python3.6-alpine3.9" image to start master and slave (can use example from the repo: https://github.com/karol-brejna-i/docker-locust/blob/master/examples/docker-compose-distributed-headless.yml)

Support Locust v1.0.x

Locust seems to have released new version with v1.0.x . It would be great to have this supported here. Example would be like

FROM python:3.8.1-alpine3.11

COPY docker-entrypoint.sh /

RUN    apk --no-cache add --virtual=.build-dep build-base git \
    && apk --no-cache add zeromq-dev libffi-dev \
    && python3 -m pip install --no-cache-dir git+https://github.com/locustio/[email protected]#egg=locustio  \
    && apk del .build-dep \
    && chmod +x /docker-entrypoint.sh \
    && mkdir /locust
WORKDIR /locust
EXPOSE 8089 5557 5558

ENTRYPOINT ["/docker-entrypoint.sh"]

Weird issue in OpenShift

When I update the image and the env variables I get the following error:

usage: locust [-h] [-H HOST] [--web-host WEB_HOST] [-P PORT] [-f LOCUSTFILE]
              [--csv CSVFILEBASE] [--csv-full-history] [--master] [--slave]
              [--master-host MASTER_HOST] [--master-port MASTER_PORT]
              [--master-bind-host MASTER_BIND_HOST]
              [--master-bind-port MASTER_BIND_PORT]
              [--heartbeat-liveness HEARTBEAT_LIVENESS]
              [--heartbeat-interval HEARTBEAT_INTERVAL]
              [--expect-slaves EXPECT_SLAVES] [--no-web] [-c NUM_CLIENTS]
              [-r HATCH_RATE] [-t RUN_TIME] [--skip-log-setup] [--step-load]
              [--step-clients STEP_CLIENTS] [--step-time STEP_TIME]
              [--loglevel LOGLEVEL] [--logfile LOGFILE] [--print-stats]
              [--only-summary] [--no-reset-stats] [--reset-stats] [-l]
              [--show-task-ratio] [--show-task-ratio-json] [-V]
              [--exit-code-on-error EXIT_CODE_ON_ERROR] [-s STOP_TIMEOUT]
              [LocustClass [LocustClass ...]]
locust: error: argument -P/--port/--web-port: invalid int value: 'tcp://0.0.0.0:5557'

I was able to debug the container and manually run the locust command adding -P=5557 argument.

Any ideas?

Note: 0.0.0.0 is masking the real IP for obvious reasons.

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.