diff --git a/src/pingjob/Dockerfile b/src/pingjob/Dockerfile new file mode 100644 index 0000000..4942b0e --- /dev/null +++ b/src/pingjob/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3-slim as base + +FROM base as builder + +RUN apt-get -qq update \ + && apt-get install -y --no-install-recommends \ + g++ + +COPY requirements.txt . + +RUN pip install --install-option="--prefix=/install" -r requirements.txt + +FROM base +COPY --from=builder /install /usr/local + +COPY . . +ENTRYPOINT ["./pinger.sh"] + diff --git a/src/pingjob/pinger.py b/src/pingjob/pinger.py new file mode 100644 index 0000000..fb9b8e7 --- /dev/null +++ b/src/pingjob/pinger.py @@ -0,0 +1,86 @@ +#!/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 + +import requests +import sys + +BASE = sys.argv[1] + +products = [ + '0PUK6V6EV0', + '1YMWWN1N4O', + '2ZYFJ3GM2N', + '66VCHSJNUP', + '6E92ZMYYFZ', + '9SIQT8TOJO', + 'L9ECAV7KIM', + 'LS4PSXUNUM', + 'OLJCESPC7Z'] + + +def index(): + requests.get(BASE + "/") + + +def setCurrency(): + currencies = ['EUR', 'USD', 'JPY', 'CAD'] + requests.post(BASE + "/setCurrency", + {'currency_code': random.choice(currencies)}) + + +def browseProduct(): + requests.get(BASE + "/product/" + random.choice(products)) + + +def viewCart(): + requests.get(BASE + "/cart") + + +def addToCart(): + product = random.choice(products) + requests.get(BASE + "/product/" + product) + requests.post(BASE + "/cart", { + 'product_id': product, + 'quantity': random.choice([1, 2, 3, 4, 5, 10])}) + + +def checkout(): + addToCart() + requests.post(BASE + "/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', + }) + + +if not BASE: + print("ERROR: no frontend address") +else: + print("pinging" + BASE) +index() +browseProduct() +addToCart() +viewCart() +checkout() diff --git a/src/pingjob/pinger.sh b/src/pingjob/pinger.sh new file mode 100755 index 0000000..9e799ae --- /dev/null +++ b/src/pingjob/pinger.sh @@ -0,0 +1,27 @@ +#!/bin/sh -eu +# +# 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. + +#!/bin/bash +set -e +trap "exit" TERM + +if [ -z "${FRONTEND_ADDR}" ]; then + echo >&2 "FRONTEND_ADDR not specified" + exit 1 +fi + +set -x +python pinger.py "${FRONTEND_ADDR}" diff --git a/src/pingjob/requirements.in b/src/pingjob/requirements.in new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/src/pingjob/requirements.in @@ -0,0 +1 @@ +requests diff --git a/src/pingjob/requirements.txt b/src/pingjob/requirements.txt new file mode 100644 index 0000000..59b8df2 --- /dev/null +++ b/src/pingjob/requirements.txt @@ -0,0 +1,11 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# pip-compile --output-file=requirements.txt requirements.in +# +certifi==2018.11.29 # via requests +chardet==3.0.4 # via requests +idna==2.8 # via requests +requests==2.21.0 +urllib3==1.24.1 # via requests