Skip to content

Commit

Permalink
Add admin user and a replica for the serving side
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenk committed Jul 31, 2024
1 parent 981804c commit 2fa1117
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
5 changes: 4 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Apache License
The majority of this code is released under an Apache 2.0 license.
Some elements of this code may be covered by seperate licenses, these include sub-folders with their own LICENSE files & individual files with their own license information present.

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down
51 changes: 18 additions & 33 deletions deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
apiVersion: apps/v1
kind: Deployment
kind: Job
metadata:
name: web-primary
namespace: totallylegitco
labels:
app: web-primary
spec:
replicas: 1
selector:
matchLabels:
special: web-primary-pod
strategy:
type: Recreate
template:
metadata:
labels:
group: fight-health-insurance-webbackend
group: fight-health-insurance-webbackend-batch
special: web-primary-pod
spec:
containers:
- image: holdenk/fight-health-insurance:v0.1.5b
- image: holdenk/fight-health-insurance:v0.1.6a
name: totallylegitco
env:
- name: PRIMARY
value: "1"
envFrom:
- secretRef:
name: fight-health-insurance-secret
- secretRef:
name: fight-health-insurance-primary-secret
imagePullPolicy: Always
ports:
- containerPort: 80
name: web
livenessProbe:
httpGet:
httpHeaders:
- name: Host
value: "www.fighthealthinsurance.com"
path: /
port: 80
periodSeconds: 180
startupProbe:
httpGet:
httpHeaders:
- name: Host
value: "www.fighthealthinsurance.com"
path: /
port: 80
periodSeconds: 10
failureThreshold: 30
restartPolicy: OnFailure
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -57,7 +32,7 @@ metadata:
labels:
app: fight-health-insurance
spec:
replicas: 1
replicas: 2
selector:
matchLabels:
app: fight-health-insurance
Expand All @@ -68,7 +43,7 @@ spec:
group: fight-health-insurance-webbackend
spec:
containers:
- image: holdenk/fight-health-insurance:v0.1.5b
- image: holdenk/fight-health-insurance:v0.1.6a
name: totallylegitco
envFrom:
- secretRef:
Expand Down Expand Up @@ -173,3 +148,13 @@ spec:
name: web-svc
port:
number: 80
- host: fighthealthinsurance.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-svc
port:
number: 80
28 changes: 28 additions & 0 deletions fighthealthinsurance/management/commands/ensure_adminuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://stackoverflow.com/questions/39744593/how-to-create-a-django-superuser-if-it-doesnt-exist-non-interactively
# Covered by https://stackoverflow.com/help/licensing
import os
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand

class Command(BaseCommand):
help = "Creates an admin user non-interactively if it doesn't exist"

def add_arguments(self, parser):
parser.add_argument('--username', help="Admin's username")
parser.add_argument('--email', help="Admin's email")
parser.add_argument('--password', help="Admin's password")
parser.add_argument('--no-input', help="Read options from the environment",
action='store_true')

def handle(self, *args, **options):
User = get_user_model()

if options['no_input']:
options['username'] = os.environ['FIGHT_HEALTH_ADMIN_USER']
options['email'] = os.environ['FIGHT_HEALTH_ADMIN_USER']
options['password'] = os.environ['FIGHT_HEALTH_ADMIN_PASSWORD']

if not User.objects.filter(username=options['username']).exists():
User.objects.create_superuser(username=options['username'],
email=options['email'],
password=options['password'])
2 changes: 2 additions & 0 deletions scripts/start-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cd /opt/app
if [ ! -z "$PRIMARY" ]; then
./manage.py migrate
./manage.py loaddata initial
./manage.py ensure_admin --no-input
exit 0
fi
# Start gunicorn
export DJANGO_CONFIGURATION=${DJANGO_CONFIGURATION:-"Prod"}
Expand Down

0 comments on commit 2fa1117

Please sign in to comment.