Skip to content

Commit

Permalink
Add deployment configuration
Browse files Browse the repository at this point in the history
- Fix css linting issue
  • Loading branch information
thenav56 authored and AdityaKhatri committed Sep 13, 2023
1 parent 174a319 commit c3c651a
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 1 deletion.
162 changes: 162 additions & 0 deletions deploy-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
version: '3.2'

# WIP - For Preview oonly

x-server: &base_server_setup
image: ghcr.io/the-deep/qber-backend:${DOCKER_BACKEND_TAG:-latest}
build:
context: ./backend/
tty: true
environment: &base_server_environment
APP_ENVIRONMENT: deployment
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY?err}
# To overwrite this values. set the values in .env
DJANGO_DEBUG: ${DJANGO_DEBUG:-False}
APP_DOMAIN: ${APP_DOMAIN:-localhost:8311}
DJANGO_CORS_ORIGIN_REGEX_WHITELIST: ${DJANGO_CORS_ORIGIN_REGEX_WHITELIST}
APP_HTTP_PROTOCOL: ${APP_HTTP_PROTOCOL:-http}
APP_FRONTEND_HOST: ${APP_FRONTEND_HOST:-localhost:3000}
SESSION_COOKIE_DOMAIN: ${SESSION_COOKIE_DOMAIN:-localhost}
CSRF_COOKIE_DOMAIN: ${CSRF_COOKIE_DOMAIN:-localhost}
DJANGO_ALLOWED_HOST: ${DJANGO_ALLOWED_HOST:-*}
DJANGO_DB_NAME: ${DJANGO_DB_NAME:-qber}
DJANGO_DB_USER: ${DJANGO_DB_USER:-postgres}
DJANGO_DB_PASSWORD: ${DJANGO_DB_PASSWORD:-postgres}
DJANGO_DB_PORT: ${DJANGO_DB_PORT:-5432}
DJANGO_DB_HOST: ${DJANGO_DB_HOST:-db}
# EMAIL
EMAIL_FROM: ${EMAIL_FROM:[email protected]}
# Enketo
ENKETO_DOMAIN: ${ENKETO_DOMAIN:-http://localhost:8005}
# Redis
CELERY_REDIS_URL: ${CELERY_REDIS_URL:-redis://redis:6379/1}
DJANGO_CACHE_REDIS_URL: ${DJANGO_CACHE_REDIS_URL:-redis://redis:6379/2}
TEST_DJANGO_CACHE_REDIS_URL: ${TEST_DJANGO_CACHE_REDIS_URL:-redis://redis:6379/12}
DJANGO_STATIC_ROOT: /assets/static
DJANGO_MEDIA_ROOT: /assets/media
env_file:
# Provide additional environment variables using .env file
- .env
volumes:
- ./backend/:/code
- backend-media:/assets/media
- backend-static:/assets/static
- ipython_data_local:/root/.ipython/profile_default # persist ipython data, including ipython history
depends_on:
- db
- redis


services:
react:
tty: true
build: .
environment:
APP_TITLE: ${APP_TITLE:-Questionnaire Builder}
APP_STATIC_ENDPOINT: ${APP_STATIC_ENDPOINT:-http://localhost:8311}
APP_GRAPHQL_ENDPOINT: ${APP_GRAPHQL_ENDPOINT:-http://localhost:8311/graphql/}
env_file:
- .env
command: sh -c 'yarn install && yarn generate && yarn build && rm -rf /client-build/* ; cp -r build/* /client-build/'
volumes:
- client-static:/client-build/
- .:/code

db:
image: postgis/postgis:15-master
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: qber
volumes:
- postgres-data15:/var/lib/postgresql/data

redis:
image: redis:latest
volumes:
- redis-data:/data
healthcheck:
test: ["CMD-SHELL", "redis-cli ping"]
interval: 10s
timeout: 5s
retries: 5

api:
<<: *base_server_setup
environment:
<<: *base_server_environment
APP_TYPE: web
# TODO: using gunicorn
command: ./scripts/run_develop.sh

worker:
<<: *base_server_setup
environment:
<<: *base_server_environment
APP_TYPE: worker
# TODO: using non-dev celery
command: ./manage.py run_celery_dev

enketo_redis_main:
image: redis:7.0
volumes:
- enketo_redis_main-data:/data
restart: unless-stopped

enketo_redis_cache:
image: redis:7.0
volumes:
- enketo_redis_cache-data:/data
restart: unless-stopped

enketo:
image: ghcr.io/enketo/enketo-express:6.2.2
depends_on:
- enketo_redis_main
- enketo_redis_cache
environment:
ENKETO_PORT: 8005
SUPPORT_EMAIL: ${SUPPORT_EMAIL:[email protected]}
ENKETO_REDIS_MAIN_URL: redis://redis:redis@enketo_redis_main:6379
ENKETO_REDIS_CACHE_URL: redis://redis:redis@enketo_redis_cache:6379
ENKETO_API_KEY: ${ENKETO_API_KEY?err}
ENKETO_ENCRYPTION_KEY: ${ENKETO_API_KEY?err}
command: bash -c "cd $${ENKETO_SRC_DIR}/ && pm2-runtime app.js -n enketo"
restart: unless-stopped

nginx:
image: nginx
user: root
volumes:
# Nginx config
- ./nginx.deploy.conf.template:/etc/nginx/templates/default.conf.template:ro
# Static files
- client-static:/app-assests/client-static:ro
- backend-static:/app-assests/backend-static:ro
# Media files
- backend-media:/app-assests/backend-media:ro
restart: unless-stopped
environment:
- NGINX_BACKEND_HOST=${NGINX_BACKEND_HOST?err}
- NGINX_CLIENT_HOST=${NGINX_CLIENT_HOST?err}
- NGINX_CLIENT_ENKETO_HOST=${NGINX_CLIENT_ENKETO_HOST?err}
ports:
- '127.0.0.1:$QBER_NGINX_SERVER_PORT:80' # This will be different for each alpha-x
depends_on:
- api
- enketo


volumes:
# Static files
backend-static:
client-static:
# Media files
backend-media:
# DB
postgres-data15:
redis-data:
enketo_redis_main-data:
enketo_redis_cache-data:
# Shell history
ipython_data_local:
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ x-server: &base_server_setup
DJANGO_DEBUG: ${DJANGO_DEBUG:-True}
APP_DOMAIN: localhost:8311
APP_HTTP_PROTOCOL: http
APP_FRONTEND_HOST: localhost:3000
APP_FRONTEND_HOST: http://localhost:3000
SESSION_COOKIE_DOMAIN: ${SESSION_COOKIE_DOMAIN:-localhost}
CSRF_COOKIE_DOMAIN: ${CSRF_COOKIE_DOMAIN:-localhost}
DJANGO_ALLOWED_HOST: ${DJANGO_ALLOWED_HOST:-*}
Expand Down
60 changes: 60 additions & 0 deletions nginx.deploy.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
server {
listen 80;
server_name $NGINX_BACKEND_HOST;

location /static {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
alias /app-assests/backend-static/;
}

location /media {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
alias /app-assests/backend-media/;
}

location / {
proxy_pass http://api:8000;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# IF SSL: proxy_set_header X-Forwarded-Proto https;
}
}


server {
listen 80;
server_name $NGINX_CLIENT_ENKETO_HOST;

location / {
proxy_pass http://enketo:8005;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# IF SSL: proxy_set_header X-Forwarded-Proto https;
}
}

server {
listen 80;
server_name $NGINX_CLIENT_HOST;

gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

location / {
alias /app-assests/client-static/;
try_files $uri /index.html;
}
}

# set vim: syntax=nginx

0 comments on commit c3c651a

Please sign in to comment.