[Locust Dockerfile]

FROM python:3.6.2

# Install packages
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt

# Add tasks directory
COPY locust-tasks /locust-tasks

# Set the entrypoint
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 5557 5558 8089




[docker-entrypoint.sh]

#!/bin/bash

LOCUST_MODE=${LOCUST_MODE:="standalone"}
LOCUST_MASTER=${LOCUST_MASTER:=""}
LOCUST_LOCUSTFILE_PATH=${LOCUST_LOCUSTFILE_PATH:="/locust-tasks/basic.py"}
LOCUST_LOCUSTFILE_URL=${LOCUST_LOCUSTFILE_URL:=""}
LOCUST_TARGET_HOST=${LOCUST_TARGET_HOST:="https://example.com"}

if [ ! -z "$LOCUST_LOCUSTFILE_URL" ]; then
    LOCUST_LOCUSTFILE_PATH="/locust-tasks/locustfile.py"
    curl $LOCUST_LOCUSTFILE_URL -o $LOCUST_LOCUSTFILE_PATH
fi

LOCUST_PATH="/usr/local/bin/locust"
LOCUST_FLAGS="-f $LOCUST_LOCUSTFILE_PATH --host=$LOCUST_TARGET_HOST"

if [[ "$LOCUST_MODE" = "master" ]]; then
    LOCUST_FLAGS="$LOCUST_FLAGS --master"
elif [[ "$LOCUST_MODE" = "slave" ]]; then
    LOCUST_FLAGS="$LOCUST_FLAGS --slave --master-host=$LOCUST_MASTER"
fi

exec $LOCUST_PATH $LOCUST_FLAGS




[requirements.txt]

Flask==0.12.2
gevent==1.2.2
greenlet==0.4.12
itsdangerous==0.24
Jinja2==2.9.6
locustio==0.8.1
MarkupSafe==1.0
msgpack-python==0.4.8
pyzmq==16.0.2
requests==2.18.4
Werkzeug==0.12.2





[locust-tasks/basic.py]

from locust import HttpLocust, TaskSet, task

def index(l):
    l.client.get("/")

def stats(l):
    l.client.get("/stats/requests")

class UserTasks(TaskSet):
    # one can specify tasks like this
    tasks = [index, stats]
    
    # but it might be convenient to use the @task decorator
    @task
    def page404(self):
        self.client.get("/does_not_exist")
    
class WebsiteUser(HttpLocust):
    """
    Locust user class that does requests to the locust web server running on 
localhost
    """
    host = "http://127.0.0.1:8089";
    min_wait = 2000
    max_wait = 5000
    task_set = UserTasks


-- 
You received this message because you are subscribed to the Google Groups 
"Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to kubernetes-users+unsubscr...@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to