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

Docker db decouple #89

Merged
merged 3 commits into from
Oct 9, 2019
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
86 changes: 14 additions & 72 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,20 @@
FROM debian:latest
FROM tiangolo/meinheld-gunicorn-flask:python3.7

LABEL authors="[email protected],[email protected]" \
description="Docker image running MegaQC"

# Install container-wide requrements
RUN apt-get update && apt-get install git -y && \
apt-get install python2.7 -y && \
apt-get install python2.7-dev -y && \
apt-get install libyaml-dev -y && \
apt-get install libffi-dev -y && \
apt-get install libpng-dev -y && \
apt-get install libfreetype6-dev -y && \
apt-get install curl -y && \
apt-get install gcc -y && \
apt-get install g++ -y && \
apt-get install apache2 -y

# Enable apache mod_proxy
RUN a2enmod proxy
RUN a2enmod proxy_http

# Overwrite apache config
RUN echo "<VirtualHost *:80> \n\
ServerName megaqc \n\
ProxyPass / http://127.0.0.1:8000/ \n\
ProxyPassReverse / http://127.0.0.1:8000/ \n\
</VirtualHost>" > /etc/apache2/sites-enabled/000-default.conf

# Fix matplotlib being dumb
RUN ln -s /usr/include/freetype2/ft2build.h /usr/include/

# Link python
RUN ln -s /usr/bin/python2.7 /usr/bin/python

# Install pip
RUN curl -fsSL https://bootstrap.pypa.io/get-pip.py -o /opt/get-pip.py && \
python /opt/get-pip.py && \
rm /opt/get-pip.py

# Install PostgreSQL and psycopg2
RUN apt-get install postgresql-9.6 postgresql-server-dev-9.6 -y

# Set data directory
ENV PGDATA /usr/local/lib/postgresql

# Tell MegaQC to use postgres / psycopg2
ENV MEGAQC_PRODUCTION 1

# create the data directory
RUN mkdir $PGDATA
RUN chown postgres $PGDATA
# Start postgres
# Create the basic requirements
RUN su postgres -c "/usr/lib/postgresql/9.6/bin/initdb" && \
su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D $PGDATA -w start" && \
su postgres -c "/usr/lib/postgresql/9.6/bin/createuser megaqc_user" && \
su postgres -c "/usr/lib/postgresql/9.6/bin/createdb megaqc -O megaqc_user" && \
su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D $PGDATA -w stop"

# Install MegaQC
COPY . MegaQC
WORKDIR MegaQC
RUN python setup.py install

# Set up the Postgres SQL server
RUN su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D $PGDATA -w start" && \
megaqc initdb && \
su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D $PGDATA -w stop"

# Use volumes to persist logs and data
VOLUME ["/var/log/postgresql", "/usr/local/lib/postgresql"]

# Run the MegaQC server
EXPOSE 80
CMD su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D $PGDATA -w start" && \
service apache2 start && \
gunicorn megaqc.wsgi:app --timeout 300
ENV MEGAQC_PRODUCTION=1 \
MEGAQC_SECRET="SuperSecretValueYouShouldReallyChange" \
MEGAQC_CONFIG="" \
APP_MODULE=megaqc.wsgi:app\
DB_HOST="127.0.0.1" \
DB_PORT="5432" \
DB_NAME="megaqc" \
DB_USER="megaqc" \
DB_PASS="megaqcpswd"

COPY . /app

RUN python /app/setup.py install
9 changes: 6 additions & 3 deletions megaqc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ def update_db_uri(self):
self.SQLALCHEMY_DATABASE
)


class ProdConfig(Config):
"""Production configuration."""

ENV = 'prod'
DEBUG = False
SQLALCHEMY_DBMS = 'postgresql'
SQLALCHEMY_USER = 'megaqc_user'
SQLALCHEMY_HOST = 'localhost:5432'
SQLALCHEMY_DATABASE = 'megaqc'
SQLALCHEMY_HOST = "{}:{}".format(os.environ.get(
'DB_HOST', 'localhost'), os.environ.get('DB_PORT', '5432'))
SQLALCHEMY_USER = os.environ.get('DB_USER', 'megaqc')
SQLALCHEMY_PASS = os.environ.get('DB_PASS', 'megaqcpswd')
SQLALCHEMY_DATABASE = os.environ.get('DB_NAME', 'megaqc')
DEBUG_TB_ENABLED = False # Disable Debug toolbar

def __init__(self):
Expand Down
71 changes: 37 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,45 @@
"Flask-Caching>=1.0.0",
"Flask-DebugToolbar>=0.10.1",
"Flask-Login>=0.4.0",
"Flask-SQLAlchemy==2.2",
"Flask-WTF==0.14.2",
"Flask-SQLAlchemy>=2.2",
"Flask-WTF>=0.14.2",
"Flask==1.0.2",
"future==0.16.0",
"itsdangerous>=0.24",
"Jinja2>=2.9.5",
"markdown>=2.6.11",
"numpy==1.14.3",
"multiqc>=1.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

"numpy>=1.14.3",
"passlib==1.7.1",
"plotly==2.0.15",
"pyyaml==3.12",
"pyyaml>=3.12",
"SQLAlchemy>=1.1.5",
"Werkzeug==0.14.1",
"Werkzeug>=0.14.1",
"WTForms>=2.1",

# Testing
"pytest==3.0.6",
"WebTest==2.0.26",
"factory-boy==2.8.1",
"livereload==2.5.1",
"pytest>=3.0.6",
"WebTest>=2.0.26",
"factory-boy>=2.8.1",
"livereload>=2.5.1",

# Lint and code style
#"flake8==3.3.0",
#flake8-blind-except==0.1.1",
#"flake8-debugger==1.4.0",
#"flake8-docstrings==1.0.3",
#"flake8-isort==2.1.3",
#"flake8-quotes==0.9.0",
#"isort==4.2.5",
#"pep8-naming==0.4.1",
# "flake8==3.3.0",
# flake8-blind-except==0.1.1",
# "flake8-debugger==1.4.0",
# "flake8-docstrings==1.0.3",
# "flake8-isort==2.1.3",
# "flake8-quotes==0.9.0",
# "isort==4.2.5",
# "pep8-naming==0.4.1",
]

prod_reqs = dev_reqs + [
"psycopg2-binary>=2.6.2",
"gunicorn>=19.7.1",
]
install_requires = prod_reqs if os.environ.get('MEGAQC_PRODUCTION') else dev_reqs
install_requires = prod_reqs if os.environ.get(
'MEGAQC_PRODUCTION') else dev_reqs


print("""-----------------------------------
Expand All @@ -67,22 +69,23 @@
""".format(version))

setup(
name = 'megaqc',
version = version,
author = 'Phil Ewels',
author_email = '[email protected]',
description = "Collect and visualise data across multiple MultiQC runs",
long_description = __doc__,
keywords = ['bioinformatics', 'biology', 'sequencing', 'NGS', 'next generation sequencing', 'quality control'],
url = 'https://megaqc.info/',
download_url = 'https://github.com/ewels/MegaQC/releases',
license = 'GPLv3',
packages = ['megaqc'],
include_package_data = True,
zip_safe = False,
scripts = ['scripts/megaqc'],
install_requires = install_requires,
classifiers = [
name='megaqc',
version=version,
author='Phil Ewels',
author_email='[email protected]',
description="Collect and visualise data across multiple MultiQC runs",
long_description=__doc__,
keywords=['bioinformatics', 'biology', 'sequencing', 'NGS',
'next generation sequencing', 'quality control'],
url='https://megaqc.info/',
download_url='https://github.com/ewels/MegaQC/releases',
license='GPLv3',
packages=['megaqc'],
include_package_data=True,
zip_safe=False,
scripts=['scripts/megaqc'],
install_requires=install_requires,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
Expand Down