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

Dockerize #97

Merged
merged 16 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
.github
.gitignore
.travis.yml
mkdocs.yml
docs
tests
Dockerfile
docker-compose.yml
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [] -
## [1.3] - 2020.10.25
### Added
- Created deployment WSGI file
- Cython requirement
- Dockerfiles for backend and frontend


## [1.2] - 2020.10.19
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ git clone https://github.com/Clinical-Genomics/cgbeacon2.git

Change directory to the cloned folder and from there, install the software using the following command:
```
pip install -r requirements.txt
pip install -e .
```

Expand Down
2 changes: 1 addition & 1 deletion cgbeacon2/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2"
__version__ = "1.3"
7 changes: 6 additions & 1 deletion cgbeacon2/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def create_app():
LOG.warning("Please add database settings param in your config file.")
quit()

client = MongoClient(app.config["DB_URI"])
# If app is runned from inside a container, override host port
db_uri = app.config["DB_URI"]
if os.getenv("MONGODB_HOST"):
db_uri=f"mongodb://{os.getenv('MONGODB_HOST')}:{'27017'}/{'cgbeacon2'}"

client = MongoClient(db_uri)
app.db = client[app.config["DB_NAME"]]
LOG.info("database connection info:{}".format(app.db))

Expand Down
18 changes: 18 additions & 0 deletions containers/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.8-alpine3.12

Copy link

Choose a reason for hiding this comment

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

Suggested change
LABEL maintainer="Chiara Rasi <chiara.rasi@scilifelab.se>"

You could also add some more labels here to describe the container. Have a look at @jemten and @henrikstranneheim examples in MIP for inspiration

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll check, thanks!

MAINTAINER Chiara Rasi

RUN apk update
RUN apk add make automake gcc g++ linux-headers curl libcurl curl-dev \
zlib-dev bzip2-dev xz-dev libffi-dev curl libressl-dev bash \
&& rm -rf /var/cache/apk/*s

WORKDIR /home/worker/app
COPY . /home/worker/app

RUN pip install -r requirements.txt
RUN pip install -e .

RUN adduser -D worker
RUN chown worker:worker -R /home/worker
USER worker
7 changes: 7 additions & 0 deletions containers/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM northwestwitch/cgbeacon2:latest
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm hosting the image on my docker hub now because I don't have access to the clinicalgenomics one, but I plan to move the images there


MAINTAINER Chiara Rasi

EXPOSE 5000

CMD cgbeacon2 run --host 0.0.0.0
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3'
northwestwitch marked this conversation as resolved.
Show resolved Hide resolved
# usage:
# sudo docker-compose build
# sudo docker-compose up
services:
mongodb:
image: mvertes/alpine-mongo
container_name: mongodb
ports:
- '27017:27017'
expose:
- '27017'

beacon-cli:
environment:
MONGODB_HOST: mongodb
image: northwestwitch/cgbeacon2
container_name: beacon-cli
links:
- mongodb
command: bash -c 'cgbeacon2 add demo'

beacon-web:
environment:
MONGODB_HOST: mongodb
image: northwestwitch/cgbeacon2
container_name: beacon-web
links:
- mongodb
expose:
- '5000'
ports:
- '5000:5000'
command: bash -c 'cgbeacon2 run --host 0.0.0.0'
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ PyJWT
# utils
cyvcf2
pybedtools
pysam<0.16 #Avoid ImportError: libchtslib.cpython-35m-x86_64-linux-gnu.so
northwestwitch marked this conversation as resolved.
Show resolved Hide resolved
jsonschema
cython
24 changes: 0 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@

here = os.path.abspath(os.path.dirname(__file__))

def parse_reqs(req_path='./requirements.txt'):
northwestwitch marked this conversation as resolved.
Show resolved Hide resolved
"""Recursively parse requirements from nested pip files."""
install_requires = []
with io.open(os.path.join(here, 'requirements.txt'), encoding='utf-8') as handle:
# remove comments and empty lines
lines = (line.strip() for line in handle
if line.strip() and not line.startswith('#'))

for line in lines:
# check for nested requirements files
if line.startswith('-r'):
# recursively call this function
install_requires += parse_reqs(req_path=line[3:])

else:
# add the line as a new requirement
install_requires.append(line)

return install_requires

# What packages are required for this module to be executed?
REQUIRED = parse_reqs()

# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
Expand Down Expand Up @@ -106,7 +83,6 @@ def run(self):
download_url = '/'.join([URL,'tarball',version]),
keywords = KEYWORDS,
packages=find_packages(),
install_requires=REQUIRED,
include_package_data=True,
license=LICENSE,
classifiers=[
Expand Down
19 changes: 18 additions & 1 deletion tests/server/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,22 @@
def test_create_app_from_envar(monkeypatch):
"""Test option to create app from a file specified by an environment variable"""

# GIVEN a a config file defined in the environment
monkeypatch.setenv("CGBEACON2_CONFIG", config_file_path, prepend=False)
assert create_app()
# THEN the app should connect to a database on localhost, port 27017 as defined on config file
app = create_app()
assert app
db_attrs = str(vars(app.db)) # convert database attributes to string
assert "host=['127.0.0.1:27017']" in db_attrs


def test_create_app_in_container(monkeypatch):
"""Test creating app from inside a container, when an env varianble named 'MONGODB_HOST' is present to modify the hosr provided in config file"""

# GIVEN an env var named MONGODB_HOST
monkeypatch.setenv("MONGODB_HOST", "mongodb")
# THEN the app should connect to a mongo host named mongodb on port 27017
app = create_app()
assert app
db_attrs = str(vars(app.db)) # convert database attributes to string
assert "host=['mongodb:27017']" in db_attrs