Skip to content

Commit

Permalink
Ensure settings exclusivity among deployments; add render settings/build
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbelesky committed Apr 16, 2022
1 parent 610c967 commit 5635c64
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

env:
## Environment variable
GITHUB_CI: true # Just 'CI' clashes with Render

steps:
- uses: actions/checkout@v2
- name: Cache node modules
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ django-summernote = "*"
dj-cmd = "*"
django-redis = "*"
django-cors-headers = "*"
psycopg2 = "*"
psycopg2-binary = "*"
asgiref = "*"
channels = "*"
channels-redis = "*"
Expand Down
79 changes: 62 additions & 17 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions bin/render-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# exit on error
set -o errexit

echo "-----> Install dependencies"
python -m pip install pipenv
pipenv install --system

echo "-----> I'm post-compile hook"
cd ./tabbycat/

echo "-----> Running database migration"
python manage.py migrate --noinput

echo "-----> Running dynamic preferences checks"
python manage.py checkpreferences

echo "-----> Running static asset compilation"
npm install -g @vue/cli-service-global
npm install
npm run build

echo "-----> Running static files compilation"
python manage.py collectstatic --noinput

echo "-----> Post-compile done"
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ formats too. If you're looking for a general overview of the software, check out
:maxdepth: 1
:caption: Installation

install/render
install/heroku
install/local
install/docker
Expand Down
45 changes: 45 additions & 0 deletions docs/install/render.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. _install-render:

====================
Installing on Render
====================

Render is a web hosting platform, similar to Heroku. Like Heroku, it provides a similar '1 click' method of deployment that should be approachable to people without experience in deploying web applications. Support for deploying Tabbycat to Render is currently **in beta**.

.. admonition:: Warning
:class: warning

The most important difference between Render and Heroku is that **after 90 days, Render's free-tier database will stop working and delete all your data**. If you want to keep your tab data around for the long term, you must backup your data and host it elsewhere after the tournament ends

Please also note:

- Although Tabbycat is setup to run within the free-tier of Render, you may need to add a credit card to your account in order to create your account
- While Render might run faster for small tournaments, we are unclear how well it runs at a larger scale and how best to employ Render's scaling tools

To deploy to Render, follow the instructions below.

1. Signup
=========

`Follow this link <https://dashboard.render.com/register?next=/>`_ and sign-up for the Render service. Login when finished, and navigate to your *Dashboard*.

2. Setup
========

.. image:: https://render.com/images/deploy-to-render-button.svg
:target: https://render.com/deploy?repo=https://github.com/TabbycatDebate/tabbycat/

Click the button above. Enter whatever you want as the **Service Group Name** and leave "Branch" as it is.

Then, enter your email and Time Zone in the fields. Time zones are formatted as per Heroku — copy of a "TZ database name" `from this list <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List>`_, e.g. *Europe/Copenhagen*.

Then, click "Apply" at the bottom of the page. The button will disappear.

Wait it a few minutes then go to your *Dashboard*. It may take up to 30 minutes for all items have a *STATUS* of "Deploy succeeded" or "Available" and you may need to refresh the page to see these updated status.

3. Login
========

When everything is successful/available, click through to the "Web Service" item on your Render Dashboard to see the URL of your site below the title. Open the URL to complete the normal Tabbycat admin account setup.

Note that this URL cannot be changed unless you `add a custom domain using a URL you already own <https://render.com/docs/custom-domains>`_.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Debating tabulation software for two-team parliamentary formats",
"scripts": {
"serve": "npm-run-all -p serve-*",
"serve-render": "npm-run-all -p render-*",
"build": "NODE_ENV='production' npm-run-all -p build-* cp-*",
"lint": "pre-commit run --all-files",
"build-sass": "npx node-sass --output-style compressed --include-path node_modules/ --output tabbycat/static/css/ tabbycat/templates/scss/style.scss",
Expand All @@ -19,7 +20,9 @@
"serve-sass": "npm run build-sass -- --watch --recursive --output-style expanded & npm run build-sass-print -- --watch --recursive --output-style expanded --sourcemap",
"serve-vue": "npx vue-cli-service serve",
"serve-worker": "dj runworker notifications adjallocation venues",
"windows-build": "SET NODE_ENV='production' & npm-run-all -p build-* cp-* && cpx \"tabbycat/static/vue/app.js\" \"tabbycat/static/vue/js/\""
"windows-build": "SET NODE_ENV='production' & npm-run-all -p build-* cp-* && cpx \"tabbycat/static/vue/app.js\" \"tabbycat/static/vue/js/\"",
"render-server": "python tabbycat/run-asgi.py",
"render-worker": "python manage.py runworker notifications adjallocation venues"
},
"dependencies": {
"@babel/cli": "^7.16.0",
Expand Down
48 changes: 48 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
databases:
- name: tabbycat_database
databaseName: tabbycat
user: tabbycat
plan: free

services:
- type: web
name: tabbycat_website
env: python
plan: free
region: oregon
buildCommand: "./bin/render-compile.sh"
startCommand: "npm run serve-render"
envVars:
- key: DATABASE_URL
fromDatabase:
name: tabbycat_database
property: connectionString
- key: REDIS_HOST
fromService:
type: redis
name: tabbycat_redis
property: host
- key: REDIS_PORT
fromService:
type: redis
name: tabbycat_redis
property: port
- key: DJANGO_SECRET_KEY
generateValue: true
- key: PYTHON_VERSION
value: "3.9.9"
- key: WEB_CONCURRENCY
value: 4
- key: TAB_DIRECTOR_EMAIL
sync: false
- key: TIME_ZONE
sync: false
- key: ON_RENDER
value: true
- type: redis
name: tabbycat_redis
ipAllowList: # required
- source: 0.0.0.0
description: everywhere
plan: free
maxmemoryPolicy: allkeys-lru # (default)
19 changes: 9 additions & 10 deletions tabbycat/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@

base_settings = [
'core.py',
optional('local.py'),
]

if os.environ.get('CI', '') == 'true':
if os.environ.get('GITHUB_CI', ''):
base_settings.append('github.py')

if os.environ.get('IN_DOCKER', '') and bool(int(os.environ['IN_DOCKER'])):
elif os.environ.get('IN_DOCKER', '') and bool(int(os.environ['IN_DOCKER'])):
base_settings.append('docker.py')

if os.environ.get('ON_HEROKU', ''):
elif os.environ.get('ON_HEROKU', ''):
base_settings.append('heroku.py')

if os.environ.get('LOCAL_DEVELOPMENT', ''):
base_settings.append('development.py')

elif os.environ.get('ON_RENDER', ''):
base_settings.append('render.py')
else:
base_settings.append('local.py')
if os.environ.get('LOCAL_DEVELOPMENT', ''):
base_settings.append('development.py')

include(*base_settings)
2 changes: 2 additions & 0 deletions tabbycat/settings/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import os

print("Imported docker settings")

ALLOWED_HOSTS = ["*"]

DATABASES = {
Expand Down
2 changes: 2 additions & 0 deletions tabbycat/settings/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Github CI
# ==============================================================================

print("Imported CI settings")

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
Expand Down
10 changes: 5 additions & 5 deletions tabbycat/settings/heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

from .core import TABBYCAT_VERSION

print("Imported heroku settings")

# ==============================================================================
# Heroku
# ==============================================================================

# Store Tab Director Emails for reporting purposes
if 'TAB_DIRECTOR_EMAIL' in environ:
TAB_DIRECTOR_EMAIL = environ.get('TAB_DIRECTOR_EMAIL', '')
if os.environ.get('TAB_DIRECTOR_EMAIL', ''):
TAB_DIRECTOR_EMAIL = environ.get('TAB_DIRECTOR_EMAIL')

# Get key from heroku config env else use a fall back
if environ.get('DJANGO_SECRET_KEY'):
SECRET_KEY = environ.get('DJANGO_SECRET_KEY')
if os.environ.get('DJANGO_SECRET_KEY', ''):
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')

# Allow all host headers
ALLOWED_HOSTS = ['*']
Expand Down
4 changes: 4 additions & 0 deletions tabbycat/settings/local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ON_LOCAL = True

print("Imported local settings")

# ==============================================================================
# Settings that you should specify
# ==============================================================================
Expand Down Expand Up @@ -34,6 +36,8 @@ SECRET_KEY = '#2q43u&tp4((4&m3i8v%w-6z6pp7m(v0-6@w@i!j5n)n15epwc'
# Django-specific Modules
# ==============================================================================

ALLOWED_HOSTS = ["*"]

INTERNAL_IPS = (
'0.0.0.0',
'127.0.0.1'
Expand Down
Loading

0 comments on commit 5635c64

Please sign in to comment.