Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/simple deployment #65

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:18-bullseye
# -------------------------- Dev ---------------------------------------

FROM node:18-bullseye as dev

RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
Expand All @@ -8,3 +10,13 @@ RUN apt-get update -y \
WORKDIR /code

RUN git config --global --add safe.directory /code


# -------------------------- Builder ---------------------------------------
FROM dev AS builder

COPY ./package.json ./yarn.lock /code/
RUN yarn install --frozen-lockfile --check-files --cache-folder .ycache && \
rm -rf .ycache

COPY . /code/
2 changes: 1 addition & 1 deletion backend
Submodule backend updated 46 files
+38 −0 apps/common/admin.py
+15 −0 apps/common/enums.py
+8 −0 apps/common/factories.py
+24 −0 apps/common/migrations/0001_initial.py
+0 −0 apps/common/migrations/__init__.py
+18 −0 apps/common/models.py
+3 −1 apps/export/tests/test_mutations.py
+3 −1 apps/export/tests/test_queries.py
+3 −1 apps/export/tests/test_tasks.py
+7 −2 apps/qbank/admin.py
+3 −0 apps/qbank/factories.py
+30 −7 apps/qbank/importer/xlsxform.py
+28 −0 apps/qbank/migrations/0003_questionbank_ended_at_questionbank_errors_and_more.py
+7 −0 apps/qbank/models.py
+76 −0 apps/qbank/mutations.py
+33 −0 apps/qbank/serializers.py
+58 −0 apps/qbank/tasks.py
+0 −0 apps/qbank/tests/__init__.py
+277 −0 apps/qbank/tests/test_mutations.py
+ apps/qbank/tests/xlsform-invalid-name.xlsx.gz
+ apps/qbank/tests/xlsform-invalid.xlsx.gz
+ apps/qbank/tests/xlsform-valid.xlsx.gz
+2 −1 apps/qbank/types.py
+1 −0 apps/questionnaire/mutations.py
+44 −28 apps/questionnaire/tests/test_mutations.py
+24 −38 apps/questionnaire/tests/test_queries.py
+1 −1 apps/questionnaire/types.py
+2 −0 apps/user/admin.py
+15 −0 apps/user/models.py
+6 −0 apps/user/types.py
+9 −0 deploy/run_web.sh
+15 −0 deploy/run_worker.sh
+12 −0 deploy/uwsgi.ini
+2 −0 main/enums.py
+20 −3 main/graphql/schema.py
+14 −0 main/sentry.py
+71 −0 main/ses.py
+1 −0 main/settings.py
+1 −1 main/storages.py
+39 −9 main/tests/base.py
+4 −1 main/urls.py
+285 −2 poetry.lock
+4 −0 pyproject.toml
+29 −0 schema.graphql
+5 −1 utils/strawberry/mutations.py
+6 −0 utils/strawberry/transformers.py
208 changes: 208 additions & 0 deletions deploy-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
x-logging-options:
options: &logging_options
awslogs-region: ${AWS_LOGGING_REGION?err}
awslogs-group: ${AWS_LOGGING_GROUP?err}


x-server: &base_server_setup
image: qber-backend:${LOCAL_BACKEND_TAG:?error}
build:
context: ./backend/
tty: true
environment: &base_server_environment
APP_ENVIRONMENT: ${APP_ENVIRONMENT?err}
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?err}
DJANGO_CORS_ORIGIN_REGEX_WHITELIST: ${DJANGO_CORS_ORIGIN_REGEX_WHITELIST?err}
APP_HTTP_PROTOCOL: ${APP_HTTP_PROTOCOL:-https}
APP_FRONTEND_HOST: ${APP_FRONTEND_HOST?err}
SESSION_COOKIE_DOMAIN: ${SESSION_COOKIE_DOMAIN?err}
CSRF_COOKIE_DOMAIN: ${CSRF_COOKIE_DOMAIN?err}
DJANGO_ALLOWED_HOST: ${DJANGO_ALLOWED_HOST?err}
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?err}
# Enketo
ENKETO_DOMAIN: ${ENKETO_DOMAIN?err}
# 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}
# Sentry
SENTRY_DSN: ${DJANGO_SENTRY_DSN?err}
SENTRY_SAMPLE_RATE: ${DJANGO_SENTRY_SAMPLE_RATE:-0.2}
env_file:
# Provide additional environment variables using .env file
- .env
volumes:
- ipython_data_local:/root/.ipython/profile_default # persist ipython data, including ipython history
restart: unless-stopped
depends_on:
- db
- redis


services:
react:
tty: true
build:
context: .
target: builder
environment:
APP_TITLE: ${APP_TITLE:-Questionnaire Builder}
APP_STATIC_ENDPOINT: ${APP_STATIC_ENDPOINT?err}
APP_GRAPHQL_ENDPOINT: ${APP_GRAPHQL_ENDPOINT?err}
NODE_OPTIONS: "--max_old_space_size=1024"
env_file:
- .env
command: |
sh -c 'yarn generate && yarn build && rm -rf /client-build/* ; cp -r build/* /client-build/'
volumes:
- client-static:/client-build/
profiles: [frontend]

db:
image: postgis/postgis:15-master
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: qber
restart: unless-stopped
volumes:
- postgres-data15:/var/lib/postgresql/data
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "db"

redis:
image: redis:latest
volumes:
- redis-data:/data
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "redis-cli ping"]
interval: 10s
timeout: 5s
retries: 5
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "redis"

api:
<<: *base_server_setup
environment:
<<: *base_server_environment
APP_TYPE: web
command: ./deploy/run_web.sh
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "api"

worker:
<<: *base_server_setup
environment:
<<: *base_server_environment
APP_TYPE: worker
command: ./deploy/run_worker.sh
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "worker"

enketo_redis_main:
image: redis:7.0
volumes:
- enketo_redis_main-data:/data
restart: unless-stopped
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "enketo-redis"

enketo_redis_cache:
image: redis:7.0
volumes:
- enketo_redis_cache-data:/data
restart: unless-stopped
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "enketo-redis-cache"

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?err}
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
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "enketo"

caddy:
image: caddy:2
restart: always
volumes:
# Static files
- client-static:/app-assests/client-static:ro
# Caddy config
- ./deploy/Caddyfile:/etc/caddy/Caddyfile:ro
# Caddy data volumes
- caddy_data:/data
- caddy_config:/config
environment:
CADDY_EMAIL: ${SUPPORT_EMAIL?err}
CADDY_BACKEND_HOST: ${CADDY_BACKEND_HOST?err}
CADDY_CLIENT_HOST: ${CADDY_CLIENT_HOST?err}
CADDY_CLIENT_ENKETO_HOST: ${CADDY_CLIENT_ENKETO_HOST?err}
ports:
- 80:80
- 443:443
depends_on:
- api
- enketo
logging:
driver: awslogs
options:
<<: *logging_options
awslogs-stream: "caddy"


volumes:
# Static files
client-static:
# DB
postgres-data15:
redis-data:
enketo_redis_main-data:
enketo_redis_cache-data:
# Shell history
ipython_data_local:
# Caddy
caddy_data:
caddy_config:
18 changes: 18 additions & 0 deletions deploy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
email {$CADDY_EMAIL}
}

{$CADDY_BACKEND_HOST} {
reverse_proxy http://api:80
}

{$CADDY_CLIENT_ENKETO_HOST} {
reverse_proxy http://enketo:8005
}

{$CADDY_CLIENT_HOST} {
encode gzip
try_files {path} /index.html
root * /app-assests/client-static
file_server
}
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
version: '3.2'


x-server: &base_server_setup
image: ghcr.io/the-deep/qber-backend:${DOCKER_BACKEND_TAG:-latest}
build:
Expand Down Expand Up @@ -49,7 +46,9 @@ x-server: &base_server_setup
services:
react:
tty: true
build: .
build:
context: .
target: dev
environment:
APP_TITLE: ${APP_TITLE:-Questionnaire Builder}
APP_STATIC_ENDPOINT: ${APP_STATIC_ENDPOINT:-http://localhost:8311}
Expand Down
Loading
Loading