diff --git a/.env.sample b/.env.sample index 9ecf7e9..f71be38 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,17 @@ -DATABASE_URL=postgres:///myurl +################################ +# # +# THIS IS A SECRET FILE!!! # +# # +# Do not add your .env to git! # +# # +################################ + +# SECRET_KEY encrypts things. In production it should be a random string. SECRET_KEY=mysecretshouldnotbeongit + +# Set DATABASE_URL to use something other than the default SQLite. +# DATABASE_URL=postgres:///myurl + +# Set Open Humans project CLIENT_ID and CLIENT_SECRET. OH_CLIENT_ID=myclientidshouldnotbeongit OH_CLIENT_SECRET=myclientsecretshouldnotbeongit diff --git a/LICENSE b/LICENSE index 0d8f1c3..8a0d8f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Bastian Greshake Tzovaras +Copyright (c) 2018 Bastian Greshake Tzovaras, Mad Price Ball Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 21ac247..a4f9a7c 100644 --- a/README.md +++ b/README.md @@ -24,17 +24,22 @@ conda create -n oh_uploader python=3.6 pip install -r requirements.txt ``` -*Step 2: Install heroku-CLI & PostgreSQL* +*Step 2: Install Heroku Command Line Interface (CLI)* -If you are running MacOS the easiest way to do this is using [Homebrew](https://brew.sh/). If you are on a Linux machine you [should be able to do the same things using Linuxbrew](https://virtualenv.pypa.io/en/stable/). After installing Homebrew/Linuxbrew -you can do: +You should install the Heroku CLI to run this app. Heroku has [installation instructions for MacOS, Windows, and Linux](https://devcenter.heroku.com/articles/heroku-cli#download-and-install). + +If you are running MacOS the easiest way to do this is using [Homebrew](https://brew.sh/). After installing Homebrew you can do: ``` -brew install postgres brew install heroku/brew/heroku ``` -Once this is done you can start the setup of your *Open Humans uploader* by copying the example `.env` file (`cp .env.sample .env`) and entering at least your database URL. Once this is done you can migrate your database using `heroku local:run python manage.py migrate`. Afterwards you can start the webserver of your local heroku environment using `heroku local`. +Once this is done you can complete minimal setup by: +* Create an `.env` file from the example: `cp .env.sample .env`) +* Edit `.env` to set a random string for `DJANGO_SECRET` +* Migrate your database using `heroku local:run python manage.py migrate` + +Now you can run the webserver of your local heroku environment using `heroku local`. To fully set up your uploader you will have to modify some files, as described below. diff --git a/config.yaml b/config.yaml index 24c7268..39a2da9 100644 --- a/config.yaml +++ b/config.yaml @@ -7,8 +7,9 @@ project_description: This template demonstrates how you can run your own Open Hu # REQUIRED: Where can we find your project on Open Humans oh_activity_page: https://www.openhumans.org/activity/your-project-url/ -# REQUIRED: which URL will lead to your Open Humans uploader -app_base_url: http://127.0.0.1:5000 +# Optional: which URL will lead to your Open Humans uploader +# Defaults to http://127.0.0.1:500 if not set. +# app_base_url: http://127.0.0.1:5000 # REQUIRED: Tell Open Humans what kind of data is being uploaded file_description: This is an example file that doesnt have any meaning. diff --git a/oh_data_uploader/settings.py b/oh_data_uploader/settings.py index 445a52a..09628dd 100644 --- a/oh_data_uploader/settings.py +++ b/oh_data_uploader/settings.py @@ -30,7 +30,13 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False if os.getenv('DEBUG', '').lower() == 'false' else True -ALLOWED_HOSTS = ['*'] +# Establish whether this is running on Heroku +ON_HEROKU = os.getenv('ON_HEROKU', '').lower() == 'true' + +if ON_HEROKU: + ALLOWED_HOSTS = ['*'] +else: + ALLOWED_HOSTS = [] # Read OH settings from .env/environment variables @@ -43,7 +49,8 @@ YAML_CONFIG = yaml.load(''.join(yaml_content)) YAML_CONFIG['file_tags_string'] = str(YAML_CONFIG['file_tags']) -APP_BASE_URL = YAML_CONFIG['app_base_url'] +# Set up base URL. +APP_BASE_URL = YAML_CONFIG.get('app_base_url', 'http://127.0.0.1:5000') if APP_BASE_URL[-1] == "/": APP_BASE_URL = APP_BASE_URL[:-1] @@ -96,9 +103,16 @@ # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases -db_from_env = dj_database_url.config(conn_max_age=500) +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} -DATABASES = {'default': db_from_env} +if ON_HEROKU: + db_from_env = dj_database_url.config(conn_max_age=500) + DATABASES = {'default': db_from_env} # Password validation