Skip to content

Commit

Permalink
use config file with CURL loader (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm authored Dec 18, 2024
1 parent 6a701f7 commit c677b04
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
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 "Warning: $LOADER_CONFIG not found! Environment variables will be used instead."
else
SLEEP=$(jq -r '.sleep' "$LOADER_CONFIG")
WAIT=$(jq -r '.wait' "$LOADER_CONFIG")
URLS=$(jq -r '.urls | join(" ")' "$LOADER_CONFIG")
fi


# 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.

0 comments on commit c677b04

Please sign in to comment.