From 10cd0044e3625aec8e2ff7f590bb3f2e67a9d206 Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Tue, 24 Jul 2018 22:06:40 -0400 Subject: [PATCH 01/10] Dockerfile and startup script --- Dockerfile | 10 ++++++++++ docker_start.sh | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Dockerfile create mode 100644 docker_start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..a8dd95723e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.6 + +RUN pip install locustio pyzmq + +ADD docker_start.sh /usr/bin/docker_start +RUN chmod 755 /usr/bin/docker_start + +EXPOSE 8089 5557 5558 + +CMD ["docker_start"] \ No newline at end of file diff --git a/docker_start.sh b/docker_start.sh new file mode 100644 index 0000000000..fba7bbe6ed --- /dev/null +++ b/docker_start.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +if [ -z "${TARGET_URL}" ]; then + echo "ERROR: TARGET_URL not configured" >&2 + exit 1 +fi + +LOCUST_MODE="${LOCUST_MODE:=standalone}" +LOCUST_OPTS="-f ${LOCUSTFILE_PATH:-/locustfile.py} -H ${TARGET_URL}" + +if [ "${LOCUST_MODE}" = "master" ]; then + 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}" +fi + +echo "Starting Locust..." +echo "$ locust ${LOCUST_OPTS}" + +locust ${LOCUST_OPTS} \ No newline at end of file From e4f1be570984437f0cc2fd9a5e95b91d0797537a Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Tue, 24 Jul 2018 22:07:04 -0400 Subject: [PATCH 02/10] Docker Compose example --- examples/docker-compose/docker-compose.yml | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/docker-compose/docker-compose.yml diff --git a/examples/docker-compose/docker-compose.yml b/examples/docker-compose/docker-compose.yml new file mode 100644 index 0000000000..e3de7b5b3c --- /dev/null +++ b/examples/docker-compose/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3.4" + +x-common: &common + image: locustio/locust + environment: &common-env + TARGET_URL: http://locust-master:8089 + LOCUSTFILE_PATH: /tests/basic.py + volumes: + - ../:/tests + +services: + locust-master: + <<: *common + ports: + - 8089:8089 + environment: + <<: *common-env + LOCUST_MODE: master + + locust-slave: + <<: *common + environment: + <<: *common-env + LOCUST_MODE: slave + LOCUST_MASTER_HOST: locust-master \ No newline at end of file From ae4286c7c18b5dfada71619611930db496465f0f Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Tue, 24 Jul 2018 22:07:16 -0400 Subject: [PATCH 03/10] First pass at Docker docs --- docs/running-locust-distributed.rst | 6 +++ docs/running-locust-docker.rst | 57 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 docs/running-locust-docker.rst diff --git a/docs/running-locust-distributed.rst b/docs/running-locust-distributed.rst index 4f2633e80d..d0cb704871 100644 --- a/docs/running-locust-distributed.rst +++ b/docs/running-locust-distributed.rst @@ -81,6 +81,12 @@ Used when starting the master node with ``--no-web``. The master node will then nodes has connected before the test is started. +Running distributed with Docker +============================================= + +See :ref:`running-locust-docker` + + Running Locust distributed without the web UI ============================================= diff --git a/docs/running-locust-docker.rst b/docs/running-locust-docker.rst new file mode 100644 index 0000000000..996f50c1fc --- /dev/null +++ b/docs/running-locust-docker.rst @@ -0,0 +1,57 @@ +.. _running-locust-docker: + +================================= +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. + + +Environment Variables +--------------------------------------------- + +- ``LOCUST_MODE`` + +One of 'standalone', 'master', or 'slave'. Defaults to 'standalone'. + +- ``LOCUSTFILE_PATH`` + +The path inside the container to the locustfile. Defaults to '/locustfile.py` + +- ``LOCUST_MASTER_HOST`` + +The hostname of the master. + +- ``LOCUST_MASTER_PORT`` + +The port used to communicate with the master. Defaults to 5557. + + +Add your tests +--------------------------------------------- + +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``: + +``` +FROM locustio/locust +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. + + +Running in Docker Compose +--------------------------------------------- + +While developing your locustfile it can be helpful to run it locally. Here's an example of a basic Docker Compose file showing Locust running distributed: + +.. literalinclude:: ../examples/docker-compose/docker-compose.yml + +When running in Docker Compose you'll probably want the locust containers to be placed in the same Docker network as your application. If you already have a ``docker-compose.yml`` for your application you could copy the example compose file into the same directory named ``docker-compose.locust.yml`` and then start your stack with: + +``docker-compose -f docker-compose.yml -f docker-compose.locust.yml up`` + +This will ensure that your application and the locust containers are placed in the same network and can easily communicate. \ No newline at end of file From 7bb9f2198cc2a5288c3a4679a4fba8ba5a0b9c23 Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Wed, 25 Jul 2018 07:22:03 -0400 Subject: [PATCH 04/10] Attempt to add docker build to travis matrix --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7cd6ae159d..1436d099ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ matrix: env: TOXENV=py34 - python: 2.7 env: TOXENV=py27 + - stage: Verify Docker image builds + script: docker build -t locustio/locust . addons: apt: packages: From cda503a4ce02974248d7696854a452965c96a9eb Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 14 Aug 2018 18:08:34 -0400 Subject: [PATCH 05/10] Remove Docker Compose docs I've found it easier to run locust locally in standalone mode while developing the locustfile. The example docker-compose file still exists though. --- docs/running-locust-docker.rst | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docs/running-locust-docker.rst b/docs/running-locust-docker.rst index 996f50c1fc..7841f1fddc 100644 --- a/docs/running-locust-docker.rst +++ b/docs/running-locust-docker.rst @@ -41,17 +41,3 @@ 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. - - -Running in Docker Compose ---------------------------------------------- - -While developing your locustfile it can be helpful to run it locally. Here's an example of a basic Docker Compose file showing Locust running distributed: - -.. literalinclude:: ../examples/docker-compose/docker-compose.yml - -When running in Docker Compose you'll probably want the locust containers to be placed in the same Docker network as your application. If you already have a ``docker-compose.yml`` for your application you could copy the example compose file into the same directory named ``docker-compose.locust.yml`` and then start your stack with: - -``docker-compose -f docker-compose.yml -f docker-compose.locust.yml up`` - -This will ensure that your application and the locust containers are placed in the same network and can easily communicate. \ No newline at end of file From 74f4bc491fb58209a1d98f850d497f131b4a6f54 Mon Sep 17 00:00:00 2001 From: Sam Payeur Date: Wed, 12 Sep 2018 15:16:10 -0600 Subject: [PATCH 06/10] Update dockerfile to slim down created image and tweak behaviors. Change base image from py3.6 to py3.7-alpine. This shrinks the image size by about 600MB so that's nice. Addition of the apk call is required for pip to actually build and of the dependencies for Locust. Removal of docker_start portion is based on comments by mbeacom. Technically this makes the base image unusable without a consumer adding their own Dockerfile with a COPY/ADD call or another ENTRYPOINT. --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a8dd95723e..0746f0c237 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ -FROM python:3.6 +FROM python:3.7-alpine +RUN apk --no-cache add g++ RUN pip install locustio pyzmq -ADD docker_start.sh /usr/bin/docker_start -RUN chmod 755 /usr/bin/docker_start - EXPOSE 8089 5557 5558 -CMD ["docker_start"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/locust"] From 76c345875d013f98ac8fe57f9dde5ca34d027923 Mon Sep 17 00:00:00 2001 From: Sam Payeur Date: Thu, 13 Sep 2018 10:08:27 -0600 Subject: [PATCH 07/10] Add py37 environment to tox and travis.yml --- .travis.yml | 2 ++ tox.ini | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1436d099ae..5408494fa8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: python cache: pip matrix: include: + - python: 3.7 + end: TOXENV=py37 - python: 3.6 env: TOXENV=py36 - python: 3.5 diff --git a/tox.ini b/tox.ini index dfa2693c85..9d472cabbe 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34, py35, py36 +envlist = py27, py34, py35, py36, py37 [testenv] deps = From c7a722fca92d629fcf5d66f0749c18155a0034b2 Mon Sep 17 00:00:00 2001 From: Sam Payeur Date: Thu, 13 Sep 2018 10:23:57 -0600 Subject: [PATCH 08/10] Fix typo in travis.yml. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5408494fa8..32d91eab75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ cache: pip matrix: include: - python: 3.7 - end: TOXENV=py37 + env: TOXENV=py37 - python: 3.6 env: TOXENV=py36 - python: 3.5 From 8f79552555e76767a9f852866c343f3ddd0df988 Mon Sep 17 00:00:00 2001 From: Sam Payeur Date: Thu, 13 Sep 2018 10:31:00 -0600 Subject: [PATCH 09/10] Roll back addition of py37 to py36 due to travis distribution --- .travis.yml | 2 -- Dockerfile | 2 +- tox.ini | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 32d91eab75..1436d099ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ language: python cache: pip matrix: include: - - python: 3.7 - env: TOXENV=py37 - python: 3.6 env: TOXENV=py36 - python: 3.5 diff --git a/Dockerfile b/Dockerfile index 0746f0c237..e89d4fbecd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.6-alpine RUN apk --no-cache add g++ RUN pip install locustio pyzmq diff --git a/tox.ini b/tox.ini index 9d472cabbe..dfa2693c85 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34, py35, py36, py37 +envlist = py27, py34, py35, py36 [testenv] deps = From 974f861c06a611286e2c8851882f8ff6815d5b32 Mon Sep 17 00:00:00 2001 From: Sam Payeur Date: Mon, 17 Sep 2018 12:59:57 -0600 Subject: [PATCH 10/10] Specify explicit version for alpine base image. Group build deps. --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e89d4fbecd..b99c8f14fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM python:3.6-alpine +FROM python:3.6.6-alpine3.8 -RUN apk --no-cache add g++ -RUN pip install locustio pyzmq +RUN apk --no-cache add g++ \ + && pip install locustio pyzmq EXPOSE 8089 5557 5558