Skip to content

jasharpe/taugame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

*** Requirements
Python 2.7 (for argparse module)
http://www.python.org/

Tornado Web Server
http://www.tornadoweb.org/

SQLAlchemy
http://www.sqlalchemy.org/

**** Install requirements with MacPorts

  sudo port install python27 py27-tornado py27-sqlalchemy

*** Running

Before running the first time, to set up necessary files run:

  python2.7 setup.py

Then edit secrets.py to add the missing fields.

Then, to run locally for development:

  sudo python2.7 tau.py --debug --port=8000 --ssl_port=8001

To build and run with Docker (experimental):

  docker build -t websockettau . && docker run --rm -p 8000:8000 -p 8001:8001 websockettau

To avoid having to rebuild the docker container on every change, you can run from your work directory:

  docker run --rm -p 8000:8000 -p 8001:8001 -v $PWD:/live -w /live websockettau

To run against a test version of a mysql db:

  docker run --rm -p 8000:8000 -p 8001:8001 -v $PWD:/live -w /live -e db=mysql -e mysql_password=$MYSQL_PASSWORD -e mysql_addr=$LOCAL_IP_FROM_IFCONFIG:3306 -e db_name=tau_game_2 websockettau python ./tau.py --debug --port=8000

Connect to actual mysql for testing by running the proxy:

  curl -o cloud_sql_proxy https://dl.google.com/cloudsql/cloud_sql_proxy.darwin.amd64
  ./cloud_sql_proxy -instances=tau-game:us-central1:tau-game-db=tcp:0.0.0.0:3306

Root access is required to bind to port 80 which is the default, so using ports 8000 and 8001 avoids this. The --debug flag allows the use of ^C to kill the server (very handy for restarting it during development).

For other options, type:

  python2.7 tau.py --help

*** Adding a new game type (as of July 15, 2012)
- Implement the rules in game.py.
- Add a name mapping to static/game_list.js.
- Add a name mapping and URL mapping to tau.py.
- Add a name mapping to constants.py.
- Add a rules description and name mapping to templates/about.html.
- (Sometimes applicable) Add changes to playing area in static/tau.js.
- (If adding new cards) Make the following updates:
    static/tau.js: getImgClass(), get_card_number()
    static/styles.css: new class similar to .regularTau, .projectiveTau, etc.

How to set up Fedora 16 server:
$ ssh root@...
$ passwd # to set password to something sane
$ yum install git
$ yum install python
$ yum install gcc-c++
$ git clone https://github.com/jasharpe/websockettau.git
# install tornado
$ wget https://pypi.python.org/packages/source/t/tornado/tornado-4.0.2.tar.gz
$ tar xvzf tornado-4.0.2.tar.gz
$ cd tornado-4.0.2
$ python setup.py build
$ sudo python setup.py install
# install backports
$ cd ~ && wget https://pypi.python.org/packages/source/b/backports.ssl_match_hostname/backports.ssl_match_hostname-3.4.0.2.tar.gz
$ tar -zxvf backports.ssl_match_hostname-3.4.0.2.tar.gz
$ cd backports.ssl_match_hostname-3.4.0.2
$ python setup.py install
# install pip
$ sudo yum install python-pip
# install certifi
$ pip-python install certifi
# install sqlalchemy
$ yum install python-sqlalchemy
# create secrets.py
# Get google client id and secret from https://console.developers.google.com/project/apps~tau-game/apiui/credential
$ cd ~/websockettau && cat > secrets.py
cookie_secret = "SOME STRING HERE"
client_id = "GOOGLE CLIENT ID"
client_secret = "GOOGLE CLIENT SECRET"
# Set up certificates by creating localhost.crt certificate, and put in websockettau directory.
# Open ports, add to /etc/sysconfig/iptables:
# -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
$ ./restart.sh

# Set up ntp, so that time stays up to date (otherwise backups will fail when the clock skew gets too high!)
$ yum install ntp
$ ntpd

# setup automatic backups to S3
$ yum install s3cmd
$ s3cmd --configure
# follow the prompts...
# test that backups will work properly
$ ./run_backup
# verify that the backup appears in S3
# set up automatic backups. s3_crontab is a template. Modify it to suit you.
$ crontab s3_crontab

### How to set up GCP instance

1. Create GCP project.

2. Upload Docker image to GCR (called `gcr.io/$PROJECT/websockettau`). Probably requires enabling the GCR API:

```
docker build -t gcr.io/tau-game/websockettau .
docker push gcr.io/tau-game/websockettau
```

3. Enable Stackdriver Logging API.

4. Create a GCP instance that runs the container uploaded (or do via the UI), and populates the environment variables needed by db.py.