From 8666722be938194d95abe6f9ae8c45d123f443fc Mon Sep 17 00:00:00 2001 From: Newbas Date: Tue, 30 Nov 2021 18:42:27 +0100 Subject: [PATCH] Add full local setup with docker - Add separate configuration for s3 endpoint - Add dockerfile to build backend image - Add docker-compose with minio and rabbitmq - Add MacOS setup guide --- Dockerfile | 15 +++++++++++++++ README.md | 16 +++++++++++++++- config/settings.py | 1 + docker-compose.yml | 30 ++++++++++++++++++++++++++++++ libs/s3.py | 5 +++-- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..44375d93d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.7 + +RUN apt-get update && apt-get install -y postgresql libpq-dev && \ + pip install --upgrade pip setuptools wheel + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +WORKDIR /code + +COPY . requirements.txt app.py manage.py wsgi.py /code/ + +RUN pip install -r requirements.txt + +CMD python manage.py migrate && python app.py \ No newline at end of file diff --git a/README.md b/README.md index 6c4485235..611b04353 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,20 @@ While it is possible to run your development environment inside of the system Py ``` I usually store it at `private/environment.sh`. Load up these environment variables by running `source private/environment.sh` at the Bash prompt. +#### MacOS Install + +1. `brew update; brew install postgresql` +2. `pip install --upgrade pip setuptools wheel` +3. `pip install -r requirements.txt` +4. Create a file for your environment variables that contains at least these: + ``` + export DOMAIN_NAME="localhost://8080" + export FLASK_SECRET_KEY="asdf" + export S3_BUCKET="a" + export SYSADMIN_EMAILS="sysadmin@localhost" + ``` + I usually store it at `private/environment.sh`. Load up these environment variables by running `source private/environment.sh` at the Bash prompt. + For additional tips on running a local development enironment please see [this wiki page](https://github.com/onnela-lab/beiwe-backend/wiki/Tips-For-Local-Beiwe-Development). If you are having difficulty getting started, or believe you could assist with any issues of documentation, please [post an issue with a documentation tag](https://github.com/onnela-lab/beiwe-backend/labels/documentation). ### Local Celery setup @@ -93,7 +107,7 @@ For those souls brave enough to run the entire broker queue and Celery task disp 2. `pip install -r requirements_data_processing.txt` (this will install Celery using pip) 3. Create a file called `manager_ip` in the top level of your `beiwe-backend` repo, and enter these two lines in it. Do not provide a trailing new-line character. ``` - 127.0.0.1:50000 + mq:50000 [YOUR DESIRED PASSWORD] ``` Where the password is the one you set when setting up RabbitMQ diff --git a/config/settings.py b/config/settings.py index 27faba80d..d8154d23a 100644 --- a/config/settings.py +++ b/config/settings.py @@ -26,6 +26,7 @@ # The name of the S3 bucket that will be used to store user generated data. S3_BUCKET = getenv("S3_BUCKET") +S3_ENDPOINT = getenv("S3_ENDPOINT", None) # Domain name for the server, this is used for various details, and should be match the address of # the frontend server. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..253375a8c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: "3.8" +services: +# db: +# image: "postgresql:14" + mq: + image: "rabbitmq:latest" + environment: + - RABBITMQ_DEFAULT_USER=beiwe + - RABBITMQ_DEFAULT_PASS=beiwe + - RABBITMQ_ERLANG_COOKIE='takeMyCookies' + storage: + image: minio/minio + environment: + - MINIO_ACCESS_KEY=minioadmin + - MINIO_SECRET_KEY=minioadmin + ports: + - "9000:9000" + command: server /data + backend: + build: . + environment: + - DOMAIN_NAME=localhost://8080 + - FLASK_SECRET_KEY=asdf + - S3_BUCKET=beiwe + - S3_ENDPOINT=http://storage:9000 + - SYSADMIN_EMAILS=sysadmin@localhost + - BEIWE_SERVER_AWS_ACCESS_KEY_ID=minioadmin + - BEIWE_SERVER_AWS_SECRET_ACCESS_KEY=minioadmin + ports: + - "8080:8080" \ No newline at end of file diff --git a/libs/s3.py b/libs/s3.py index 956fe7c2c..ffe297a42 100644 --- a/libs/s3.py +++ b/libs/s3.py @@ -2,7 +2,7 @@ import Crypto from config.settings import (BEIWE_SERVER_AWS_ACCESS_KEY_ID, BEIWE_SERVER_AWS_SECRET_ACCESS_KEY, - S3_BUCKET, S3_REGION_NAME) + S3_BUCKET, S3_REGION_NAME, S3_ENDPOINT) from libs.encryption import (decrypt_server, encrypt_for_server, generate_key_pairing, get_RSA_cipher, prepare_X509_key_for_java) @@ -31,7 +31,8 @@ class NoSuchKeyException(Exception): pass 's3', aws_access_key_id=BEIWE_SERVER_AWS_ACCESS_KEY_ID, aws_secret_access_key=BEIWE_SERVER_AWS_SECRET_ACCESS_KEY, - region_name=S3_REGION_NAME + region_name=S3_REGION_NAME, + endpoint_url=S3_ENDPOINT )