description |
---|
How to use Heroku as your hosting solution for your Battlesnake, using one of the Starter Projects. |
- A free **** Battlesnake Account****
- A GitHub Account **** and Git Command Line****
- A free **** Heroku Account and Heroku Command Line****
These instructions assume you have already installed the Git Command Line and Heroku Command Line tools.
Choose from the complete list of Starter Projects. The Official Starter Projects have been tested and are maintained by the Battlesnake team.
For whichever Starter Project you choose, you will need to:
- Click the green 'Use This template' button (or if unavailable, make a fork of the repo).
- ****Clone your repository into your local environment. Run the following in the console on your computer with your own GitHub username, and the language for whichever starter project you selected:
git clone git@github.com:[YOUR-GITHUB-USERNAME]/starter-snake-[LANGUAGE].git
{% hint style="info" %}
If you are using a Community Starter Project, the name of the repository may be different, and might not start with starter-snake-LANGUAGE.
Check the project repository to confirm the correct name for your command!
{% endhint %}
To run your Battlesnake, Create a new Heroku App **** by running the following in the console on your local computer:
heroku create [YOUR-APP-NAME]
The first URL in the output will be the URL where your Battlesnake will be run. You will need this URL in Step 3 to Register your Battlesnake.
{% hint style="info" %} Check the Language Support Page if you are getting errors about versions when attempting to create or push your code to Heroku. {% endhint %}
Once created, you can deploy your Battlesnake code to Heroku by running the command:
git push heroku main
{% hint style="info" %}
If you are using a Community Starter Project, the mainline git branch might be different. Check the project repository to see if it is called main
, master
, or something else!
{% endhint %}
Now you can open your new Heroku app in your browser to see your Battlesnake running:
heroku open
If everything was successful, you should see response text that looks like this:
{"apiversion": "1", "author": "", "color": "#ff0000", "head": "default", "tail": "default"}
Optionally, you can view your server logs using the Heroku log command. The --tail
option will show a live feed of your logs in real-time.
heroku logs --tail
Using the URL from Step 2, follow the instructions to Register your Battlesnake on the Battlesnake website. With Heroku, that URL will look something like https://my-app-name.herokuapp.com/
where my-app-name is the name you used in Step 2.
Once your Battlesnake is registered, you should also follow the instructions to Create your First Game to test and verify that your Battlesnake is communicating successfully. Be sure to watch the logs of your server by running the heroku logs --tail
command.
As you make changes to your Battlesnake code, you will need to make sure those changes get onto Heroku.
After making a code change, commit that change using git and then push it to your Heroku instance:
git add .
git commit -m "Message describing the change"
git push heroku main
Once Heroku has updated, you can create a new game with your Battlesnake to view your latest changes in action.
Continue to make code changes and push those changes to your server using this pattern.