-
-
Save lonelycode/4f645c4733faaa74d8fd to your computer and use it in GitHub Desktop.
#! /bin/bash | |
# This script will set up a full tyk environment on your machine | |
# and also create a demo user for you with one command | |
# USAGE | |
# ----- | |
# | |
# $> ./tyk_quickstart.sh {IP ADDRESS OF DOCKER VM} | |
# OSX users will need to specify a virtual IP, linux users can use 127.0.0.1 | |
if [ -z "$1" ] | |
then | |
echo "Please specify the docker IP Address (e.g. ./quickstart 127.0.0.1)" | |
exit | |
fi | |
LOCALIP=$1 | |
RANDOM_USER=$(env LC_CTYPE=C tr -dc "a-z0-9" < /dev/urandom | head -c 10) | |
PASS="test123" | |
echo "Clean up (ignore any errors)" | |
docker stop tyk_mongo && docker rm tyk_mongo | |
docker stop tyk_redis && docker rm tyk_redis | |
docker stop tyk_nginx && docker rm tyk_nginx | |
docker stop tyk_dashboard && docker rm tyk_dashboard | |
docker stop tyk_gateway && docker rm tyk_gateway | |
echo "Pulling latest containers" | |
docker pull redis:latest | |
docker pull mongo:latest | |
docker pull tykio/tyk-gateway:latest | |
docker pull tykio/tyk-dashboard:latest | |
docker pull tykio/tyk-host-manager:latest | |
echo "Setting up Mongo and Redis" | |
docker run -d --name tyk_redis redis | |
docker run -d --name tyk_mongo mongo --smallfiles | |
echo "Setting up Tyk gateway" | |
docker run -d --name tyk_gateway -p 8080:8080 --link tyk_redis:redis --link tyk_mongo:mongo tykio/tyk-gateway | |
echo "Setting up Tyk dashboard" | |
docker run -d --name tyk_dashboard -p 3000:3000 --link tyk_redis:redis --link tyk_mongo:mongo --link tyk_gateway:tyk_gateway tykio/tyk-dashboard | |
echo "Setting up NginX and Host Manager" | |
docker run -d --name tyk_nginx -p 8888:80 --link tyk_gateway:tyk_gateway --link tyk_dashboard:tyk_dashboard --link tyk_mongo:tyk_mongo --link tyk_redis:tyk_redis -e DOMAINALIAS=tyk.docker tykio/tyk-host-manager | |
sleep 2 | |
echo "Creating Organisation" | |
ORGDATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"owner_name": "TestOrg5 Ltd.","owner_slug": "testorg"}' http://$LOCALIP:3000/admin/organisations 2>&1) | |
#echo $ORGDATA | |
ORGID=$(echo $ORGDATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Meta"]') | |
echo "ORGID: $ORGID" | |
echo "Adding new user" | |
USER_DATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"first_name": "John","last_name": "Smith","email_address": "'$RANDOM_USER'@test.com","active": true,"org_id": "'$ORGID'"}' http://$LOCALIP:3000/admin/users 2>&1) | |
#echo $USER_DATA | |
USER_CODE=$(echo $USER_DATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Message"]') | |
echo "USER AUTH: $USER_CODE" | |
USER_LIST=$(curl --silent --header "authorization: $USER_CODE" http://$LOCALIP:3000/api/users 2>&1) | |
#echo $USER_LIST | |
USER_ID=$(echo $USER_LIST | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["users"][0]["id"]') | |
echo "NEW ID: $USER_ID" | |
echo "Setting password" | |
OK=$(curl --silent --header "authorization: $USER_CODE" --header "Content-Type:application/json" http://$LOCALIP:3000/api/users/$USER_ID/actions/reset --data '{"new_password":"'$PASS'"}') | |
echo "" | |
echo "DONE" | |
echo "====" | |
echo "Login at http://$LOCALIP:3000/" | |
echo "User: [email protected]" | |
echo "Pass: $PASS" | |
echo "" |
I have now created a github project to setup Tyk more easily:
https://github.com/yoanisgil/tyk_quickstart
Have not tested thoroughly but feedback is appreciated.
We have forked @yoanisgil 's version and updated with a cleverer setup script that doesn't require the host address to be present (PR sent btw, so they can be up-to-date).
We recommend everyone to use the new docker compose method, our version is here: https://github.com/lonelycode/tyk_quickstart and it should be used in conjunction with our docker quickstart docs on the tyk.io site.
I'm getting the exact same issue as @aterhzaz. "ValueError: No JSON object could be decoded"
I'm using the new docker compose quickstart method and the instructions from tyk.io.
UPDATE: Sorry, this was an selinux issue: https://stackoverflow.com/questions/24288616/permission-denied-on-accessing-host-directory-in-docker
Just a quick not one this.
If you are setting up on AWS using an EC2 install check that the port you used during setup (in my case 5000) is open to traffic from 0.0.0.0/0 or at least the security group to which that server belongs.
That solved this rather quickly.
Hello,
I have installed the Tyk-gateway and Dashboard successfully.
But I'm wondering how can I do something like this?
- Tyk-gateway run at domain.net:80
- Tyk-dashboard run at developer.domain.net
In the script above, I couldn't set my dashboard and gateway port and domain.
Thank you!
@FrEaKmAn problem very likely is with the sleep instruction. Try increasing sleep time to 30 seconds and see if that works for you. Problem is that if the server running on port 3000 is not fully up by the time the first curl call is made, then everything else fails ;). I will try to put together a docker-compose for this as I am sure many has been hit by this and worst is in the official documentation :(.