-
Notifications
You must be signed in to change notification settings - Fork 2
Cloud Hosting on Heroku
This guide is designed for hosting the bot on Heroku. Instructions will vary depending on platform, check your service's documentation for more details.
Sign into your Heroku account, and create a new app with the name of your choice.
The below steps are for programs running 1.x.x. If you are using version 2.0.0 or higher, skip this section.
Once your app is created, you will need to configure your environment/config variables. To do so, follow these steps:
- Using this section, open up and view your environment variables.
- In a browser, pen the Settings tab of your Heroku app.
- Click Reveal config vars.
- In the text box titled
KEY, enter the title of your environment/config variable, such asAPIKEY. - In the text box titled
VALUE, enter the value of your environment/config variable. (This step is necessary as Heroku can't read it off your computer.) - Click Add.
- Repeat steps 4-6 for each variable.
Instructions for all users continue here.
Then, install and sign into the Heroku CLI. Add Heroku's remote git server to your repository by opening the command line in the folder containing your bot, and running heroku git:remote -a yourappname, where yourappname is the name of the app you chose on Heroku.
The following instructions are for uses on versions version 2.0.0 or higher. Users of version 1.x.x should skip to the next section.
Since your config.yaml file is not included in your repository (due to its inclusion in the .gitignore file), it will not be uploaded to Heroku with your program, and cannot be called by Heroku to access the Twitter API. The recommended method for Heroku is to use environment variables, but manually adding these values is a tedious process. To solve this, the XKCDAltTextBot repository includes a smaller Python file that uses the command line/terminal to load your config file values into Heroku's environment variables.
To load the config file, run the following command inside the Twitter bot's folder:
python setup_heroku.py
That's all. Just watch the program load in all of your environment variables, and once it finishes continue with setup below.
Now, you'll push your bot to Heroku. After committing any changes, run git push heroku master. A series of messages will detail the upload and preparation of the app. A few special cases:
- If you need to push a different branch, use the command
git push heroku mybranch:master, wheremybranchis the name of the branch you are pushing. - If Heroku will not accept the version you are pushing (for example, an older version or due to a conflict), you can force Heroku to use it by running
git push heroku master --force, replacingmasteras necessary. Be careful with this command, it will overwrite everything.
Finally, initiate the bot by running heroku ps:scale worker=1. Now your Twitter bot is active!
Heroku by itself does not offer any error alerts or log management, besides some basic features. It is recommended you use a log retention service to receive notifications if your bot crashes. The standard pattern for log error messages from the bot is Entering log protection mode.
If you ever need to shut down the bot, you can do this in the Heroku web interface or with the command heroku ps:scale worker=0.
Your bot is now fully operational. If you'd like to contribute to the project, check out the next page.
← Running Your Bot // Forking and Contributing to XKCDAltTextBot →