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

initial commit nodejs service #35

Closed
wants to merge 11 commits into from
9 changes: 5 additions & 4 deletions .github/workflows/build-images-on-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on:
push:
branches: [main]
paths:
- 'src/loaders/**'
- 'src/services/**'
- '.version'
- "src/loaders/**"
- "src/services/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/build-images-on-commit.yml"
workflow_dispatch:
jobs:
build:
uses: ./.github/workflows/reusable-build-container-images.yml
with:
push: true
release_stream: dev
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
pull_request_target:
branches: [main]
paths:
- 'src/loaders/**'
- 'src/services/**'
- '.version'
- "src/loaders/**"
- "src/services/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/check.yml"
jobs:
build:
uses: ./.github/workflows/reusable-build-container-images.yml
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build-images-on-schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Build and publish nightly container images
on:
schedule:
- cron: '0 0 * * *'
jobs:
build:
uses: ./.github/workflows/reusable-build-container-images.yml
with:
push: true
secrets: inherit
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: Build and publish release container images
on:
release:
types: [published]
push:
tags:
- 'v*.*.*'
jobs:
build:
uses: ./.github/workflows/reusable-build-container-images.yml
with:
push: true
release_stream: latest
secrets: inherit
11 changes: 7 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: lint
on:
workflow_dispatch:
push:
# Run superlinter on pushes to default branch
branches:
Expand All @@ -20,16 +21,18 @@ jobs:
statuses: write
steps:
- name: 🔒 harden runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: 🧹 run superlinter
uses: super-linter/super-linter@e1cb86b6e8d119f789513668b4b30bf17fe1efe4 # v7.2.0
uses: super-linter/super-linter@85f7611e0f7b53c8573cca84aa0ed4344f6f6a4d # v7.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
YAML_CONFIG_FILE: '.yamllint.yml'
LINTER_RULES_PATH: '.'
YAML_CONFIG_FILE: '.yamllint'
VALIDATE_GIT_COMMITLINT: false
VALIDATE_ALL_CODEBASE: false
MULTI_STATUS: false
35 changes: 20 additions & 15 deletions .github/workflows/reusable-build-container-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ on:
default: false
required: false
type: boolean
release_stream:
type: string
description: Set the release stream (latest, dev, ...)
required: false
default: dev
registry_ghcr:
description: github container registry
default: 'ghcr.io/cisco-open/app-simulator'
default: "ghcr.io/cisco-open/app-simulator"
required: false
type: string
jobs:
Expand All @@ -25,19 +20,29 @@ jobs:
image:
- context: ./src/loaders/curl
name: loaders-curl
- context: ./src/services/java
name: services-java
steps:
- name: Checkout
uses: actions/[email protected]
- name: Bump version
# Only bump the version if the release stream is not 'latest'
# This way we make sure that released versions are fixed to their version
# and that 'dev' or other non stable releases do not overwrite.
if: ${{ inputs.release_stream != 'latest' }}
run: ./scripts/bumpversion.sh --patch
- name: Read version from .version file
id: version
run: |
echo "version=$(cat .version)" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry_ghcr }}-${{ matrix.image.name }} # e.g. ghcr.io/cisco-open/app-simulator-loaders-curl
# build nightly releases on schedule
# build semver releases on tag
# build edge releases on main branch
tags: |
type=schedule,pattern={{date 'YYYYMMDD'}}
type=semver,pattern={{ version }}
type=edge,branch=main
labels: |

- name: Log into GitHub Container Registry
if: ${{ inputs.push }}
uses: docker/login-action@v3
Expand All @@ -57,8 +62,8 @@ jobs:
context: ${{ matrix.image.context }}
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push }}
tags: |
${{ inputs.registry_ghcr }}-${{ matrix.image.name }}:${{ steps.version.outputs.version }}
${{ inputs.registry_ghcr }}-${{ matrix.image.name }}:${{ inputs.release_stream }}
cache-from: type=gha
cache-to: type=gha
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
36 changes: 0 additions & 36 deletions examples/backend.json

This file was deleted.

8 changes: 8 additions & 0 deletions examples/docker-compose/backend-db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "mysql",
"name": "backend-db",
"databases": {
"carts": ["id", "name", "total"]
}
}

15 changes: 15 additions & 0 deletions examples/docker-compose/backend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "java",
"endpoints": {
"http": {
"/cart/checkout": [
"sleep,1000",
"sql://backend-db/?query=SELECT * from carts",
["http://ext-payment-1:8080/pay", "http://ext-payment-2:8080/pay"]
],
"/cart/add": ["sql://backend-db/?query=SELECT * from carts"],
"error": [{ "call": "error,500,Cart not found", "probability": 0.5 }]
}
},
"name": "backend"
}
File renamed without changes.
53 changes: 53 additions & 0 deletions examples/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
services:
frontend:
image: ghcr.io/cisco-open/app-simulator-services-java:latest
build:
context: ../../src/services/java
dockerfile: Dockerfile
ports:
- "8080:8080"
volumes:
- ./frontend.json:/config.json
backend:
image: ghcr.io/cisco-open/app-simulator-services-java:latest
build:
context: ../../src/services/java
dockerfile: Dockerfile
ports:
- "8090:8080"
volumes:
- ./backend.json:/config.json
ext-payment:
image: ghcr.io/cisco-open/app-simulator-services-java:latest
build:
context: ../../src/services/java
dockerfile: Dockerfile
ports:
- "8091:8080"
volumes:
- ./ext-payment.json:/config.json
networks:
default:
aliases:
- ext-payment-1
- ext-payment-2
loader:
image: ghcr.io/cisco-open/app-simulator-loaders-curl:latest
build:
context: ../../src/loaders/curl
dockerfile: Dockerfile
environment:
- URLS=https://frontend:8080/addtocart http://frontend:8080/checkout
- SLEEP=5
- WAIT=1
# backend-db:
# image: ghcr.io/cisco-open/app-simulator-databases-mysql:latest
# build:
# context: ../src/databases/mysql
# dockerfile: Dockerfile
# ports:
# - "3306:3306"
# volumes:
# - ./backend-db.json:/config.json
networks:
default:
13 changes: 13 additions & 0 deletions examples/docker-compose/ext-payment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "java",
"endpoints": {
"http": {
"/pay": [
"sleep,50",
"log,warn,do some logging",
"log,more logging",
]
}
},
"name": "ext-payment"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "nodejs",
"type": "java",
"options": {
"connectionDelay": 500,
"httpLibrary": "request-promise"
Expand All @@ -9,7 +9,7 @@
"/logo.png": ["sleep,1000"],
"/script.js": ["sleep,5000"],
"/checkout": [
"http://backend/cart/checkout",
"http://backend:8080/cart/checkout",
"image,logo.png",
"script,script.js",
"ajax,cache"
Expand Down
7 changes: 6 additions & 1 deletion src/loaders/curl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM alpine:3.20.3
RUN apk add --no-cache curl=8.11.0-r2 util-linux=2.40.1-r1

LABEL org.opencontainers.image.source https://github.com/cisco-open/app-simulator
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
WORKDIR /usr/bin/
COPY loader.sh /usr/bin
RUN chmod +x /usr/bin/loader.sh
Expand Down
3 changes: 1 addition & 2 deletions src/loaders/curl/loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ while true; do
ID=$(uuidgen)
for URL in ${URLS}; do
/usr/bin/curl -s "${URL}?unique_session_id=${ID}"
#/usr/bin/curl -s -X POST -d "unique_session_id=${ID}" "${URL}"
done
sleep "${SLEEP}"
done
done
5 changes: 5 additions & 0 deletions src/services/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package

FROM openjdk:11-jre

LABEL org.opencontainers.image.source https://github.com/cisco-open/app-simulator
LABEL org.opencontainers.image.description="java service for app-simulator"
LABEL org.opencontainers.image.licenses=BSD-3-Clause

RUN mkdir -p /app/dependency-jars
WORKDIR /app
COPY --from=build /home/app/target /app/
Expand Down
Loading