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

Add documentation for running with prod secrets #76

Merged
merged 1 commit into from
Oct 4, 2018
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
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ APP_PORT=8080
BUILD_TAG=development
DOCKER_REPO=cwolff
USE_DEVTOOLS=True
GUNICORN_WORKERS=1
CELERY_WORKERS=1
SERVER_WORKERS=1
QUEUE_WORKERS=1
LOKOLE_LOG_LEVEL=DEBUG
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ stored in files in the :code:`secrets` directory. Other parts of the
project's tooling (e.g. docker-compose) depend on these files so make sure to
not delete them.

To run the project using the Azure resources created by the setup, use the
following command:

.. sourcecode :: sh

docker-compose -f docker-compose.yml -f docker-compose.secrets.yml up --build

Production setup
----------------

Expand Down
28 changes: 28 additions & 0 deletions docker-compose.secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.4'

x-shared-secret-environment:
&shared-secret-environment
build:
args:
USE_DEVTOOLS: "False"
environment:
DOTENV_SECRETS: azure;sendgrid
LOKOLE_STORAGE_PROVIDER: AZURE_BLOBS
QUEUE_BROKER_SCHEME: azureservicebus
secrets:
- azure
- sendgrid

services:

api:
<< : *shared-secret-environment

worker:
<< : *shared-secret-environment

secrets:
azure:
file: ./secrets/azure.env
sendgrid:
file: ./secrets/sendgrid.env
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.4'

x-shared-app-environment:
&shared-app-environment
CELERY_BROKER_URL: pyamqp://guest:guest@rabbitmq
QUEUE_BROKER_URL: pyamqp://guest:guest@rabbitmq
LOKOLE_LOG_LEVEL: ${LOKOLE_LOG_LEVEL}
LOKOLE_STORAGE_PROVIDER: "LOCAL"
LOKOLE_EMAIL_SERVER_AZURE_BLOBS_NAME: "/data/server-blobs"
Expand Down Expand Up @@ -42,15 +42,15 @@ services:
<< : *shared-app-environment
CONNEXION_SPEC: /app/opwen_email_server/static/email-receive-spec.yaml,/app/opwen_email_server/static/client-read-spec.yaml,/app/opwen_email_server/static/client-write-spec.yaml,/app/opwen_email_server/static/healthcheck-spec.yaml
CONNEXION_SERVER: flask
GUNICORN_WORKERS: ${GUNICORN_WORKERS}
SERVER_WORKERS: ${SERVER_WORKERS}
TESTING_UI: "True"

worker:
<< : *shared-app-build
command: ["/app/run-celery.sh"]
environment:
<< : *shared-app-environment
CELERY_WORKERS: ${CELERY_WORKERS}
QUEUE_WORKERS: ${QUEUE_WORKERS}

rabbitmq:
image: rabbitmq:3.7.8-management
4 changes: 2 additions & 2 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ADD docker/docker-entrypoint.sh /docker-entrypoint.sh
ENV TESTING_UI="False"
ENV CONNEXION_SERVER="tornado"
ENV CONNEXION_SPEC="SET_ME"
ENV GUNICORN_WORKERS="1"
ENV CELERY_WORKERS="1"
ENV SERVER_WORKERS="1"
ENV QUEUE_WORKERS="1"
ENV LOKOLE_LOG_LEVEL="INFO"
ENV PORT="80"

Expand Down
2 changes: 1 addition & 1 deletion docker/app/run-celery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"${PY_ENV}/bin/celery" \
--app="opwen_email_server.services.tasks" \
worker \
--concurrency="${CELERY_WORKERS}" \
--concurrency="${QUEUE_WORKERS}" \
--loglevel="${LOKOLE_LOG_LEVEL}"
2 changes: 1 addition & 1 deletion docker/app/run-gunicorn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ done
apis="[${apis:1:${#apis}-1}]"

"${PY_ENV}/bin/gunicorn" \
--workers="${GUNICORN_WORKERS}" \
--workers="${SERVER_WORKERS}" \
--log-level="${LOKOLE_LOG_LEVEL}" \
--bind="0.0.0.0:${PORT}" \
"runserver:build_app(apis=${apis}, server='${CONNEXION_SERVER}', ui=${TESTING_UI})"
8 changes: 4 additions & 4 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@
secretKeyRef:
name: sendgrid
key: LOKOLE_SENDGRID_KEY
- name: CELERY_BROKER_SCHEME
- name: QUEUE_BROKER_SCHEME
value: azureservicebus
- name: CELERY_BROKER_USERNAME
- name: LOKOLE_EMAIL_SERVER_QUEUES_SAS_NAME
valueFrom:
secretKeyRef:
name: azure
key: LOKOLE_EMAIL_SERVER_QUEUES_SAS_NAME
- name: CELERY_BROKER_PASSWORD
- name: LOKOLE_EMAIL_SERVER_QUEUES_SAS_KEY
valueFrom:
secretKeyRef:
name: azure
key: LOKOLE_EMAIL_SERVER_QUEUES_SAS_KEY
- name: CELERY_BROKER_HOST
- name: LOKOLE_EMAIL_SERVER_QUEUES_NAMESPACE
valueFrom:
secretKeyRef:
name: azure
Expand Down
4 changes: 2 additions & 2 deletions helm/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ spec:
env:
- name: CONNEXION_SPEC
value: /app/opwen_email_server/static/email-receive-spec.yaml,/app/opwen_email_server/static/client-read-spec.yaml,/app/opwen_email_server/static/client-write-spec.yaml,/app/opwen_email_server/static/healthcheck-spec.yaml
- name: GUNICORN_WORKERS
value: "{{.Values.server.gunicornWorkers}}"
- name: SERVER_WORKERS
value: "{{.Values.server.serverWorkers}}"
{{ include "opwen.environment.shared" }}
ports:
- containerPort: 80
Expand Down
4 changes: 2 additions & 2 deletions helm/templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ spec:
image: {{.Values.version.imageRegistry}}/opwenserver_app:{{.Values.version.dockerTag}}
command: ["/app/run-celery.sh"]
env:
- name: CELERY_WORKERS
value: "{{.Values.worker.celeryWorkers}}"
- name: QUEUE_WORKERS
value: "{{.Values.worker.queueWorkers}}"
{{ include "opwen.environment.shared" }}
ports:
- containerPort: 80
Expand Down
4 changes: 2 additions & 2 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ version:
dockerTag: latest

server:
gunicornWorkers: 2
serverWorkers: 2

worker:
celeryWorkers: 1
queueWorkers: 1

logging:
level: INFO
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean:

server: venv
PY_ENV="$(py_env)" \
GUNICORN_WORKERS=1 \
SERVER_WORKERS=1 \
LOKOLE_LOG_LEVEL=DEBUG \
TESTING_UI="True" \
PORT="8080" \
Expand All @@ -58,6 +58,6 @@ server: venv

worker: venv
PY_ENV="$(py_env)" \
CELERY_WORKERS=1 \
QUEUE_WORKERS=1 \
LOKOLE_LOG_LEVEL=DEBUG \
./docker/app/run-celery.sh
13 changes: 7 additions & 6 deletions opwen_email_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
MAX_WIDTH_IMAGES = int(environ.get('MAX_WIDTH_EMAIL_IMAGES', '200'))
MAX_HEIGHT_IMAGES = int(environ.get('MAX_HEIGHT_EMAIL_IMAGES', '200'))

CELERY_BROKER = environ.get('CELERY_BROKER_URL') or (
'{scheme}://{username}:{password}@{host}'.format(
scheme=environ.get('CELERY_BROKER_SCHEME'),
username=environ.get('CELERY_BROKER_USERNAME'),
password=environ.get('CELERY_BROKER_PASSWORD'),
host=environ.get('CELERY_BROKER_HOST')))
if environ.get('QUEUE_BROKER_SCHEME') == 'azureservicebus':
QUEUE_BROKER = 'azureservicebus://{username}:{password}@{host}'.format(
username=environ.get('LOKOLE_EMAIL_SERVER_QUEUES_SAS_NAME'),
password=environ.get('LOKOLE_EMAIL_SERVER_QUEUES_SAS_KEY'),
host=environ.get('LOKOLE_EMAIL_SERVER_QUEUES_NAMESPACE'))
else:
QUEUE_BROKER = environ.get('QUEUE_BROKER_URL', '')
2 changes: 1 addition & 1 deletion opwen_email_server/services/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from opwen_email_server.api import store_inbound_emails
from opwen_email_server.api import store_written_client_emails

celery = Celery(broker=config.CELERY_BROKER)
celery = Celery(broker=config.QUEUE_BROKER)


@celery.task(ignore_result=True)
Expand Down