Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-software-pl committed Aug 28, 2024
1 parent 979a82d commit 549e5d4
Show file tree
Hide file tree
Showing 75 changed files with 3,621 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Publish Docker Image

on:
push:
branches:
- feature/NU-1740

jobs:
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Read version from file
id: get_version
run: |
VERSION=$(grep LIBRARY_DOCKER_IMAGE_VERSION version | cut -d'=' -f2)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
password: ${{ secrets.DOCKERHUB_USER }}
username: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker images
uses: docker/buildx-action@v2
with:
args: |
--platform linux/amd64,linux/arm64
--push
-t myusername/myimage:latest
-t myusername/myimage:${{ env.VERSION }}
.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.swp
.idea
*.iml
target
.metals
.vscode
.DS_Store
common/scripts/jq
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM holomekc/wiremock-gui:3.8.1 AS wiremock

RUN apt-get update && \
apt-get install -y wget && \
wget -P /var/wiremock/extensions https://repo1.maven.org/maven2/org/wiremock/extensions/wiremock-faker-extension-standalone/0.2.0/wiremock-faker-extension-standalone-0.2.0.jar

FROM phusion/baseimage:noble-1.0.0

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

WORKDIR /app

COPY scenario-examples-bootstrapper/setup/ /app/setup/
COPY scenario-examples-bootstrapper/mocks/ /app/mocks/
COPY scenario-examples-bootstrapper/data/ /app/data/
COPY scenario-examples-bootstrapper/utils/ /app/utils/
COPY scenario-examples-bootstrapper/run-mocks-setup-data.sh /app/run-mocks-setup-data.sh

COPY scenario-examples-bootstrapper/services/postgres.sh /etc/service/db/run
COPY scenario-examples-bootstrapper/services/wiremock.sh /etc/service/http-service/run
COPY scenario-examples-bootstrapper/services/setup.sh /etc/service/setup/run

# WIREMOCK & POSTGRES
COPY --from=wiremock /var/wiremock /var/wiremock
COPY --from=wiremock /home/wiremock /home/wiremock

USER root

RUN apt update && \
apt install -y --no-install-recommends curl ca-certificates jq less && \
install -d /usr/share/postgresql-common/pgdg && \
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc && \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt update -y && \
apt -y install postgresql-16 && \
apt -y install openjdk-11-jre-headless && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
curl https://raw.githubusercontent.com/birdayz/kaf/master/godownloader.sh | BINDIR=/bin bash

EXPOSE 8080
EXPOSE 5432

COPY scenario-examples-library/ /scenario-examples

HEALTHCHECK --interval=10s --timeout=1s --retries=12 --start-period=30s \
CMD (/app/setup/is-setup-done.sh && /app/mocks/db/is-postgres-ready.sh && /app/mocks/http-service/is-wiremock-ready.sh) || exit 1
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# MOCKS

## Resources:
https://github.com/wiremock/wiremock-faker-extension/blob/main/docs/reference.md
https://docs.wiremock.io/response-templating/basics/
https://docs.wiremock.io/response-templating/dates-and-times/

# todo:
- delete
- write about disabling examples (eg. LOAN_REQUEST_DISABLED: true)
- write about required envs: NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS, SCHEMA_REGISTRY_ADDRESS, KAFKA_ADDRESS, NU_DESIGNER_ADDRESS
9 changes: 9 additions & 0 deletions build-and-push-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ./version

./build-docker-image.sh

docker push "touk/nussknacker-example-scenarios-library${LIBRARY_DOCKER_IMAGE_VERSION}"
7 changes: 7 additions & 0 deletions build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ./version

docker build -t "touk/nussknacker-example-scenarios-library${LIBRARY_DOCKER_IMAGE_VERSION}" -f Dockerfile .
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) scenario example folder path${RESET}\n"
exit 1
fi

function runRequestSending() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}ERROR: Two parameters required: 1) OpenAPI service slug, 2) request generator script${RESET}\n"
exit 11
fi

set -e

local OPENAPI_SERVICE_SLUG=$1
local REQUEST_GENERATOR_SCRIPT=$2

echo -n "Starting to send to '$OPENAPI_SERVICE_SLUG' OpenAPI service, requests generated by '$REQUEST_GENERATOR_SCRIPT' generator script... "

mkdir -p /var/log/continuously-send-http-requests
nohup ../../utils/http/continuously-send-http-requests.sh "$OPENAPI_SERVICE_SLUG" "$REQUEST_GENERATOR_SCRIPT" > /var/log/continuously-send-http-requests/output.log 2>&1 &

echo "OK"
}

SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send generated requests to Nu OpenAPI services..."

shopt -s nullglob

for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/generated"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

if [[ ! "$ITEM" == *.sh ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script${RESET}\n"
exit 3
fi

OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".sh")

runRequestSending "$OPENAPI_SERVICE_SLUG" "$ITEM"

done

echo -e "Generators are running!\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) scenario example folder path${RESET}\n"
exit 1
fi

function sendRequest() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}ERROR: Two parameters required: 1) Request-Response OpenAPI service slug, 2) request body${RESET}\n"
exit 11
fi

set -e

local OPENAPI_SERVICE_SLUG=$1
local REQUEST_BODY=$2

echo -n "Sending request '$REQUEST_BODY' to Request-Response '$OPENAPI_SERVICE_SLUG' OpenAPI service... "
../../utils/http/send-request-to-nu-openapi-service.sh "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"
echo "OK"
}

SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send preconfigured Request-Response OpenAPI service requests..."

shopt -s nullglob

for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/static"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

if [[ ! "$ITEM" == *.txt ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages${RESET}\n"
exit 3
fi

OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".txt")

while IFS= read -r REQUEST_BODY; do
if [[ $REQUEST_BODY == "#"* ]]; then
continue
fi

sendRequest "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"

done < "$ITEM"
done

echo -e "Requests sent!\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) scenario example folder path${RESET}\n"
exit 1
fi

function runMessageSending() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}ERROR: Two parameters required: 1) topic name, 2) message generator script${RESET}\n"
exit 11
fi

set -e

local TOPIC_NAME=$1
local MSG_GENERATOR_SCRIPT=$2

echo -n "Starting to send to '$TOPIC_NAME' messages generated by '$MSG_GENERATOR_SCRIPT' generator script... "

mkdir -p /var/log/continuously-send-to-topic
nohup ../../utils/kafka/continuously-send-to-topic.sh "$TOPIC_NAME" "$MSG_GENERATOR_SCRIPT" > /var/log/continuously-send-to-topic/output.log 2>&1 &

echo "OK"
}

SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send generated messages..."

shopt -s nullglob

for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/generated"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

if [[ ! "$ITEM" == *.sh ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script${RESET}\n"
exit 3
fi

TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/')

runMessageSending "$TOPIC_NAME" "$ITEM"

done

echo -e "Generators are running!\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) scenario example folder path${RESET}\n"
exit 1
fi

function sendMessage() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}ERROR: Two parameters required: 1) topic name, 2) message${RESET}\n"
exit 11
fi

set -e

local TOPIC_NAME=$1
local MSG=$2

echo -n "Sending message $MSG to '$TOPIC_NAME'"
../../utils/kafka/send-to-topic.sh "$TOPIC_NAME" "$MSG"
echo "OK"
}

SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send preconfigured messages..."

shopt -s nullglob

for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/static"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

if [[ ! "$ITEM" == *.txt ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages${RESET}\n"
exit 3
fi

TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/')

while IFS= read -r MSG; do
if [[ $MSG == "#"* ]]; then
continue
fi

sendMessage "$TOPIC_NAME" "$MSG"

done < "$ITEM"
done

echo -e "Messages sent!\n"
26 changes: 26 additions & 0 deletions scenario-examples-bootstrapper/data/keep-sending.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -e

cd "$(dirname "$0")"

source ../utils/lib.sh

echo -e "${MAGENTA}-------- DATA GENERATION ACTIVATION STAGE is starting... ------${RESET}\n"

shopt -s nullglob

for FOLDER in /scenario-examples/*; do
if isScenarioEnabled "$FOLDER"; then
echo -e "Starting to send static and generated data for scenario from ${GREEN}$FOLDER${RESET} directory...\n\n"

./http/send-http-static-requests.sh "$FOLDER"
./kafka/send-kafka-static-messages.sh "$FOLDER"
./http/continuously-send-http-generated-requests.sh "$FOLDER"
./kafka/continuously-send-kafka-generated-messages.sh "$FOLDER"

echo -e "Static data sent and generators from ${GREEN}$FOLDER${RESET} directory are runnning!\n\n"
else
echo -e "Skipping sending static and generated data for scenario from ${GREEN}$FOLDER${RESET} directory.\n"
fi
done

echo -e "${MAGENTA}-------- DATA GENERATION ACTIVATION STAGE is finished! --------${RESET}\n\n"
Loading

0 comments on commit 549e5d4

Please sign in to comment.