Skip to content

Commit

Permalink
chore: polish readme, update settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Viitala committed Dec 18, 2023
1 parent 4c49eb4 commit c35f1e6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
context: ./.
file: ./Dockerfile
push: true
tags: ${{env.REGISTRY}}:${{github.run_number}}
tags: ${{env.REGISTRY}}:${{github.run_number}}, ${{env.REGISTRY}}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ RUN apt-get -y purge gcc libc-dev python3-dev
# Add all application code from this folder, including deployment entrypoints
COPY --chown=python:python ./ /app

# Create staticfiles folder
RUN mkdir -p staticfiles && \
chown -R python:python staticfiles

# Make entrypoints executable
RUN chmod +x /app/deployment/server-entrypoint.sh && \
chmod +x /app/deployment/worker-entrypoint.sh
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# `railway_django_stack`

<!-- BUTTON HERE -->
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/NBR_V3?referralCode=6rOei9)

Full Django/Postgres stack with Celery tasks and Redis as cache/queue.

## Overview

WIP

## Deploying the template

1. In the deployment screen, you will need to configure a `DJANGO_SECRET_KEY`. You can use the below snippet to do that or otherwise generate your own.
<details>
<summary>Snippet to create secret</summary>

**This assumes your default python installation has Django installed.**

```bash
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
```

</details>
1. Once the containers have been deployed, please take the following steps to delete public proxy addresses, as you will not need to access the private services directly:
- Go to the **Postgres** service > Settings > Networking, delete the proxy
- Go to the **Redis** service > Settings > Networking, delete the proxy

## Resources

Expand Down Expand Up @@ -55,14 +78,5 @@ This is a barebones Django-project with the following additions/updates:
- [`django-celery-beat`](https://github.com/celery/django-celery-beat) for periodic task management
- [`django-celery-results`](https://github.com/celery/django-celery-results) for viewing results of Celery tasks in Django Admin
- Uses [`python-decouple`](https://github.com/HBNetwork/python-decouple) to manage settings via environment varialbes
- Uses [`whitenoise`](https://github.com/evansd/whitenoise) to make serving static assets easy
- Installs and runs with [`gunicorn`](https://github.com/benoitc/gunicorn)

## Variable configurations

| Variable | Description | Used by |
| -------- | ----------- | ------- |
`POSTGRES_HOST` | This should be the private URL of the Postgres service | Django, Celery
`POSTGRES_DB` | Sets the Postgres default database name | Django, Celery, Postgres
`POSTGRES_USER` | Sets the Postgres username | Django, Celery, Postgres
`POSTGRES_PASSWORD` | Sets the Postgres user's password | Django, Celery, Postgres
`REDIS_URL` | Configures the private URl of the Redis service | Django, Celery |
3 changes: 3 additions & 0 deletions deployment/server-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

echo "Collecting static files.."
python manage.py collectstatic --noinput

if [ "$RUN_MIGRATIONS" = "True" ]; then
echo "Running migrations..."
until python manage.py migrate
Expand Down
6 changes: 5 additions & 1 deletion railway_django_stack/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
import os

from decouple import config

Expand All @@ -24,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config("DEBUG", default=False, cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]


# Application definition
Expand All @@ -49,6 +50,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
]

ROOT_URLCONF = "railway_django_stack.urls"
Expand Down Expand Up @@ -136,6 +138,8 @@
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ django-celery-results==2.5.1
gunicorn==21.2.0
psycopg[binary]==3.1.15
python-decouple==3.8
redis==5.0.1
redis==5.0.1
whitenoise==6.6.0
Empty file added static/.gitkeep
Empty file.

0 comments on commit c35f1e6

Please sign in to comment.