Set up for running in distributed mode using Docker

This commit is contained in:
Christopher DeCairos 2019-09-26 14:44:48 -04:00
Родитель 08f5fead4e
Коммит 08c004166d
5 изменённых файлов: 69 добавлений и 2 удалений

25
Dockerfile Normal file
Просмотреть файл

@ -0,0 +1,25 @@
FROM python:3.7-slim-stretch
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
WORKDIR /app/
RUN apt-get update && apt-get upgrade -y
RUN pip install virtualenv
RUN virtualenv venv
COPY requirements.txt .
RUN . /app/venv/bin/activate && pip install -r requirements.txt
COPY stress_test.py .
COPY docker_start.sh .
RUN useradd -ms /bin/bash locust
USER locust
CMD . /app/venv/bin/activate && ./docker_start.sh

Просмотреть файл

@ -3,4 +3,17 @@ donate-wagtail-locust
This project aims to help us in capacity planning for the new wagtail based donate platform we're launching in late 2019.
This is a very early WIP commit, more documentation to follow once it's in a working state.
### Running with Docker locally
1. `docker build -t donate-locust .`
2. Copy the sample environment file, and customize it to your needs: `cp sample.env .env`.
3. `docker run --env-file .env -p 8089:8089 --add-host "localhost:$HOST_IP_ADDR" -it donate-locust`
#### Environment variables
| Variable | Description |
|--------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| TARGET_URL | The hostname (including protocol) of the wagtail-donate stack to test. Required. |
| LOCUST_MODE | Start locust in the specified mode. One of `standalone`, `leader`, or `follower`. Optional, defaults to `standalone` |
| LOCUST_LEADER_HOST | When running in distributed mode, this variable tells followers where to connect to the leader node. Required when `LOCUST_MODE` is `standalone` |
| LOCUST_LEADER_PORT | When running in distributed mode, this variable tells followers what port number the leader mode is listening for follower nodes on. optional, defaults to `5557` |

27
docker_start.sh Executable file
Просмотреть файл

@ -0,0 +1,27 @@
#!/usr/bin/env sh
# adapted from https://github.com/locustio/locust/blob/246ec42e59fe38f0d27b8ea752209d838e27b898/docker_start.sh
if [ -z "${TARGET_URL}" ]; then
echo "ERROR: TARGET_URL is not configured" >&2
exit 1
fi
LOCUST_MODE="${LOCUST_MODE:=standalone}"
LOCUST_OPTS="-f ./stress_test.py -H ${TARGET_URL}"
if [ "${LOCUST_MODE}" = "leader"]; then
LOCUST_OPTS="${LOCUST_OPTS} --master"
elif [ "${LOCUST_MODE}" = "follower" ]; then
if [ -z "$LOCUST_LEADER_HOST" ]; then
echo "ERROR: LOCUST_LEADER_HOST is not configured. A follower node requires a leader node." >&2
exit 1
fi
LOCUST_OPTS="${LOCUST_OPTS} --slave --master-host=${LOCUST_LEADER_HOST} --master-port=${LOCUST_LEADER_PORT:-5557}"
fi
echo "starting Locust"
echo "$ locust ${LOCUST_OPTS}"
locust ${LOCUST_OPTS}

2
sample.env Normal file
Просмотреть файл

@ -0,0 +1,2 @@
TARGET_URL=http://localhost:4000
LOCUST_MODE=standalone

Просмотреть файл

@ -21,7 +21,7 @@ class DonorBehaviour(TaskSequence):
'amount': 50,
'landing_url': 'https://donate-wagtail-staging.herokuapp.com/en-US/',
'project': 'mozillafoundation',
'campaign_id': 'testing-a-donation',
'campaign_id': 'test-campaign',
# https://developers.braintreepayments.com/reference/general/testing/python#nonces-representing-cards
'braintree_nonce': 'fake-valid-nonce'
}