-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add CI/testing to examples #12491
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
Merged
Merged
Add CI/testing to examples #12491
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5423ebd
Update verify_examples script
phlax 32d6477
Add azure pipeline
phlax cf02f14
fix for verify script
phlax 5342ad7
improve error handling
phlax 5bd2bdf
Fix for jaeger-native-tracing example
phlax 1304b40
Copy config into redis example image
phlax 164a229
Improve verify_example tests
phlax f956795
disable tty on exec tests
phlax 685c58d
disable tty on exec tests - continued
phlax df931ca
Add redis to (temp) azure test runner
phlax ff1932e
make azure work...
phlax 4d70253
make azure work... continued
phlax 62f4388
Tidy verify_examples script
phlax 1a6aabc
Add filter argument
phlax f5faa93
Split example tests into example folders
phlax 79a6fa4
Cleanups: mostly bash formatting and syntax
phlax 9758da4
Cleanup: bash formatting
phlax 03c89e4
Cleanup: bash vars
phlax 8466237
Use built images for examples ci tests
phlax acc13b7
Cleanup: add -s to curl in example
phlax bec9c65
Tag incoming images
phlax a57a1ef
Move image loading to ci and ensure docker uses correct images
phlax 2d01d4f
Cleanup: docker build/pull
phlax 0ce19a8
Cleanup: bash linting
phlax 2685a13
Move verify examples setup to do_ci.sh
phlax cae5ab8
Allow do_ci to run without build setup
phlax b7dd274
check user env in azure
phlax 28ebcb1
Set umask for azure user
phlax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,43 +1,67 @@ | ||
| #!/bin/bash | ||
| #!/bin/bash -E | ||
|
|
||
| set -e | ||
| TESTFILTER="${1:-*}" | ||
| FAILED=() | ||
| SRCDIR="${SRCDIR:-$(pwd)}" | ||
| EXCLUDED_BUILD_CONFIGS=${EXCLUDED_BUILD_CONFIGS:-"^./jaeger-native-tracing|docker-compose"} | ||
|
|
||
| verify() { | ||
| echo $1 | ||
| CONTAINER_ID="$(docker ps -aqf name=$1)" | ||
| if [ "false" == "$(docker inspect -f {{.State.Running}} ${CONTAINER_ID})" ] | ||
| then | ||
| echo "error: $1 not running" | ||
| exit 1 | ||
| fi | ||
|
|
||
| trap_errors () { | ||
| local frame=0 command line sub file | ||
| if [[ -n "$example" ]]; then | ||
| command=" (${example})" | ||
| fi | ||
| set +v | ||
| while read -r line sub file < <(caller "$frame"); do | ||
| if [[ "$frame" -ne "0" ]]; then | ||
| FAILED+=(" > ${sub}@ ${file} :${line}") | ||
| else | ||
| FAILED+=("${sub}@ ${file} :${line}${command}") | ||
| fi | ||
| ((frame++)) | ||
| done | ||
| set -v | ||
| } | ||
|
|
||
| trap trap_errors ERR | ||
| trap exit 1 INT | ||
|
|
||
|
|
||
| run_examples () { | ||
| local examples example | ||
| cd "${SRCDIR}/examples" || exit 1 | ||
| examples=$(find . -mindepth 1 -maxdepth 1 -type d -name "$TESTFILTER" | sort) | ||
| for example in $examples; do | ||
| pushd "$example" > /dev/null || return 1 | ||
| ./verify.sh | ||
| popd > /dev/null || return 1 | ||
| done | ||
| } | ||
|
|
||
| # Test front proxy example | ||
| cd examples/front-proxy | ||
| docker-compose up --build -d | ||
| for CONTAINER_NAME in "frontproxy_front-envoy" "frontproxy_service1" "frontproxy_service2" | ||
| do | ||
| verify $CONTAINER_NAME | ||
| done | ||
| cd ../ | ||
|
|
||
| # Test grpc bridge example | ||
| # install go | ||
| GO_VERSION="1.14.7" | ||
| curl -O https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz | ||
| tar -xf go$GO_VERSION.linux-amd64.tar.gz | ||
| sudo mv go /usr/local | ||
| export PATH=$PATH:/usr/local/go/bin | ||
| export GOPATH=$HOME/go | ||
| mkdir -p $GOPATH/src/github.com/envoyproxy/envoy/examples/ | ||
| cp -r grpc-bridge $GOPATH/src/github.com/envoyproxy/envoy/examples/ | ||
| # build example | ||
| cd $GOPATH/src/github.com/envoyproxy/envoy/examples/grpc-bridge | ||
| ./script/bootstrap | ||
| ./script/build | ||
| # verify example works | ||
| docker-compose up --build -d | ||
| for CONTAINER_NAME in "grpcbridge_python" "grpcbridge_grpc" | ||
| do | ||
| verify $CONTAINER_NAME | ||
| done | ||
| verify_build_configs () { | ||
| local config configs missing | ||
| missing=() | ||
| cd "${SRCDIR}/examples" || return 1 | ||
| configs="$(find . -name "*.yaml" -o -name "*.lua" | grep -vE "${EXCLUDED_BUILD_CONFIGS}" | cut -d/ -f2-)" | ||
| for config in $configs; do | ||
| grep "\"$config\"" BUILD || missing+=("$config") | ||
| done | ||
| if [[ -n "${missing[*]}" ]]; then | ||
| for config in "${missing[@]}"; do | ||
| echo "Missing config: $config" >&2 | ||
| done | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| verify_build_configs | ||
| run_examples | ||
|
|
||
|
|
||
| if [[ "${#FAILED[@]}" -ne "0" ]]; then | ||
| echo "TESTS FAILED:" | ||
| for failed in "${FAILED[@]}"; do | ||
| echo "$failed" >&2 | ||
| done | ||
| exit 1 | ||
| fi |
This file contains hidden or 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 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| export NAME=cors | ||
| export PATHS=frontend,backend | ||
|
|
||
| # shellcheck source=examples/verify-common.sh | ||
| . "$(dirname "${BASH_SOURCE[0]}")/../verify-common.sh" | ||
|
|
||
|
|
||
| run_log "Test service" | ||
| responds_with \ | ||
| "Envoy CORS Webpage" \ | ||
| http://localhost:8000 | ||
|
|
||
| run_log "Test cors server: disabled" | ||
| responds_with \ | ||
| Success \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8002/cors/disabled | ||
| responds_without_header \ | ||
| access-control-allow-origin \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8002/cors/disabled | ||
|
|
||
| run_log "Test cors server: open" | ||
| responds_with \ | ||
| Success \ | ||
| -H 'Origin: http://example.com' \ | ||
| http://localhost:8002/cors/open | ||
| responds_with_header \ | ||
| "access-control-allow-origin: http://example.com" \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8002/cors/open | ||
|
|
||
| run_log "Test cors server: restricted" | ||
| responds_with \ | ||
| Success \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8002/cors/restricted | ||
| responds_without_header \ | ||
| access-control-allow-origin \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8002/cors/restricted | ||
| responds_with_header \ | ||
| "access-control-allow-origin: http://foo.envoyproxy.io" \ | ||
| -H "Origin: http://foo.envoyproxy.io" \ | ||
| http://localhost:8002/cors/restricted | ||
This file contains hidden or 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,69 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| export NAME=csrf | ||
| export PATHS=samesite,crosssite | ||
|
|
||
| # shellcheck source=examples/verify-common.sh | ||
| . "$(dirname "${BASH_SOURCE[0]}")/../verify-common.sh" | ||
|
|
||
|
|
||
| run_log "Test services" | ||
| responds_with \ | ||
| "Envoy CSRF Demo" \ | ||
| http://localhost:8002 | ||
| responds_with \ | ||
| "Envoy CSRF Demo" \ | ||
| http://localhost:8000 | ||
|
|
||
| run_log "Test stats server" | ||
| responds_with \ | ||
| ":" \ | ||
| http://localhost:8001/stats | ||
|
|
||
| run_log "Test csrf server: disabled" | ||
| responds_with \ | ||
| Success \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/disabled | ||
| responds_with_header \ | ||
| "access-control-allow-origin: http://example.com" \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/disabled | ||
|
|
||
| run_log "Test csrf server: shadow" | ||
| responds_with \ | ||
| Success \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/shadow | ||
| responds_with_header \ | ||
| "access-control-allow-origin: http://example.com" \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/shadow | ||
|
|
||
| run_log "Test csrf server: enabled" | ||
| responds_with \ | ||
| "Invalid origin" \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/enabled | ||
| responds_with_header \ | ||
| "HTTP/1.1 403 Forbidden" \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/enabled | ||
|
|
||
| run_log "Test csrf server: additional_origin" | ||
| responds_with \ | ||
| Success \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/additional_origin | ||
| responds_with_header \ | ||
| "access-control-allow-origin: http://example.com" \ | ||
| -X POST \ | ||
| -H "Origin: http://example.com" \ | ||
| http://localhost:8000/csrf/additional_origin |
This file contains hidden or 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 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| export NAME=ext_authz | ||
|
|
||
| # shellcheck source=examples/verify-common.sh | ||
| . "$(dirname "${BASH_SOURCE[0]}")/../verify-common.sh" | ||
|
|
||
|
|
||
| run_log "Test services responds with 403" | ||
| responds_with_header \ | ||
| "HTTP/1.1 403 Forbidden"\ | ||
| http://localhost:8000/service | ||
|
|
||
| run_log "Restart front-envoy with FRONT_ENVOY_YAML=config/http-service.yaml" | ||
| docker-compose down | ||
| FRONT_ENVOY_YAML=config/http-service.yaml docker-compose up -d | ||
| sleep 10 | ||
|
|
||
| run_log "Test service responds with 403" | ||
| responds_with_header \ | ||
| "HTTP/1.1 403 Forbidden"\ | ||
| http://localhost:8000/service | ||
|
|
||
| run_log "Test authenticated service responds with 200" | ||
| responds_with_header \ | ||
| "HTTP/1.1 200 OK" \ | ||
| -H "Authorization: Bearer token1" \ | ||
| http://localhost:8000/service | ||
|
|
||
| run_log "Restart front-envoy with FRONT_ENVOY_YAML=config/opa-service/v2.yaml" | ||
| docker-compose down | ||
| FRONT_ENVOY_YAML=config/opa-service/v2.yaml docker-compose up -d | ||
| sleep 10 | ||
|
|
||
| run_log "Test OPA service responds with 200" | ||
| responds_with_header \ | ||
| "HTTP/1.1 200 OK" \ | ||
| http://localhost:8000/service | ||
|
|
||
| run_log "Check OPA logs" | ||
| docker-compose logs ext_authz-opa-service | grep decision_id -A 30 | ||
|
|
||
| run_log "Check OPA service rejects POST" | ||
| responds_with_header \ | ||
| "HTTP/1.1 403 Forbidden" \ | ||
| -X POST \ | ||
| http://localhost:8000/service |
This file contains hidden or 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,59 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| export NAME=fault-injection | ||
|
|
||
| # shellcheck source=examples/verify-common.sh | ||
| . "$(dirname "${BASH_SOURCE[0]}")/../verify-common.sh" | ||
|
|
||
|
|
||
| run_log "Send requests for 20 seconds" | ||
| docker-compose exec -T envoy bash -c \ | ||
| "bash send_request.sh & export pid=\$! && sleep 20 && kill \$pid" \ | ||
| &> /dev/null | ||
|
|
||
| run_log "Check logs" | ||
| docker-compose logs | grep "HTTP/1.1\" 200" | ||
|
|
||
|
|
||
| _fault_injection_test () { | ||
| local action code existing_200s existing_codes | ||
| action="$1" | ||
| code="$2" | ||
| existing_codes=0 | ||
|
|
||
| # enable fault injection and check for http hits of type $code | ||
| existing_codes=$(docker-compose logs | grep -c "HTTP/1.1\" ${code}" || :) | ||
| run_log "Enable ${action} fault injection" | ||
| docker-compose exec -T envoy bash "enable_${action}_fault_injection.sh" | ||
| run_log "Send requests for 20 seconds" | ||
| docker-compose exec -T envoy bash -c \ | ||
| "bash send_request.sh & export pid=\$! && sleep 20 && kill \$pid" \ | ||
| &> /dev/null | ||
| run_log "Check logs again" | ||
| new_codes=$(docker-compose logs | grep -c "HTTP/1.1\" ${code}") | ||
| if [[ "$new_codes" -le "$existing_codes" ]]; then | ||
| echo "ERROR: expected to find new logs with response code $code" >&2 | ||
| return 1 | ||
phlax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| # disable fault injection and check for http hits of type 200 | ||
| existing_200s=$(docker-compose logs | grep -c "HTTP/1.1\" 200") | ||
| run_log "Disable ${action} fault injection" | ||
| docker-compose exec -T envoy bash "disable_${action}_fault_injection.sh" | ||
| run_log "Send requests for 20 seconds" | ||
| docker-compose exec -T envoy bash -c \ | ||
| "bash send_request.sh & export pid=\$! && sleep 20 && kill \$pid" \ | ||
| &> /dev/null | ||
| run_log "Check logs again" | ||
| new_200s=$(docker-compose logs | grep -c "HTTP/1.1\" 200") | ||
| if [[ "$new_200s" -le "$existing_200s" ]]; then | ||
| echo "ERROR: expected to find new logs with response code 200" >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| _fault_injection_test abort 503 | ||
| _fault_injection_test delay 200 | ||
|
|
||
| run_log "Check tree" | ||
| docker-compose exec -T envoy tree /srv/runtime | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.