-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-1740] scenario examples bootstrapper + scenario examples library (#1
) Co-authored-by: MK Software <[email protected]>
- Loading branch information
1 parent
979a82d
commit ea29a47
Showing
75 changed files
with
3,666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: PR Workflow | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build and test | ||
run: | | ||
.github/workflows/scripts/test-with-nu-quickstart.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build and Publish Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
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@v3 | ||
|
||
- 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: | ||
username: ${{ secrets.DOCKERHUB_USER }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Build and push Docker images | ||
run: | | ||
docker buildx build \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--tag touk/nussknacker-example-scenarios-library:latest \ | ||
--tag touk/nussknacker-example-scenarios-library:${{ env.VERSION }} \ | ||
--push . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash -ex | ||
|
||
cd "$(dirname "$0")" | ||
|
||
cd ../../../ | ||
EXAMPLES_LIBABRY_BUILD_TEMP_VERSION=$(uuidgen | tr -d '-' | tr 'A-Z' 'a-z' | cut -c1-10) | ||
echo "1. Building Scenario Examples Library image. Version: ${EXAMPLES_LIBABRY_BUILD_TEMP_VERSION}..." | ||
docker buildx build --tag touk/nussknacker-example-scenarios-library:"$EXAMPLES_LIBABRY_BUILD_TEMP_VERSION" . | ||
|
||
echo "2. Checking out Nu Quickstart..." | ||
cd .github/workflows/scripts | ||
rm -rf nussknacker-quickstart | ||
git clone https://github.com/TouK/nussknacker-quickstart.git | ||
cd nussknacker-quickstart | ||
git checkout staging # TODO: change to main when Nu 1.17 is released | ||
|
||
echo "3. Setting proper Scenario Examples Library image version..." | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
sed -i '' "s|touk/nussknacker-example-scenarios-library:latest|touk/nussknacker-example-scenarios-library:${EXAMPLES_LIBABRY_BUILD_TEMP_VERSION}|g" docker-compose.yml | ||
else | ||
sed -i "s|touk/nussknacker-example-scenarios-library:latest|touk/nussknacker-example-scenarios-library:${EXAMPLES_LIBABRY_BUILD_TEMP_VERSION}|g" docker-compose.yml | ||
fi | ||
|
||
on_error() { | ||
docker compose logs | ||
} | ||
|
||
on_exit() { | ||
echo "4. Cleanup" | ||
./stop-and-clean.sh | ||
rm -rf ../nussknacker-quickstart | ||
} | ||
|
||
trap on_error ERR | ||
trap on_exit EXIT | ||
|
||
./start.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.swp | ||
.idea | ||
*.iml | ||
target | ||
.metals | ||
.vscode | ||
.DS_Store | ||
**/nussknacker-installation-example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 | ||
|
||
# WIREMOCK & POSTGRES | ||
COPY --from=wiremock /var/wiremock /var/wiremock | ||
COPY --from=wiremock /home/wiremock /home/wiremock | ||
|
||
EXPOSE 8080 | ||
EXPOSE 5432 | ||
|
||
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 | ||
|
||
COPY scenario-examples-library/ /tmp/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 |
53 changes: 53 additions & 0 deletions
53
scenario-examples-bootstrapper/data/http/continuously-send-http-generated-requests.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function run_request_sending() { | ||
if [ "$#" -ne 2 ]; then | ||
red_echo "ERROR: Two parameters required: 1) OpenAPI service slug, 2) request generator script\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 | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n" | ||
exit 3 | ||
fi | ||
|
||
OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".sh") | ||
|
||
run_request_sending "$OPENAPI_SERVICE_SLUG" "$ITEM" | ||
|
||
done | ||
|
||
echo -e "Generators are running!\n" |
56 changes: 56 additions & 0 deletions
56
scenario-examples-bootstrapper/data/http/send-http-static-requests.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function send_request() { | ||
if [ "$#" -ne 2 ]; then | ||
red_echo "ERROR: Two parameters required: 1) Request-Response OpenAPI service slug, 2) request body\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 | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n" | ||
exit 3 | ||
fi | ||
|
||
OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".txt") | ||
|
||
while IFS= read -r REQUEST_BODY; do | ||
if [[ $REQUEST_BODY == "#"* ]]; then | ||
continue | ||
fi | ||
|
||
send_request "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY" | ||
|
||
done < "$ITEM" | ||
done | ||
|
||
echo -e "Requests sent!\n" |
53 changes: 53 additions & 0 deletions
53
scenario-examples-bootstrapper/data/kafka/continuously-send-kafka-generated-messages.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function run_message_sending() { | ||
if [ "$#" -ne 2 ]; then | ||
red_echo "ERROR: Two parameters required: 1) topic name, 2) message generator script\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 | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n" | ||
exit 3 | ||
fi | ||
|
||
TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/') | ||
|
||
run_message_sending "$TOPIC_NAME" "$ITEM" | ||
|
||
done | ||
|
||
echo -e "Generators are running!\n" |
56 changes: 56 additions & 0 deletions
56
scenario-examples-bootstrapper/data/kafka/send-kafka-static-messages.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function send_message() { | ||
if [ "$#" -ne 2 ]; then | ||
red_echo "ERROR: Two parameters required: 1) topic name, 2) message\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 | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n" | ||
exit 3 | ||
fi | ||
|
||
TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/') | ||
|
||
while IFS= read -r MSG; do | ||
if [[ $MSG == "#"* ]]; then | ||
continue | ||
fi | ||
|
||
send_message "$TOPIC_NAME" "$MSG" | ||
|
||
done < "$ITEM" | ||
done | ||
|
||
echo -e "Messages sent!\n" |
Oops, something went wrong.