Skip to content

Commit

Permalink
Merge pull request #2362 from CreatedBySeb/bug/fix-heroku-deploy
Browse files Browse the repository at this point in the history
Fix miscellaneous issues with deploy_heroku.py
  • Loading branch information
tienne-B committed Nov 16, 2023
2 parents 999df8c + eeb0d84 commit 62d4de5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
19 changes: 16 additions & 3 deletions deploy_heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import subprocess
import sys
import time

try:
from django.core.management.utils import get_random_secret_key
Expand Down Expand Up @@ -42,8 +43,8 @@ def get_random_secret_key():
help="Heroku Postgres plan (default mini)")

parser.add_argument(
"--web-dynos", type=str, default="1:eco",
help="Web dyno specification, passed to heroku ps:scale web=[], e.g. 1:eco, 1:hobby, 2:Standard-1X")
"--web-dynos", type=str, default="1",
help="Web dyno specification, passed to heroku ps:scale web=[], e.g. 1:eco, 1:basic, 2:Standard-1X")

parser.add_argument(
"--import-tournament", type=str, metavar="IMPORT_DIR",
Expand Down Expand Up @@ -165,7 +166,7 @@ def get_git_push_spec():
if args.urlname != "-":
command.append(args.urlname)
output = get_output_from_command(command)
match = re.search(r"https://([\w_-]+)\.herokuapp\.com/\s+\|\s+(https://git.heroku.com/[\w_-]+.git)", output)
match = re.search(r"https://([\w_-]+?)(?:-\w{12})?\.herokuapp\.com/\s+\|\s+(https://git.heroku.com/[\w_-]+.git)", output)
urlname = match.group(1)
heroku_url = match.group(2)

Expand Down Expand Up @@ -207,6 +208,18 @@ def get_git_push_spec():
else:
remote_name = heroku_url

# Wait for Redis provisioning, which can take a significant amount of time
redis_provisioned = False
redis_status_command = make_heroku_command(["redis:info"])
print_yellow("Waiting for Heroku Redis to provision (may take up to 5 minutes)...")

while not redis_provisioned:
time.sleep(30)
redis_output = subprocess.check_output(redis_status_command).decode().split("\n")
redis_provisioned = "available" in redis_output[2]

print("Heroku Redis is available, starting deployment")

# Push source code to Heroku
push_spec = get_git_push_spec()
run_command(["git", "push", remote_name, push_spec])
Expand Down
30 changes: 18 additions & 12 deletions docs/install/heroku.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Account Setup

`Heroku <http://www.heroku.com/>`_ is a platform as a service on which Tabbycat can be installed to be available on the internet. Naturally, this requires you to have a Heroku account. Head to the site and sign-up for one.

.. note:: During the setup process, Heroku will ask you to verify your account by adding a credit card. A standard Tabbycat site *will not charge* your card — charges only accrue if you deliberately add a paid service in the Heroku dashboard.
.. note:: During the setup process, Heroku will ask you to verify your account by adding a credit card. A standard Tabbycat site *may charge* your card. If you have a paid Heroku Eco plan Tabbycat will use your Eco hours and you will not be charged, otherwise Tabbycat will use 2 Basic dynos which cost roughly $0.25/day or $7/month each.

1. Install dependencies
-----------------------
Expand All @@ -101,12 +101,16 @@ a. Navigate on the command-line your Tabbycat directory. If you have not changed

cd tabbycat

b. Run the script to deploy the app to Heroku. Replace ``yourappname`` with your preferred URL. Your website will be at ``yourappname.herokuapp.com``.
b. Run the script to deploy the app to Heroku. Replace ``yourappname`` with your preferred URL. Your website will be at ``yourappname-suffix.herokuapp.com``.

.. warning:: On June 14th, 2023, Heroku started appending 12-character random suffixes to subdomains to prevent domain takeover when an app is renamed or deleted. Tabs created before this point will keep their ``yourappname.herokuapp.com`` domain, but new tabs will have the random suffix after ``yourappname``.

::

python deploy_heroku.py yourappname

The script uses the default dyno type for your Heroku account. If you have a paid Heroku Eco plan, the script will use Eco dynos. If you do not have an Eco plan, it will use Basic dynos which are billed based on usage. You can use the ``--web-dynos`` option to use a specific type, such as ``--web-dynos 1:basic`` if you have an Eco plan but wish to use Basic dynos.

This script has other options that you might find useful. Run ``python deploy_heroku.py --help`` for details.

The script may work away on its own for 10-30 minutes before it asks you some questions to answer. When finished, it will open the app in your browser. It should look something like this:
Expand All @@ -122,6 +126,8 @@ TLDR commands

.. warning:: We provide a "short version" for experienced users. Don't just copy and paste these commands before you understand what they do! If things aren't set up perfectly they can fail, so it's important to supervise them the first time you do them. If this is all new to you, read the long version of the instructions below.

The script uses the default dyno type for your Heroku account. If you have a paid Heroku Eco plan, the script will use Eco dynos. If you do not have an Eco plan, it will use Basic dynos which are billed based on usage. You can use the ``--web-dynos`` option with the last command to use a specific type, such as ``--web-dynos 1:basic`` if you have an Eco plan but wish to use Basic dynos.

.. parsed-literal::
git clone https://github.com/TabbycatDebate/tabbycat.git
Expand All @@ -139,20 +145,20 @@ If you have a large tournament, you may want to customize your Heroku app. This
Upgrading your database size
----------------------------

The free plan of `Heroku Postgres <https://elements.heroku.com/addons/heroku-postgresql>`_, "Hobby Dev", should work for most small tournaments. For large tournaments, however, you may find that you exceed the 10,000-row limit of this plan. It's difficult to give general guidance on how many rows you're likely to use, because it depends on which features of Tabbycat you use (*e.g.*, if you use adjudicator feedback). But to give some idea:
The Mini plan of `Heroku Postgres <https://elements.heroku.com/addons/heroku-postgresql>`_, should work for most small tournaments. For large tournaments, however, you may find that you exceed the 10,000-row limit of this plan. It's difficult to give general guidance on how many rows you're likely to use, because it depends on which features of Tabbycat you use (*e.g.*, if you use adjudicator feedback). But to give some idea:

- Australs 2016, which had 74 teams, 8 preliminary rounds and heavily used adjudicator feedback, ended up at around 30,000 rows.
- The Asia BP championships 2017 had 100 teams, 6 preliminary rounds, and mandatory feedback (i.e. 100% return rates) used 15,000 rows.
- A 3 vs 3 tournament with 54 teams, 5 preliminary rounds, and which only lightly used adjudicator feedback ended up using around 4,500 rows

If you need more than 10,000 rows, you'll need to upgrade to a paid Heroku Postgres Plan. The 10,000,000 rows allowed in the lowest paid plan, "Hobby Basic", should certainly be more than sufficient.
If you need more than 10,000 rows, you'll need to upgrade to a larger Heroku Postgres Plan. The 10,000,000 rows allowed in the lowest paid plan, "Basic", should certainly be more than sufficient.

If you're not sure, you can always start at Hobby Dev—just be prepared to `upgrade <https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups>`_ during the tournament if you run close to capacity.
If you're not sure, you can always start at Mini—just be prepared to `upgrade <https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups>`_ during the tournament if you run close to capacity.

Custom domain names
-------------------

Your Heroku app will be available at ``yourappname.herokuapp.com``. You may want it to be a subdomain of your tournament's website, like ``tab.australasians2015.org``. If so, you'll need to configure your custom domain and SSL. Instructions for both are in the Heroku Dev Center:
Your Heroku app will be available at ``yourappname-suffix.herokuapp.com``. You may want it to be a subdomain of your tournament's website, like ``tab.australasians2015.org``. If so, you'll need to configure your custom domain and SSL. Instructions for both are in the Heroku Dev Center:

- `Custom Domain Names for Apps <https://devcenter.heroku.com/articles/custom-domains>`_
- `Heroku SSL <https://devcenter.heroku.com/articles/ssl>`_
Expand Down Expand Up @@ -215,17 +221,17 @@ You'll need both Git and the Heroku CLI, and you'll need to be logged in to the
3. Check to see if you have a Git remote already in place::

$ git remote -v
heroku https://git.heroku.com/mytournament2018.git (fetch)
heroku https://git.heroku.com/mytournament2018.git (push)
heroku https://git.heroku.com/yourappname.git (fetch)
heroku https://git.heroku.com/yourappname.git (push)

If you do, the name of the remote will be on the left (``heroku`` in the above example), and the URL of your Git repository will be on the right. In the example above, our Tabbycat site URL would be ``mytournament2018.herokuapp.com``; the Git remote URL is then ``https://git.heroku.com/mytournament2018.git``.
If you do, the name of the remote will be on the left (``heroku`` in the above example), and the URL of your Git repository will be on the right. In the example above, our Tabbycat site URL would be ``yourappname-suffix.herokuapp.com``; the Git remote URL is then ``https://git.heroku.com/yourappname.git``.

If a Git remote URL for your Tabbycat site *doesn't* appear, then create one::

$ heroku git:remote --app mytournament2018 --remote heroku
set git remote heroku to https://git.heroku.com/mytournament2018.git
$ heroku git:remote --app yourappname --remote heroku
set git remote heroku to https://git.heroku.com/yourappname.git

.. tip:: If you tab many tournaments, it'll probably be helpful to use a name other than ``heroku`` (say, ``mytournament2018``), so that you can manage multiple tournaments.
.. tip:: If you tab many tournaments, it'll probably be helpful to use a name other than ``heroku`` (say, ``yourappname``), so that you can manage multiple tournaments.

4. Push to Heroku::

Expand Down

0 comments on commit 62d4de5

Please sign in to comment.