Created
January 26, 2019 09:37
-
-
Save asoorm/d83ec542a843996c573a00b77dce5ac5 to your computer and use it in GitHub Desktop.
tyk gateway simple bench script
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
sudo systemctl enable docker | |
docker network create tyk | |
docker run -itd --name redis --restart on-failure --network tyk redis:5.0-alpine | |
# this is the upstream server that tyk will reverse proxy to | |
docker run -itd --name nginx --restart on-failure --network tyk nginx:1.15.8-alpine | |
mkdir apidefs | |
cat > apidefs/keyless.json <<- EOF | |
{ | |
"name": "keyless", | |
"api_id": "keyless", | |
"org_id": "default", | |
"definition": { | |
"location": "", | |
"key": "" | |
}, | |
"use_keyless": true, | |
"auth": { | |
"auth_header_name": "" | |
}, | |
"version_data": { | |
"not_versioned": true, | |
"versions": { | |
"Default": { | |
"name": "Default", | |
"expires": "3000-01-02 15:04", | |
"use_extended_paths": true, | |
"extended_paths": { | |
"ignored": [], | |
"white_list": [], | |
"black_list": [] | |
} | |
} | |
} | |
}, | |
"proxy": { | |
"listen_path": "/nginx/", | |
"target_url": "http://nginx/", | |
"strip_listen_path": true | |
}, | |
"do_not_track": true | |
} | |
EOF | |
cat > apidefs/bearer_token.json <<- EOF | |
{ | |
"name": "bearer_token", | |
"api_id": "bearer_token", | |
"org_id": "default", | |
"definition": { | |
"location": "", | |
"key": "" | |
}, | |
"use_keyless": false, | |
"auth": { | |
"auth_header_name": "Authorization" | |
}, | |
"version_data": { | |
"not_versioned": true, | |
"versions": { | |
"Default": { | |
"name": "Default", | |
"expires": "3000-01-02 15:04", | |
"use_extended_paths": true, | |
"extended_paths": { | |
"ignored": [], | |
"white_list": [], | |
"black_list": [] | |
} | |
} | |
} | |
}, | |
"proxy": { | |
"listen_path": "/bearer_token/", | |
"target_url": "http://nginx/", | |
"strip_listen_path": true | |
}, | |
"do_not_track": true, | |
"disable_rate_limit": true | |
} | |
EOF | |
cat > apidefs/static.json <<- EOF | |
{ | |
"name": "static", | |
"api_id": "static", | |
"org_id": "default", | |
"definition": { | |
"location": "", | |
"key": "" | |
}, | |
"use_keyless": true, | |
"auth": { | |
"auth_header_name": "" | |
}, | |
"version_data": { | |
"not_versioned": true, | |
"versions": { | |
"Default": { | |
"name": "Default", | |
"expires": "3000-01-02 15:04", | |
"use_extended_paths": true, | |
"extended_paths": { | |
"white_list": [ | |
{ | |
"path": "nginx", | |
"method_actions": { | |
"GET": { | |
"action": "reply", | |
"code": 200, | |
"data": "<!DOCTYPE html>\n<html>\n<head>\n<title>Welcome to nginx!</title>\n<style>\n body {\n width: 35em;\n margin: 0 auto;\n font-family: Tahoma, Verdana, Arial, sans-serif;\n }\n</style>\n</head>\n<body>\n<h1>Welcome to nginx!</h1>\n<p>If you see this page, the nginx web server is successfully installed and\nworking. Further configuration is required.</p>\n\n<p>For online documentation and support please refer to\n<a href=\"http://nginx.org/\">nginx.org</a>.<br/>\nCommercial support is available at\n<a href=\"http://nginx.com/\">nginx.com</a>.</p>\n\n<p><em>Thank you for using nginx.</em></p>\n</body>\n</html>", | |
"headers": { | |
"Content-Type": "text/html" | |
} | |
} | |
} | |
} | |
] | |
}, | |
"black_list": [ | |
] | |
} | |
} | |
}, | |
"proxy": { | |
"listen_path": "/static_auth/", | |
"target_url": "http://nginx/", | |
"strip_listen_path": true | |
}, | |
"do_not_track": true | |
} | |
EOF | |
cat > key.json <<- EOF | |
{ | |
"allowance": 1000, | |
"rate": 1000, | |
"per": 60, | |
"expires": -1, | |
"quota_max": -1, | |
"quota_renews": 1406121006, | |
"quota_remaining": 0, | |
"quota_renewal_rate": 60, | |
"access_rights": { | |
"bearer_token": { | |
"api_name": "Versioned API", | |
"api_id": "bearer_token", | |
"versions": [ | |
"Default" | |
] | |
} | |
}, | |
"org_id": "default" | |
} | |
EOF | |
docker run -itd --rm --name gateway \ | |
-e TYK_GW_COPROCESSOPTIONS_ENABLECOPROCESS=false \ | |
-e TYK_GW_ENABLEANALYTICS=false \ | |
-e TYK_GW_HASHKEYS=false \ | |
-p 8080:8080 \ | |
-v $(pwd)/apidefs:/opt/tyk-gateway/apps \ | |
--network | |
tyk tykio/tyk-gateway:v2.7.5 | |
# hacky way to check gateway is up | |
sleep 10 | |
curl -X POST localhost:8080/tyk/keys/mykey \ | |
-H 'x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7' \ | |
-d @key.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment