Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use config file with CURL loader #53

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ services:
- ext-payment-2
loader:
image: ghcr.io/cisco-open/app-simulator-loaders-curl:latest
pull_policy: build
build:
context: ../src/loaders/curl
dockerfile: Dockerfile
environment:
- URLS=https://frontend:8080/addtocart http://frontend:8080/checkout
- SLEEP=5
- WAIT=1
volumes:
- ./loader.json:/config.json

# backend-db:
# image: ghcr.io/cisco-open/app-simulator-databases-mysql:latest
# build:
Expand All @@ -50,4 +50,4 @@ services:
# volumes:
# - ./backend-db.json:/config.json
networks:
default:
default:
8 changes: 8 additions & 0 deletions examples/loader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sleep" : 5,
"urls" : [
"https://frontend:8080/addtocart",
"http://frontend:8080/checkout"
],
"wait" : 1
}
8 changes: 4 additions & 4 deletions src/loaders/curl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ LABEL org.opencontainers.image.source=https://github.com/cisco-open/app-simulato
LABEL org.opencontainers.image.description="curl loader for app-simulator"
LABEL org.opencontainers.image.licenses=BSD-3-Clause

RUN apk add --no-cache curl util-linux
RUN apk add --no-cache curl util-linux jq
WORKDIR /usr/bin/
COPY loader.sh /usr/bin
RUN chmod +x /usr/bin/loader.sh
ENTRYPOINT ["/usr/bin/loader.sh"]
COPY entrypoint.sh /usr/bin
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
37 changes: 37 additions & 0 deletions src/loaders/curl/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

LOADER_CONFIG="/config.json"

# Check if the file exists
if [[ ! -f "${LOADER_CONFIG}" ]]; then
echo "Error: $LOADER_CONFIG not found!"
exit 1
fi

SLEEP=$(jq -r '.sleep' "$LOADER_CONFIG")
WAIT=$(jq -r '.wait' "$LOADER_CONFIG")
URLS=$(jq -r '.urls | join(" ")' "$LOADER_CONFIG")

# Check if SLEEP and WAIT are numbers
if ! [[ "${SLEEP}" =~ ^[0-9]+$ ]]; then
echo "Error: SLEEP is not a valid number: $SLEEP"
exit 1
fi

if ! [[ "${WAIT}" =~ ^[0-9]+$ ]]; then
echo "Error: WAIT is not a valid number: $WAIT"
exit 1
fi

echo "Running CURL load in ${WAIT} seconds ..."
echo "URLs to test"
echo "${URLS}"
echo "Sleep time in between requests ${SLEEP}"
sleep "${WAIT}"
while true; do
ID=$(uuidgen)
for URL in ${URLS}; do
/usr/bin/curl -s "${URL}?unique_session_id=${ID}"
done
sleep "${SLEEP}"
done
13 changes: 0 additions & 13 deletions src/loaders/curl/loader.sh

This file was deleted.

Loading