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

feat: OAS break test, API contract test, load test, security test. #134

Open
wants to merge 89 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
6db8f3c
Make Insomnia linter happy
battlebyte May 27, 2024
adedde0
Make Insomnia linter happy
battlebyte May 28, 2024
ce4d4c0
Make insomnia linter happy
battlebyte May 28, 2024
57acc9e
Make insomnia linter happy
battlebyte May 28, 2024
a6defb2
[create-pull-request] automated change
battlebyte May 28, 2024
826826c
Push package to my repo
battlebyte May 28, 2024
2d9e70f
Use ${{ github.event.repository.name }}
battlebyte May 28, 2024
613a9a4
Revert repository name
battlebyte May 28, 2024
4b19d27
Merge pull request #1 from battlebyte/create-pull-request/patch
battlebyte May 28, 2024
28173af
Upgrade deck to 1.38.0
battlebyte May 28, 2024
5619e8a
use deck gateway syntax
battlebyte May 28, 2024
dedb7cc
Trigger workflow
battlebyte May 29, 2024
175fa90
Trigger workflow
battlebyte May 29, 2024
59c8d97
[create-pull-request] automated change
battlebyte May 29, 2024
c88ab38
Merge pull request #2 from battlebyte/create-pull-request/patch
battlebyte May 29, 2024
4189707
[create-pull-request] automated change
battlebyte May 29, 2024
8180f88
Merge pull request #3 from battlebyte/PRD/kong
battlebyte May 29, 2024
7019408
Enable workflow dispatch
battlebyte May 29, 2024
92c120c
start services
battlebyte May 29, 2024
3ecd4dd
Contract testing
battlebyte May 29, 2024
581bb11
Fix ports
battlebyte May 29, 2024
1e29f59
Restore pipes in openapi specs
battlebyte May 29, 2024
3c2325b
Fixes based on contract testing
battlebyte May 29, 2024
7c2d420
Booking authentication fix
battlebyte May 29, 2024
05d5026
Own section for contract testing
battlebyte May 29, 2024
fcf422c
Fix consumer service contract
battlebyte May 29, 2024
51c4605
Allow .env files in git
battlebyte May 29, 2024
558d362
Force workflow
battlebyte May 29, 2024
8f42641
Force workflow
battlebyte May 29, 2024
8b1efbd
oasdiff
battlebyte May 29, 2024
2f0e4c2
git depth 0
battlebyte May 29, 2024
37678d2
change operation id
battlebyte May 29, 2024
2b1982b
Show output in PR
battlebyte May 30, 2024
9b8b6f3
Output in quotes:
battlebyte May 30, 2024
5614872
Use body-path
battlebyte May 30, 2024
53a5c37
Security scan on flights
battlebyte May 30, 2024
cc61e6e
Change server url in openapi spec
battlebyte May 30, 2024
a82de58
fix zap scan position
battlebyte May 30, 2024
6d280d1
change to http protocol
battlebyte May 30, 2024
0451664
Use strigo url
battlebyte Jun 4, 2024
465e86f
Fix deck gateway sync
battlebyte Jun 4, 2024
14a30a9
ACME storage to kong
battlebyte Jun 4, 2024
24a6ba0
[create-pull-request] automated change
battlebyte Jun 4, 2024
fd8d0cc
Merge pull request #6 from battlebyte/create-pull-request/patch
battlebyte Jun 4, 2024
cb4b719
[create-pull-request] automated change
battlebyte Jun 4, 2024
a236fc4
Merge pull request #7 from battlebyte/PRD/kong
battlebyte Jun 4, 2024
83e400f
Change to matrix structure
battlebyte Jul 5, 2024
d245691
Run workflow in contract-test branch
battlebyte Jul 5, 2024
77607fc
Fix GitHub token in create-an-issue
battlebyte Jul 5, 2024
a4bb077
Create comment after create PR
battlebyte Jul 5, 2024
387b52f
Fix issue creation on breaking changes
battlebyte Jul 5, 2024
9446e2b
Separate OAS check and contract testing
battlebyte Jul 5, 2024
6e78b31
update deprecated ::set-output
battlebyte Jul 5, 2024
ad386e8
Separate security testing
battlebyte Jul 5, 2024
259fc30
Checkout security test
battlebyte Jul 5, 2024
fbdfb21
Start services in security testing
battlebyte Jul 5, 2024
2271860
Test breaking change.
battlebyte Jul 5, 2024
19bd695
Manage multiline strings between actions.
battlebyte Jul 8, 2024
b729723
chore: Update base64 encoding for changelog content
battlebyte Jul 8, 2024
b29490c
chore: Update base64 encoding for changelog content
battlebyte Jul 8, 2024
ebc7ec3
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
3e44069
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
fd6dd49
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
c50bdb1
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
874f4b9
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
04681ec
chore: Update PR comment creation with changelog content
battlebyte Jul 8, 2024
733e1ba
Update flight number property type to integer
battlebyte Jul 8, 2024
cf55ae8
Update flight number property type to string
battlebyte Jul 8, 2024
0226fda
Update PR comment creation with changelog content
battlebyte Jul 8, 2024
632daaf
Load testing
battlebyte Jul 8, 2024
95a9420
chore: Update openapi-generator version to v0.3.0 and fix openapi fil…
battlebyte Jul 8, 2024
8f1d88c
Update parameter name in openapi.yaml file
battlebyte Jul 8, 2024
7f33c9e
chore: Update k6 version and add npm install step for dependencies
battlebyte Jul 8, 2024
dd4384c
chore: Update k6 load test
battlebyte Jul 8, 2024
9cb152f
Update k6 load test script and specify username in script.js file
battlebyte Jul 15, 2024
0883317
add deck file lint example
battlebyte Jul 15, 2024
05cfaa3
chore: Update Kong linting step in GitHub workflow
battlebyte Jul 23, 2024
1ad4722
chore: Update Kong deployment workflow to support different targets
battlebyte Jul 23, 2024
46a0850
Update README
battlebyte Jul 24, 2024
affb44e
Update README
battlebyte Jul 24, 2024
e0879c1
Update README
battlebyte Jul 24, 2024
71657e0
Update README
battlebyte Jul 24, 2024
851b4b1
Update README.md
battlebyte Jul 29, 2024
418053c
Use github.actor in ghcr.io
battlebyte Jul 30, 2024
3848bbb
Disable formatting in bookings.json
battlebyte Jul 30, 2024
0b8eec9
Open API url https://api.kong-air.com.
battlebyte Jul 30, 2024
10c3154
Update Kong linting rules for https usage in GW Services and Routes
battlebyte Jul 30, 2024
b17f1cd
chore: Update Kong linting rules for http usage in GW Services
battlebyte Jul 30, 2024
21a4de0
chore: Update title in openapi.yaml
battlebyte Jul 31, 2024
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
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/breaking-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: 'Breaking Change Detected for "{{ env.APP_NAME }}":'
---

A breaking change was detected in the OpenAPI specification. Please review the changes.

{{ env.BREAKING_CHANGES }}
30 changes: 24 additions & 6 deletions .github/workflows/deploy-kong-PRD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- PRD/kong/kong.yaml
- .github/workflows/deploy-kong-PRD.yaml
workflow_dispatch:

jobs:

Expand All @@ -23,6 +24,8 @@ jobs:
deploy-kong:
name: Deploy Kong to PRD
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: KONNECT

steps:
- name: Checkout
Expand All @@ -31,12 +34,27 @@ jobs:
- name: Setup deck
uses: kong/setup-deck@v1
with:
deck-version: '1.26.0'
deck-version: '1.38.0'
wrapper: false

- name: deck sync
- name: deck sync konnect
if: env.DEPLOY_TARGET == 'KONNECT' || env.DEPLOY_TARGET == ''
run: |
deck sync --select-tag platform-repo-managed \
-s PRD/kong/kong.yaml \
--konnect-runtime-group-name KongAir-PRD \
--konnect-token ${{ secrets.KONNECT_PAT }}
deck gateway sync --select-tag platform-repo-managed \
--konnect-control-plane-name ${{ env.KONNECT_CP_NAME }}\
--konnect-token ${{ secrets.KONNECT_PAT }} \
--konnect-addr ${{ env.KONNECT_ADDR }} \
PRD/kong/kong.yaml

- name: deck sync Kong EE
if: env.DEPLOY_TARGET == 'EE'
run: |
deck gateway sync --select-tag platform-repo-managed \
--kong-addr ${{ env.KONG_EE_ADMIN_API }} \
PRD/kong/kong.yaml

- name: deck sync Kong Ingress Controller
if: env.DEPLOY_TARGET == 'KIC'
run: |
deck file kong2kic --select-tag platform-repo-managed \
-s PRD/kong/kong.yaml | kubectl apply -f -
3 changes: 2 additions & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths-ignore:
- 'PRD/**'
- 'platform/kong/.generated/kong.yaml'
workflow_dispatch:

jobs:
docker:
Expand Down Expand Up @@ -43,4 +44,4 @@ jobs:
context: "${{ matrix.app.dir }}/${{ matrix.app.name }}"
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/kong/kongair-${{ matrix.app.name }}:latest
tags: ghcr.io/battlebyte/kongair-${{ matrix.app.name }}:latest
battlebyte marked this conversation as resolved.
Show resolved Hide resolved
226 changes: 221 additions & 5 deletions .github/workflows/stage-changes-for-kong.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ on:
branches:
- main
- workflow/**
- contract-test
paths-ignore:
- 'PRD/**'
- 'platform/kong/.generated/kong.yaml'
workflow_dispatch:

jobs:

Expand Down Expand Up @@ -48,23 +50,189 @@ jobs:
- 'sales/customer/kong/**'
- 'experience/kong/**'
- 'platform/kong/**'

oas-to-kong:
name: Convert OAS to Kong configurations


# Check if there are breaking changes in the OAS
# specifications of the services. If there are breaking
# changes, create an issue in the repository.
oas-break:
name: Check breaking changes

needs: has-changes
if: ${{ needs.has-changes.outputs.are-changes == 'true' }}

runs-on: ubuntu-latest
strategy:
matrix:
app:
- dir: flight-data
name: flights
port: 8080
- dir: flight-data
name: routes
port: 8081
- dir: sales
name: bookings
port: 8082
- dir: sales
name: customer
port: 8083

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# The base OAS file is the version of the OAS file from the previous commit
- name: Base OAS
run: |
git show HEAD~1:${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml > ${{ matrix.app.dir }}/${{ matrix.app.name }}/base.yaml
# Check breaking changes in the OAS and create an issue if there are any
- name: Check OAS breaking changes
uses: oasdiff/oasdiff-action/breaking@main
id: oasdiff # Static ID
with:
base: ${{ matrix.app.dir }}/${{ matrix.app.name }}/base.yaml
revision: ${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml
- name: Create Issue on Breaking Change
if: steps.oasdiff.outputs.breaking != 'No breaking changes'
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_NAME: ${{ matrix.app.name }}
BREAKING_CHANGES: ${{ steps.oasdiff.outputs.breaking }}
with:
filename: .github/ISSUE_TEMPLATE/breaking-change.md

# Run contract testing with SchemaThesis.
# The tests are based on the OpenAPI specifications of the services.
contract-test:
name: Contract testing
needs: has-changes
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Start the API implementation services and execute contract testing
# If you have a schemathesis token, you can uncomment the token line and use it
- name: Start services
run: chmod +x run-all.sh && ./run-all.sh
- name: Contract testing flights
uses: schemathesis/action@v1
with:
schema: flight-data/flights/openapi.yaml
base-url: http://localhost:8080
#token: ${{ secrets.SCHEMATHESIS_TOKEN }}
- name: Contract testing routes
uses: schemathesis/action@v1
with:
schema: flight-data/routes/openapi.yaml
base-url: http://localhost:8081
#token: ${{ secrets.SCHEMATHESIS_TOKEN }}
- name: Contract testing bookings
uses: schemathesis/action@v1
with:
schema: sales/bookings/openapi.yaml
base-url: http://localhost:8082
args: '-H "x-consumer-username: dfreese"'
#token: ${{ secrets.SCHEMATHESIS_TOKEN }}
- name: Contract testing customer
uses: schemathesis/action@v1
with:
schema: sales/customer/openapi.yaml
base-url: http://localhost:8083
args: '-H "x-consumer-username: jsmith"'
#token: ${{ secrets.SCHEMATHESIS_TOKEN }}

# Run security testing with OWASP ZAP Scan.
# The test is based on the OpenAPI specifications of the services.
security-test:
name: Security testing
runs-on: ubuntu-latest
needs: has-changes
strategy:
matrix:
app:
- dir: flight-data
name: flights
- dir: flight-data
name: routes
- dir: sales
name: bookings
- dir: sales
name: customer
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Start services
run: chmod +x run-all.sh && ./run-all.sh
- name: ZAP Scan
uses: zaproxy/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
docker_name: 'ghcr.io/zaproxy/zaproxy:stable'
format: openapi
target: '${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml'

# Run load testing with K6. The script is generated from the OpenAPI specification.
load-test:
name: Load testing
runs-on: ubuntu-latest
needs: has-changes
strategy:
matrix:
app:
- dir: flight-data
name: flights
- dir: flight-data
name: routes
- dir: sales
name: bookings
- dir: sales
name: customer
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate K6 script from openapi
uses: hatamiarash7/[email protected]
with:
openapi-file: '${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml'
generator: 'k6'
output-dir: '${{ matrix.app.dir }}/${{ matrix.app.name }}/k6'
- name: Specifiy username
# if app name is bookings, use dfreese as username
# change string "TODO_EDIT_THE_X-CONSUMER-USERNAME" to "dfreese" in the script.js file
# if the app name is customer, use jsmith as username
# change string "TODO_EDIT_THE_X-CONSUMER-USERNAME" to "jsmith" in the script.js file
run: |
if [ "${{ matrix.app.name }}" == "bookings" ]; then
sed -i 's/TODO_EDIT_THE_X-CONSUMER-USERNAME/dfreese/g' '${{ matrix.app.dir }}/${{ matrix.app.name }}/k6/script.js'
fi
if [ "${{ matrix.app.name }}" == "customer" ]; then
sed -i 's/TODO_EDIT_THE_X-CONSUMER-USERNAME/jsmith/g' '${{ matrix.app.dir }}/${{ matrix.app.name }}/k6/script.js'
fi
- name: Start services
run: chmod +x run-all.sh && ./run-all.sh
- name: Run load test
run: |
curl https://github.com/grafana/k6/releases/download/v0.52.0/k6-v0.52.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
./k6 run '${{ matrix.app.dir }}/${{ matrix.app.name }}/k6/script.js' --vus 10 --duration 10s


oas-to-kong:
name: Convert OAS to Kong configurations
needs: [has-changes, oas-break, contract-test]
if: ${{ needs.has-changes.outputs.are-changes == 'true' }}
runs-on: ubuntu-latest
outputs:
pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup deck
uses: kong/setup-deck@v1
with:
deck-version: '1.26.0'
deck-version: '1.38.0'
wrapper: false

- name: Convert Flights API to Kong
Expand Down Expand Up @@ -143,6 +311,9 @@ jobs:
-o platform/kong/.generated/kong.yaml \
"platform-repo-managed"

- name: Kong linting
run: deck file lint -s platform/kong/.generated/kong.yaml platform/kong/lint-rulesets.yaml

- name: Upload Artifacts
# Artifacts are the files that are built along the way of the pipeline but are not committed to the repo
uses: actions/upload-artifact@v3
Expand All @@ -151,7 +322,52 @@ jobs:
path: .github/artifacts/kong/*.yaml

- name: Create PR for changed Kong Gateway Configuration
id: create_pr
# The only file that should be changed for this PR is platform/kong/.generated/kong.yaml
uses: peter-evans/create-pull-request@v5
with:
title: Stage Kong Gateway Configuration

# Obtain the changelog between the previous and current OAS for all services
# and create a PR comment with the changelog. This is useful for tracking changes
# and provides details in case of breaking changes.
oas-changelog:
# obtain the changelog between the previous and current OAS for all services
# and create a PR comment with the changelog
needs: oas-to-kong
runs-on: ubuntu-latest
strategy:
matrix:
app:
- dir: flight-data
name: flights
- dir: flight-data
name: routes
- dir: sales
name: bookings
- dir: sales
name: customer
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# The base OAS file is the version of the OAS file from the previous commit
- name: Base OAS
run: |
git show HEAD~1:${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml > ${{ matrix.app.dir }}/${{ matrix.app.name }}/base.yaml
- name: Obtain Changelog OAS
id: oaschangelog
uses: oasdiff/oasdiff-action/changelog@main
with:
base: ${{ matrix.app.dir }}/${{ matrix.app.name }}/base.yaml
revision: ${{ matrix.app.dir }}/${{ matrix.app.name }}/openapi.yaml
output-to-file: ${{ matrix.app.dir }}/${{ matrix.app.name }}/changelog.txt
- name: Create PR Comment with Changelog
id: create_comment
if: steps.oaschangelog.outputs.changelog != 'No changelog changes'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ needs.oas-to-kong.outputs.pull-request-number }}
body-path: ${{ matrix.app.dir }}/${{ matrix.app.name }}/changelog.txt

5 changes: 3 additions & 2 deletions .github/workflows/stage-kong-for-PRD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths:
- platform/kong/.generated/kong.yaml
- .github/workflows/stage-kong-for-PRD.yaml
workflow_dispatch:

jobs:

Expand All @@ -32,7 +33,7 @@ jobs:
- name: Setup deck
uses: kong/setup-deck@v1
with:
deck-version: '1.26.0'
deck-version: '1.38.0'
wrapper: false

- name: stage combined file for PRD
Expand All @@ -46,7 +47,7 @@ jobs:
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "DIFF<<$EOF" >> $GITHUB_ENV
deck diff --select-tag platform-repo-managed -s PRD/kong/kong.yaml --konnect-runtime-group-name KongAir-PRD --konnect-token ${{ secrets.KONNECT_PAT }} >> $GITHUB_ENV
deck gateway diff --select-tag platform-repo-managed --konnect-control-plane-name KongAir-PRD --konnect-token ${{ secrets.KONNECT_PAT }} PRD/kong/kong.yaml >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV

- name: Create PR to stage changes for the Kong Gateway in production
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ kong-quickstart.*
kong.env
kong.yaml
*.pid
.hypothesis/
Loading