-
Notifications
You must be signed in to change notification settings - Fork 9
Google Cloud AI Competition Setup
This is a quick tutorial on how to setup your own AI competition in 10 minutes with Google Cloud! It assumes some requirements and essentially lets you start up the Stations API on the google cloud instance so you can watch and view your competition as it runs.
Requirements: Google Cloud SDK, a Dimensions design you want to use, and a file to run a competition using the design (and some basic bots that will participate).
Here's the steps
- Login to https://console.cloud.google.com/. Sign up if you need to
- Create a new project and give it a name (like My AI Competition)
- Enter that new project and click
Create Instance
and give it a name and choose the machine type you want. Selectf1-micro
if you want to run this for free at no cost - In the firewall setting allow HTTP traffic.
- Click the create button
Login into your gcloud instance. You can click the ssh dropdown next to your instance on the vm instances dashboard and click view gcloud command to get the command to run to login into your instance. If you don't have the gcloud command line tools, see the following link: https://cloud.google.com/sdk/docs/quickstarts
Once logged into the instance, run the following commands to install the necessary files
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs
sudo apt install nginx
We need to make our tournament available for access on the web, so we need to edit our nginx configurations
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
sudo nano /etc/nginx/sites-available/ai.com
then paste the following into the editor
server {
listen [::]:80;
listen 80;
server_name ai.com www.ai.com;
location / {
proxy_pass http://localhost:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
We now need to link this configuration to enable it
sudo ln -s /etc/nginx/sites-available/ai.com /etc/nginx/sites-enabled/ai.com
Double check the nginx configuration is valid and restart nginx to start serving from localhost:9000 to the web
sudo nginx -t
sudo service nginx restart
Once pasted in, we can now get started with testing simple tournament.
Open up the command line on your computer and navigate to your competition design file (the file that has the design class that extends Dimensions.Design
) and a file that will run your competition. We will copy this over to our Google Cloud instance with the following command and replacing instance_name
with the name of your VM instance you made earlier.
gcloud compute scp design.js run.js instance_name:~/
If you have a folder you want to copy over, e.g a folder containing all the bot files, you can run
gcloud compute scp --recurse ./botsfolder instance_name:~/
To test now, back to the command line of the google cloud instance, go to your root folder by running cd
and then run
node run.js
Assuming your files worked locally, they should also work here. To find the link to examine the competition you are running, go back to your vm instances dashboard and copy the external IP of the vm instance you are working on. Then go to http://ip_address/api/dimensions/0
where you replace ip_address
with the external IP and test if you can see data related to the first dimension you created.
We will now install pm2 so it can run our tournament indefinitely on the Google cloud platform. So run
sudo npm install pm2@latest -g
Then at your root directory which is where you copied your files over to, run
pm2 start run.js
And congratulations! You can now go to the same IP address and view the API defined by the Stations API
For example, going to http://ip_address/api/dimensions/
gives you information on all the dimensions available and
http://ip_address/api/dimensions/<dimensions_id>/tournament/<tournament_id>/ranks
gives you information on the current rankings of the tournament with id tournament_id
being run.