diff --git a/1 b/1 deleted file mode 100644 index d00491fd..00000000 --- a/1 +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0f79421e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM python:3.11.1-slim@sha256:1591aa8c01b5b37ab31dbe5662c5bdcf40c2f1bce4ef1c1fd24802dae3d01052 as base + +FROM base as builder + +COPY requirements.txt . + +RUN pip install --prefix="/install" -r requirements.txt + +FROM base + +WORKDIR /loadgen + +COPY --from=builder /install /usr/local + +# Add application code. +COPY locustfile.py . + +# enable gevent support in debugger +ENV GEVENT_SUPPORT=True + +ENTRYPOINT locust --host="http://${FRONTEND_ADDR}" --headless -u "${USERS:-10}" 2>&1 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..8f43dc57 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,25 @@ +pipeline { + agent any + + stages { + stage('Build & Tag Docker Image') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker build -t abhishek0768/loadgenerator:latest ." + } + } + } + } + + stage('Push Docker Image') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker push abhishek0768/loadgenerator:latest" + } + } + } + } + } +} diff --git a/locustfile.py b/locustfile.py new file mode 100644 index 00000000..7874fc7a --- /dev/null +++ b/locustfile.py @@ -0,0 +1,81 @@ +#!/usr/bin/python +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import random +from locust import HttpUser, TaskSet, between + +products = [ + '0PUK6V6EV0', + '1YMWWN1N4O', + '2ZYFJ3GM2N', + '66VCHSJNUP', + '6E92ZMYYFZ', + '9SIQT8TOJO', + 'L9ECAV7KIM', + 'LS4PSXUNUM', + 'OLJCESPC7Z'] + +def index(l): + l.client.get("/") + +def setCurrency(l): + currencies = ['EUR', 'USD', 'JPY', 'CAD'] + l.client.post("/setCurrency", + {'currency_code': random.choice(currencies)}) + +def browseProduct(l): + l.client.get("/product/" + random.choice(products)) + +def viewCart(l): + l.client.get("/cart") + +def addToCart(l): + product = random.choice(products) + l.client.get("/product/" + product) + l.client.post("/cart", { + 'product_id': product, + 'quantity': random.choice([1,2,3,4,5,10])}) + +def checkout(l): + addToCart(l) + l.client.post("/cart/checkout", { + 'email': 'someone@example.com', + 'street_address': '1600 Amphitheatre Parkway', + 'zip_code': '94043', + 'city': 'Mountain View', + 'state': 'CA', + 'country': 'United States', + 'credit_card_number': '4432-8015-6152-0454', + 'credit_card_expiration_month': '1', + 'credit_card_expiration_year': '2039', + 'credit_card_cvv': '672', + }) + +class UserBehavior(TaskSet): + + def on_start(self): + index(self) + + tasks = {index: 1, + setCurrency: 2, + browseProduct: 10, + addToCart: 2, + viewCart: 3, + checkout: 1} + +class WebsiteUser(HttpUser): + tasks = [UserBehavior] + wait_time = between(1, 10) diff --git a/requirements.in b/requirements.in new file mode 100644 index 00000000..ff3f31f4 --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +locust==2.15.1 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..0f48d953 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,78 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --output-file=requirements.txt requirements.in +# +blinker==1.6.2 + # via flask +brotli==1.0.9 + # via geventhttpclient +certifi==2022.12.7 + # via + # geventhttpclient + # requests +charset-normalizer==3.1.0 + # via requests +click==8.1.3 + # via flask +configargparse==1.5.3 + # via locust +flask==2.3.2 + # via + # flask-basicauth + # flask-cors + # locust +flask-basicauth==0.2.0 + # via locust +flask-cors==3.0.10 + # via locust +gevent==22.10.2 + # via + # geventhttpclient + # locust +geventhttpclient==2.0.9 + # via locust +greenlet==2.0.2 + # via gevent +idna==3.4 + # via requests +itsdangerous==2.1.2 + # via flask +jinja2==3.1.2 + # via flask +locust==2.15.1 + # via -r requirements.in +markupsafe==2.1.2 + # via + # jinja2 + # werkzeug +msgpack==1.0.5 + # via locust +psutil==5.9.5 + # via locust +pyzmq==25.0.2 + # via locust +requests==2.30.0 + # via locust +roundrobin==0.0.4 + # via locust +six==1.16.0 + # via + # flask-cors + # geventhttpclient +typing-extensions==4.5.0 + # via locust +urllib3==1.26.15 + # via requests +werkzeug==2.3.4 + # via + # flask + # locust +zope-event==4.6 + # via gevent +zope-interface==6.0 + # via gevent + +# The following packages are considered to be unsafe in a requirements file: +# setuptools