-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PsychoinformaticsLab/dockerize
Set up docker-compose, and other boilerplate
- Loading branch information
Showing
43 changed files
with
1,318 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
APP_SETTINGS=neurostuff.config.DevelopmentConfig | ||
COMPOSE_CONVERT_WINDOWS_PATHS=1 | ||
POSTGRES_PASSWORD=example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
historical/ | ||
neurostuff/config.py | ||
|
||
# | ||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
matrix: | ||
include: | ||
- language: python | ||
python: | ||
- "3.6" | ||
install: | ||
- pip install -U setuptools==45 | ||
- pip install -r neurostuff/requirements.txt | ||
- pip install pytest-cov | ||
script: | ||
- python -m pytest neurostuff/ --cov=./ | ||
env: | ||
- APP_SETTINGS=neurostuff.config.app.TravisConfig PYTHONHASHSEED=0 | ||
addons: | ||
postgresql: "9.4" | ||
before_script: | ||
- cp neurostuff/example_config.py neurostuff/config.py | ||
- psql -c 'create database travis_ci_test;' -U postgres | ||
- CI="true" | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"creators": [ | ||
{ | ||
"affiliation": "University of Texas at Austin", | ||
"name": "Yarkoni, Tal", | ||
"orcid": "0000-0002-6558-5113" | ||
}, | ||
{ | ||
"affiliation": "University of Texas at Austin", | ||
"name": "De La Vega, Alejandro", | ||
"orcid": "0000-0001-9062-3778" | ||
}, | ||
], | ||
"keywords": [ | ||
"neuroimaging", | ||
"meta-analysis", | ||
"fMRI" | ||
], | ||
"upload_type": "software" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# neurostuff | ||
|
||
[Add badges] | ||
|
||
Requirements: Docker and docker-compose. | ||
|
||
## Configuration | ||
First, set up the main environment variables in `.env` (see: `.env.example`). | ||
|
||
cp .env.example .env | ||
|
||
Next, set up the Flask server's environment variables: | ||
|
||
cp neurostuff/example_config.py neurostuff/config.py | ||
|
||
|
||
Edit both of these template files to set the correct variables | ||
|
||
## Initalizing backend | ||
Build the containers and start services using the development configuration: | ||
|
||
docker-compose build | ||
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d | ||
|
||
The server should now be running at http://localhost/ | ||
|
||
Next, initialize, migrate and upgrade the database migrations. | ||
|
||
docker-compose exec neurostuff bash | ||
rm -rf /migrations/migrations | ||
python manage.py db init | ||
python manage.py db migrate | ||
python manage.py db upgrade | ||
|
||
Finally, add an admin user, and ingest data | ||
|
||
python manage.py add_user admin@neurostuff.org password | ||
python manage.py ingest_neurosynth | ||
|
||
|
||
## Maintaining docker image and db | ||
If you make a change to /neurostuff, you should be able to simply restart the server. | ||
|
||
docker-compose restart neurostuff | ||
|
||
If you need to upgrade the db after changing any models: | ||
|
||
docker-compose exec neurostuff python manage.py db migrate | ||
docker-compose exec neurostuff python manage.py db upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage: | ||
ignore: | ||
- "neurostuff/tests/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "2" | ||
services: | ||
nginx: | ||
volumes: | ||
- ./nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro | ||
|
||
neurostuff: | ||
command: /usr/local/bin/gunicorn -w 2 -b :8000 neurostuff.core:app --log-level debug --timeout 120 --reload | ||
restart: "no" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
version: "2" | ||
services: | ||
neurostuff: | ||
restart: always | ||
build: ./neurostuff | ||
expose: | ||
- "8000" | ||
volumes: | ||
- ./postgres/migrations:/migrations | ||
- ./:/neurostuff | ||
command: /usr/local/bin/gunicorn -w 2 -b :8000 neurostuff.core:app --log-level debug --timeout 120 | ||
env_file: | ||
- .env | ||
|
||
nginx: | ||
restart: always | ||
build: ./nginx | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
volumes: | ||
- ./nginx/certs:/etc/letsencrypt | ||
- ./nginx/certs-data:/data/letsencrypt | ||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro | ||
- ./nginx/sites-enabled:/etc/nginx/sites-enabled:ro | ||
volumes_from: | ||
- neurostuff | ||
|
||
postgres: | ||
restart: always | ||
build: ./postgres | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
expose: | ||
- '5432' | ||
environment: | ||
- POSTGRES_DB=neurostuff | ||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
env_file: | ||
- .env | ||
|
||
volumes: | ||
certs: | ||
certs-data: | ||
postgres_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Command line management tools. | ||
""" | ||
import os | ||
|
||
from flask_script import Manager, Shell | ||
from flask_migrate import Migrate, MigrateCommand | ||
from flask_security.utils import encrypt_password | ||
|
||
from neurostuff.core import app, db, user_datastore | ||
from neurostuff import ingest | ||
from neurostuff import models | ||
|
||
app.config.from_object(os.environ['APP_SETTINGS']) | ||
migrate = Migrate(app, db, directory=app.config['MIGRATIONS_DIR']) | ||
manager = Manager(app) | ||
|
||
|
||
def _make_context(): | ||
return dict(app=app, db=db, ms=models) | ||
|
||
|
||
manager.add_command('db', MigrateCommand) | ||
manager.add_command("shell", Shell(make_context=_make_context)) | ||
|
||
|
||
@manager.command | ||
def add_user(email, password): | ||
""" Add a user to the database. | ||
email - A valid email address (primary login key) | ||
password - Any string | ||
""" | ||
user_datastore.create_user( | ||
email=email, password=encrypt_password(password)) | ||
|
||
db.session.commit() | ||
|
||
|
||
@manager.command | ||
def ingest_neurosynth(max_rows=None): | ||
ingest.ingest_neurosynth(max_rows=max_rows) | ||
|
||
|
||
@manager.command | ||
def ingest_neurovault(verbose=False, limit=20): | ||
ingest.ingest_neurovault(verbose=verbose, limit=limit) | ||
|
||
|
||
if __name__ == '__main__': | ||
manager.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM python:3.6-stretch | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
RUN apt-get -qq update | ||
|
||
COPY requirements.txt /usr/src/app/ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . /usr/src/app | ||
|
||
WORKDIR /neurostuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" This is an EXAMPLE config file | ||
Rename this file to app.py and set variables | ||
""" | ||
import os | ||
|
||
|
||
class Config(object): | ||
SERVER_NAME = 'localhost' # Set to external server name in production | ||
|
||
MIGRATIONS_DIR = '/migrations/migrations' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
WTF_CSRF_ENABLED = False | ||
|
||
POSTGRES_PASSWORD = os.environ['POSTGRES_PASSWORD'] | ||
DB_NAME = 'neurostuff' | ||
SQLALCHEMY_DATABASE_URI = "postgres://postgres:" \ | ||
f"{POSTGRES_PASSWORD}@postgres:5432/{DB_NAME}" | ||
PROPAGATE_EXCEPTIONS = True | ||
|
||
GITHUB_CLIENT_ID = "github-id" | ||
GITHUB_CLIENT_SECRET = "github-secret" | ||
DANCE_SECRET_KEY = "temporary" | ||
|
||
|
||
class ProductionConfig(Config): | ||
ENV = 'production' | ||
|
||
|
||
class DevelopmentConfig(Config): | ||
ENV = 'development' | ||
DEBUG = True | ||
|
||
|
||
class TestingConfig(Config): | ||
ENV = 'testing' | ||
TESTING = True | ||
|
||
|
||
class DockerTestConfig(TestingConfig): | ||
SQLALCHEMY_DATABASE_URI = 'postgres://postgres@postgres:5432/scout_test' | ||
|
||
|
||
class TravisConfig(TestingConfig): | ||
SQLALCHEMY_DATABASE_URI = "postgresql://postgres@localhost/travis_ci_test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
Oops, something went wrong.