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

Dockerize #97

merged 16 commits into from Oct 27, 2020

Conversation

northwestwitch
Copy link
Member

@northwestwitch northwestwitch commented Oct 26, 2020

This PR adds a minimal Dockerfile that allows to build both the frontend and the backend of this app.

fix #96

The code in the Dockerfile is the following:

FROM python:3.8-alpine3.12

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

It basically just installs all the requirements and the beacon on a container and then instructs to run any commands as a non-root user.

I've reasoned that since both frontend and backend belong to the same app they should share this basic module.

The additional layers such as the mongodb connection and the specific instructions might also be added in a modular way. At this regard I've included a docker-compose with a complete demo of the app that does the following:

  • Instantiates and runs a mongodb
  • Adds a container with the backend that adds demo data to the database
  • Runs a server on localhost:5000 allowing requests from outside the container.

How to prepare for test:

  • Have installed docker and docker-compose
  • clone this repo branch on a local computer and cd to cgbeacon2

How to test:

  • Stop eventual mongodb database running on your local machine
  • Run the demo using the following command:
    docker-compose up
  • From another terminal, send a request to the / endpoint of the app:
    curl -X GET 'http://127.0.0.1:5000/apiv1.0/

Expected outcome:

  • When running docker-compose there should be 3 container created: mongodb, beacon-cli, and beacon-web.
  • mongodb container should successfully create the database, running on port 27017
  • beacon-cli should be able to connect and populate database with data
  • beacon-web should be able to connect, accept incoming requests and send responses
  • The request sent from the other terminal should receive a response from the containers server.

Review:

  • Code approved by
  • Tests executed by CR

This version is a:

  • MAJOR - when you make incompatible API changes
  • MINOR - when you add functionality in a backwards compatible manner
  • PATCH - when you make backwards compatible bug fixes or documentation/instructions

@northwestwitch
Copy link
Member Author

northwestwitch commented Oct 26, 2020

Hi @eriksjolund and @moonso. I know you're working with dockerizing other repos for the new server. Could you take a look at this PR and tell me what you think of my solution? Any suggestions?

Another way of doing it is creating 2 Dockerfiles based on mongo, one for the backend and one for the frontend, but I like the modularity..

@northwestwitch
Copy link
Member Author

northwestwitch commented Oct 26, 2020

Tests:

Start the docker-compose and get all 3 containers to work and do what they should do: 🆗

image
image
image

Database gets populated with data: 🆗
image

Sending a request from another terminal should trigger a response: 🆗
image

@@ -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

Copy link

@moonso moonso left a comment

Choose a reason for hiding this comment

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

Great @northwestwitch !! I had some comments but everything looks awesome


Run the containers and open an interactive shell for the backend by typing:
```
docker-compose run beacon-cli /bin/bash
Copy link

Choose a reason for hiding this comment

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

Suggested change
docker-compose run beacon-cli /bin/bash
docker-compose run -d beacon-cli

You can use -d to run the container in background. Also you could add

CMD ["/bin/bash"]

to the Dockerfile instead

Copy link
Member Author

Choose a reason for hiding this comment

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

If I include the CMD command in the Dockerfile it's not usable any more for launching the server.

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 can't use -d here because then it won't be interactive any more. I'd just get the ID of the image and I won't be able to type and run commands in the shell

- A working instance of **MongoDB**. From the mongo shell you can create a database using this syntax:

<a name="docker"></a>
## Installing and running the app using Docker
Copy link

Choose a reason for hiding this comment

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

It would be nice if there was some test data and instruction for how to populate the database for testing only

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I'll add the command to load the demo data!

Copy link
Member Author

Choose a reason for hiding this comment

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

The command to load the data is actually already included in the demo, but I'll comment about it in the readme and the docs

@@ -0,0 +1,15 @@
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!

docker-compose.yml Show resolved Hide resolved
@@ -0,0 +1,115 @@
## Setting up a server from a Docker image
Copy link

Choose a reason for hiding this comment

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

Very nice! Again the test data would be nice here as well

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

docs/env_install.md Show resolved Hide resolved
requirements.txt Show resolved Hide resolved
setup.py Show resolved Hide resolved
@northwestwitch northwestwitch merged commit d3dff09 into master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move the app to docker
2 participants