More production updates/fixes #97

Merged
mattn merged 3 commits from matt/prod into main 2023-03-29 16:42:44 +13:00
11 changed files with 71 additions and 26 deletions

View file

@ -1,3 +1,4 @@
__pycache__/ __pycache__/
staticfiles/ staticfiles/
media/
*.pyc *.pyc

View file

@ -7,10 +7,12 @@ RUN apt update \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& apt clean && apt clean
COPY ./requirements.txt /app/requirements.txt
RUN pip install -U --no-cache-dir -r requirements.txt
COPY . /app COPY . /app
RUN pip install -U --no-cache-dir -r requirements.txt && \
useradd -Mu 1000 righttree && \
chown -R righttree:righttree /app
ENV DJANGO_SETTINGS_MODULE="right_tree.settings" ENV DJANGO_SETTINGS_MODULE="right_tree.settings"
USER righttree

View file

@ -8,6 +8,6 @@ gunicorn==20.1.0
pandas==1.5.3 pandas==1.5.3
pdfkit==1.0.0 pdfkit==1.0.0
PyPDF2==1.28.6 PyPDF2==1.28.6
redis==4.5.1 redis==4.5.3
celery[redis]==5.2.7 celery[redis]==5.2.7
stripe==5.2.0 stripe==5.2.0

View file

@ -0,0 +1,3 @@
from .celery import app as celery_app
__all__ = ("celery_app",)

View file

@ -1,5 +1,10 @@
import os
from celery import Celery from celery import Celery
app = Celery('righttree')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'right_tree.settings')
app = Celery('right_tree')
app.config_from_object('django.conf:settings', namespace='CELERY') app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks() app.autodiscover_tasks()

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.17 on 2023-03-29 03:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0015_auto_20230306_1620'),
]
operations = [
migrations.AlterField(
model_name='activationkey',
name='key_set',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.activationkeyset'),
),
]

View file

@ -222,7 +222,7 @@ class ActivationKey(models.Model):
) )
key = models.CharField(max_length=20, unique=True, default=key_default) key = models.CharField(max_length=20, unique=True, default=key_default)
key_set = models.ForeignKey(ActivationKeySet, on_delete=models.CASCADE, null=True) key_set = models.ForeignKey(ActivationKeySet, on_delete=models.PROTECT, null=True)
remaining_activations = models.SmallIntegerField(default=1) remaining_activations = models.SmallIntegerField(default=1)
creation_date = models.DateTimeField(auto_now_add=True) creation_date = models.DateTimeField(auto_now_add=True)

View file

@ -239,7 +239,7 @@ def purchase_key(request):
invoice_creation={ invoice_creation={
'enabled': True, 'enabled': True,
'invoice_data': { 'invoice_data': {
'description': f'Your product code is {key}', 'description': f'Your activation key is {key}',
'rendering_options': {'amount_tax_display': 'include_inclusive_tax'}, 'rendering_options': {'amount_tax_display': 'include_inclusive_tax'},
'footer': 'BioSphere Capital Limited', 'footer': 'BioSphere Capital Limited',
}, },

View file

@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
""" """
import os import os
import stripe
from pathlib import Path from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.

View file

@ -6,11 +6,6 @@ volumes:
x-django: &django x-django: &django
image: right-tree image: right-tree
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
env_file: .env env_file: .env
user: "$UID:$GID" user: "$UID:$GID"
restart: always restart: always
@ -25,6 +20,13 @@ services:
- gunicorn - gunicorn
- --bind=0.0.0.0:8000 - --bind=0.0.0.0:8000
- right_tree.wsgi - right_tree.wsgi
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
celery:
condition: service_healthy
nginx: nginx:
container_name: nginx container_name: nginx
@ -54,13 +56,13 @@ services:
- POSTGRES_USER=${POSTGRES_USER} - POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
healthcheck: healthcheck:
test: ["CMD", "pg_isready", "--dbname", "righttree", "--username", "righttree"] test: ["CMD", "pg_isready", "--dbname", "$DATABASE_NAME", "--username", "$DATABASE_USER"]
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5
redis: redis:
image: redis:7.0.8 image: redis:7.0.10
restart: always restart: always
container_name: redis container_name: redis
expose: expose:
@ -84,6 +86,11 @@ services:
condition: service_healthy condition: service_healthy
redis: redis:
condition: service_healthy condition: service_healthy
healthcheck:
test: ["CMD", "celery", "-A", "right_tree.api", "inspect", "ping"]
interval: 10s
timeout: 5s
retries: 5
deploy: deploy:
resources: resources:
limits: limits:

View file

@ -6,11 +6,6 @@ volumes:
x-django: &django x-django: &django
image: right-tree image: right-tree
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
volumes: volumes:
- ./backend:/app - ./backend:/app
env_file: .env env_file: .env
@ -21,6 +16,13 @@ services:
backend: backend:
<<: *django <<: *django
container_name: backend container_name: backend
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
celery:
condition: service_healthy
expose: expose:
- "8000" - "8000"
command: command:
@ -56,7 +58,7 @@ services:
environment: environment:
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
healthcheck: healthcheck:
test: ["CMD", "pg_isready", "--dbname", "righttree", "--username", "righttree"] test: ["CMD", "pg_isready", "--dbname", "$DATABASE_NAME", "--username", "$DATABASE_USER"]
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5
@ -75,7 +77,7 @@ services:
- 80:80 - 80:80
redis: redis:
image: redis:7.0.8 image: redis:7.0.10
restart: unless-stopped restart: unless-stopped
container_name: redis container_name: redis
volumes: volumes:
@ -94,14 +96,21 @@ services:
celery: celery:
<<: *django <<: *django
container_name: celery container_name: celery
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
command: command:
- celery - celery
- -A - -A
- right_tree.api - right_tree.api
- worker - worker
depends_on: healthcheck:
redis: test: ["CMD", "celery", "-A", "right_tree.api", "inspect", "ping"]
condition: service_healthy interval: 10s
timeout: 5s
retries: 5
deploy: deploy:
resources: resources:
limits: limits: