Skip to content

Instantly share code, notes, and snippets.

@lonelycode
Last active December 28, 2022 14:52
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lonelycode/4f645c4733faaa74d8fd to your computer and use it in GitHub Desktop.
Save lonelycode/4f645c4733faaa74d8fd to your computer and use it in GitHub Desktop.
Tyk Demo Setup Script
#! /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: $RANDOM_USER@test.com"
echo "Pass: $PASS"
echo ""
@aterhzaz
Copy link

I try to install tyk on my computer using this script but , its give me this errors :

Setting up Tyk dashboard
56cc2dc43afb9328a62727d4755caf130fcb2f8eff7b1ff3ff6d85ea617505b6
FATA[0005] Error response from daemon: Cannot start container 56cc2dc43afb9328a62727d4755caf130fcb2f8eff7b1ff3ff6d85ea617505b6: Cannot link to a non running container: /tyk_mongo AS /tyk_dashboard/mongo
Setting up NginX and Host Manager
b7e19e044129d3302e511701cf3394c181d7bc5e3c41d1b4c574435227f2c08c
FATA[0002] Error response from daemon: Cannot start container b7e19e044129d3302e511701cf3394c181d7bc5e3c41d1b4c574435227f2c08c: Cannot link to a non running container: /tyk_mongo AS /tyk_nginx/tyk_mongo
Creating Organisation
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/json/init.py", line 290, in load
*_kw)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
ORGID:
Adding new user
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/json/init.py", line 290, in load
*_kw)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
USER AUTH:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/json/init.py", line 290, in load
**kw)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
NEW ID:
Setting password

DONE

Login at http://127.0.0.1:3000/
User: koq6cvurzg@test.com
Pass: test123

@DavidTPate
Copy link

I hit the same issue, what it ended up being was that Mongo didn't have enough storage space allocated to it and it couldn't allocate the space needed for the journals.

Since I'm just trying this out I set the --smallfiles flag in the configuration file myself and things started to work. Check out this SO answer for how I got there.

@ywang-pivotal
Copy link

For Mac User, 127.0.0.1 is not the right IP. Just go and run "boot2docker ip" and copy that IP as a parameter to pass in when run ./ tyk_quickstart.sh. For my case, it is "./tyk_quickstart.sh 192.168.59.103".

@T3rm1
Copy link

T3rm1 commented Jul 15, 2015

Doesn't work with Python3. You have to replace the print statement with print function (in other words put the argument in braces)

@Rikhart
Copy link

Rikhart commented Jul 18, 2015

The first time that I installed worked like a charm, but then show me the same error, anyone solved that please ??

@lonelycode
Copy link
Author

@Rikhart what is the error?

@FrEaKmAn
Copy link

FrEaKmAn commented Sep 2, 2015

I'm still getting same problem as @aterhzaz

Edit: I added longer sleep and it works now. It seems 2 seconds is not enough time to load everything.

@yoanisgil
Copy link

@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 :(.

@yoanisgil
Copy link

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.

@lonelycode
Copy link
Author

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.

@ibcoleman
Copy link

ibcoleman commented Nov 11, 2016

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

@phoenixukltd
Copy link

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.

@ossvn
Copy link

ossvn commented May 21, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment