feat: working prod deploy with duplicate code

Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
Ameya Shenoy 2021-02-12 03:26:27 +05:30
parent f685b1a0fd
commit b2f76391db
Signed by: codingcoffee
GPG key ID: F7D58AAC5DACF8D3
13 changed files with 338 additions and 23 deletions

View file

@ -35,5 +35,5 @@ ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
ENV UWSGI_STATIC_MAP="/static/=/code/static/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
USER ${APP_USER}:${APP_USER}
ENTRYPOINT ["sh", "/code/prod-entrypoint.sh"]
CMD sh /code/prod-entrypoint.sh

View file

@ -25,7 +25,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = os.environ.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get('DEBUG'))
DEBUG = os.environ.get('DEBUG')
DEBUG = False if not DEBUG or DEBUG.lower() == 'false' else True
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS')
if ALLOWED_HOSTS:

View file

@ -3,7 +3,7 @@
# Apply database migrations
echo "Apply database migrations"
python manage.py migrate collectstatic --noinput
python manage.py migrate
# Start server
echo "Starting server"

View file

@ -11,6 +11,8 @@ RUN set -ex \
&& npm i
COPY src /code/src
# hack: for prod api
RUN sed -i "s,http://localhost:8000,https://api.bullish.codingcoffee.me,g" /code/src/axios-api.js
RUN NODE_ENV=production npm run build
FROM nginx:1.19.6-alpine

View file

@ -2,7 +2,7 @@ import axios from 'axios'
// TODO: fix baseurl as per builds
const getAPI = axios.create({
baseURL: 'http://127.0.0.1:8000',
baseURL: 'http://localhost:8000',
timeout: 60000,
})

76
k8s/app/backend.yaml Normal file
View file

@ -0,0 +1,76 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bullish-backend
spec:
selector:
matchLabels:
app: bullish-backend
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: bullish-backend
spec:
containers:
- name: bullish-backend
image: codingcoffee/bullish-backend
env:
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: SECRET_KEY
value: sample
- name: ALLOWED_HOSTS
value: api.bullish.codingcoffee.me
- name: CORS_ALLOWED_ORIGINS
value: https://bullish.codingcoffee.me
- name: REDIS_HOST
value: bullish-redis
- name: REDIS_PORT
value: "6379"
- name: REDIS_CACHE_DB
value: "1"
- name: REDIS_QUEUE_DB
value: "0"
- name: POSTGRES_SERVER
value: bullish-database
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: POSTGRES_PORT
value: "5432"
---
apiVersion: v1
kind: Service
metadata:
name: bullish-backend
labels:
app: bullish-backend
spec:
type: ClusterIP
selector:
app: bullish-backend
ports:
- port: 8000
targetPort: 8000
protocol: TCP
...

View file

@ -23,4 +23,21 @@ spec:
- name: bullish-frontend
image: codingcoffee/bullish-frontend
---
apiVersion: v1
kind: Service
metadata:
name: bullish-frontend
labels:
app: bullish-frontend
spec:
type: ClusterIP
selector:
app: bullish-frontend
ports:
- port: 80
targetPort: 80
protocol: TCP
...

61
k8s/app/postgres.yaml Normal file
View file

@ -0,0 +1,61 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bullish-database
spec:
selector:
matchLabels:
app: bullish-database
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: bullish-database
spec:
volumes:
- name: postgres-data
hostPath:
path: "/var/k8s-pv/bullish/postgres"
type: DirectoryOrCreate
containers:
- name: postgres
image: postgres:13.1-alpine
env:
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data/pgdata
---
apiVersion: v1
kind: Service
metadata:
name: bullish-database
labels:
app: bullish-database
spec:
type: ClusterIP
selector:
app: bullish-database
ports:
- port: 5432
targetPort: 5432
protocol: TCP
...

43
k8s/app/redis.yaml Normal file
View file

@ -0,0 +1,43 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bullish-redis
spec:
selector:
matchLabels:
app: bullish-redis
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: bullish-redis
spec:
containers:
- name: redis
image: redis:6.0.10-alpine3.13
---
apiVersion: v1
kind: Service
metadata:
name: bullish-redis
labels:
app: bullish-redis
spec:
type: ClusterIP
selector:
app: bullish-redis
ports:
- port: 6379
targetPort: 6379
protocol: TCP
...

63
k8s/app/rqscheduler.yaml Normal file
View file

@ -0,0 +1,63 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bullish-scheduler
spec:
selector:
matchLabels:
app: bullish-scheduler
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: bullish-scheduler
spec:
containers:
- name: bullish-backend
image: codingcoffee/bullish-backend
command:
- "/bin/sh"
- "-c"
- "python manage.py rqscheduler"
env:
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: SECRET_KEY
value: sample
- name: ALLOWED_HOSTS
value: api.bullish.codingcoffee.me
- name: CORS_ALLOWED_ORIGINS
value: https://bullish.codingcoffee.me
- name: REDIS_HOST
value: bullish-redis
- name: REDIS_PORT
value: "6379"
- name: REDIS_CACHE_DB
value: "1"
- name: REDIS_QUEUE_DB
value: "0"
- name: POSTGRES_SERVER
value: bullish-database
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: POSTGRES_PORT
value: "5432"
...

63
k8s/app/rqworker.yaml Normal file
View file

@ -0,0 +1,63 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bullish-worker
spec:
selector:
matchLabels:
app: bullish-worker
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: bullish-worker
spec:
containers:
- name: bullish-backend
image: codingcoffee/bullish-backend
command:
- "/bin/sh"
- "-c"
- "python manage.py rqworker default"
env:
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: SECRET_KEY
value: sample
- name: ALLOWED_HOSTS
value: api.bullish.codingcoffee.me
- name: CORS_ALLOWED_ORIGINS
value: https://bullish.codingcoffee.me
- name: REDIS_HOST
value: bullish-redis
- name: REDIS_PORT
value: "6379"
- name: REDIS_CACHE_DB
value: "1"
- name: REDIS_QUEUE_DB
value: "0"
- name: POSTGRES_SERVER
value: bullish-database
- name: POSTGRES_USER
value: bullish
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: bullish
- name: POSTGRES_PORT
value: "5432"
...

View file

@ -1,18 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: bullish-frontend
labels:
app: bullish-frontend
spec:
type: ClusterIP
selector:
app: bullish-frontend
ports:
- port: 80
targetPort: 80
protocol: TCP
...

View file

@ -1,6 +1,6 @@
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: production-https-ingress
@ -18,10 +18,17 @@ spec:
- backend:
serviceName: bullish-frontend
servicePort: 80
- host: api.bullish.codingcoffee.me
http:
paths:
- backend:
serviceName: bullish-backend
servicePort: 8000
tls:
- hosts:
- bullish.codingcoffee.me
- api.bullish.codingcoffee.me
secretName: production-tls-cert
...