Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow options to be passed to locust in docker, update docs #1083

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ if [ -z "${TARGET_URL}" ]; then
fi

LOCUST_MODE="${LOCUST_MODE:=standalone}"
LOCUST_OPTS="-f ${LOCUSTFILE_PATH:-/locustfile.py} -H ${TARGET_URL}"
_LOCUST_OPTS="-f ${LOCUSTFILE_PATH:-/locustfile.py} -H ${TARGET_URL}"

if [ "${LOCUST_MODE}" = "master" ]; then
LOCUST_OPTS="${LOCUST_OPTS} --master"
_LOCUST_OPTS="${_LOCUST_OPTS} --master"
elif [ "${LOCUST_MODE}" = "slave" ]; then
if [ -z "${LOCUST_MASTER_HOST}" ]; then
echo "ERROR: MASTER_HOST is empty. Slave mode requires a master" >&2
exit 1
fi

LOCUST_OPTS="${LOCUST_OPTS} --slave --master-host=${LOCUST_MASTER_HOST} --master-port=${LOCUST_MASTER_PORT:-5557}"
_LOCUST_OPTS="${_LOCUST_OPTS} --slave --master-host=${LOCUST_MASTER_HOST} --master-port=${LOCUST_MASTER_PORT:-5557}"
fi

echo "Starting Locust..."
echo "$ locust ${LOCUST_OPTS}"
echo "Starting Locust in ${LOCUST_MODE} mode..."
echo "$ locust ${LOCUST_OPTS} ${_LOCUST_OPTS}"

locust ${LOCUST_OPTS}
locust ${LOCUST_OPTS} ${_LOCUST_OPTS}
24 changes: 20 additions & 4 deletions docs/running-locust-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
Running Locust with Docker
=================================

To keep things simple we provide a single Docker image that can run standalone, as a master, or as a slave.

To keep things simple we provide a single Docker image that can run standalone, as a master, or as a slave.

Environment Variables
---------------------------------------------
Expand All @@ -26,11 +25,14 @@ The hostname of the master.

The port used to communicate with the master. Defaults to 5557.

- ``LOCUST_OPTS``

Additional options to pass to locust. Defaults to ''.

Add your tests
Running your tests
---------------------------------------------

The easiest way to get your tests running is to build an image with your test file built in. Once you've
The easiest way to get your tests running is to build an image with your test file built in. Once you've
written your locustfile you can bake it into a Docker image with a simple ``Dockerfile``:

```
Expand All @@ -41,3 +43,17 @@ ADD locustfile.py locustfile.py
You'll need to push the built image to a Docker repository such as Dockerhub, AWS ECR, or GCR in order for
distributed infrastructure to be able to pull the image. See your chosen repository's documentation on how
to authenticate with the repository to pull the image.

For debugging locally you can run a container and pass your locustfile in as a volume:

```
docker run -p 8089:8089 --volume $PWD/dir/of/locustfile:/mnt/locust -e LOCUSTFILE_PATH=/mnt/locust/locustfile.py -e TARGET_URL=https://abc.com locustio/locust
```

To run in standalone mode without the web UI, you can use the `LOCUST_OPTS` environment variable to add the required options:

```
docker run --volume $PWD/dir/of/locustfile:/mnt/locust -e LOCUSTFILE_PATH=/mnt/locust/locustfile.py -e TARGET_URL=https://abc.com -e LOCUST_OPTS="--clients=10 --no-web --run-time=600" locustio/locust
```

If you are Kubernetes user, you can use the [Helm chart](https://github.com/helm/charts/tree/master/stable/locust) to scale and run locust.