Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Make Docker great again #163

Merged
merged 13 commits into from
May 17, 2017
Merged

Make Docker great again #163

merged 13 commits into from
May 17, 2017

Conversation

lipemorais
Copy link
Contributor

@lipemorais lipemorais commented May 10, 2017

This is in progress, I just created it earlier to have earlier feedbacks.

What is the purpose of this Pull Request?
The purpose of this PR is make easier contribute and develop for Jarbas using docker-compose and docker.

What was done to achieve this purpose?
Initially I fixed elm dockerfile to make docker work again for development with Jarbas. I have below a list of things to be done to make it ideal.

How to test if it really works?
make run.devel

Who can help reviewing it?
@gomex @Irio @anaschwendler @jtemporal @cuducos

What is out of scope
Is out of scope make this docker-compose ready for production environment, I'm planing to work on it in a next PR.

TODO

  • Fixes static files in rest framework front end
  • Create a jarbas-frontend image in docker hub
  • Update Jarbas image in docker hub
  • Improve documentation for Docker images
  • Update docker-compose.yml to use new images

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling ba55e58 on lipemorais:master into ** on datasciencebr:master**.

@cuducos
Copy link
Collaborator

cuducos commented May 10, 2017

I really liked that:

Is out of scope make this docker-compose ready for production environment

Not because I'm kind of against Docker on production, but because… baby steps and focus!

But there's also something I don't like: make run.devel. Why? It leaves Windows users out. It's OK to have some shortcuts set but the documentation and public discussions should be Windows friendly too.

But so far so good ; )

Some questions:

  • Do we have a kind of diagnostic of why Docker is not working properly in development?
  • Changing yarn installation is just an enhancement or is it relevant to the purpose? I do not want to discourage enhancements, just want to learn from your PR ; )

@lipemorais
Copy link
Contributor Author

But there's also something I don't like: make run.devel. Why? It leaves Windows users out. It's OK to have some shortcuts set but the documentation and public discussions should be Windows friendly too.

I am not a Windows user for a long time. Do you have any tip how could be it Windows friendly?

Do we have a kind of diagnostic of why Docker is not working properly in development?
Changing yarn installation is just an enhancement or is it relevant to the purpose? I do not want to discourage enhancements, just want to learn from your PR ; )

Both questions are related. There were a chain of problems in Dockerfile-elm. To isolate the problem I built Dockerfile-elm alone using docker build -f Dockerfile-elm -t jelm .

  1. The first one was use sudo as in RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - there is no /usr/bin/sudo in the image node:6.9.1. So every place that had sudo was necessary remove it. To solve this I removed every sudo in this file. The error is below:
➜  jarbas git:(a2b2fe2) ✗ docker build -f Dockerfile-elm -t jelm .
Sending build context to Docker daemon 181.3 MB
Step 1/13 : FROM node:6.9.1
 ---> 00673888c33c
Step 2/13 : RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
 ---> Running in 956480ca67dc
/bin/sh: 1: sudo: not found
curl: (23) Failed writing body (768 != 1369)
The command '/bin/sh -c curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -' returned a non-zero code: 127
  1. The following problem was that running apt-get update was not able to finding /usr/lib/apt/methods/https. Investigating a little more I found a solution that was like
// Dockerfile-elm
FROM node:6.9.1

RUN apt-get update
RUN apt-get install -y apt-transport-https
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get install -y yarn
...

what I think that is not elegant, so I investigate a little more and found a second solution to install yarn using npm instead of apt-get that looks good enough, so I used it.

This is the error that I found:

➜  jarbas git:(a2b2fe2) ✗ docker build -f Dockerfile-elm -t jelm .
Sending build context to Docker daemon 181.3 MB
Step 1/13 : FROM node:6.9.1
 ---> 00673888c33c
Step 2/13 : RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
 ---> Using cache
 ---> ccc588b913d0
Step 3/13 : RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
 ---> Using cache
 ---> ccc30a8feaa4
Step 4/13 : RUN apt-get update
 ---> Running in 72d991e6c27e
E: The method driver /usr/lib/apt/methods/https could not be found.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
  1. But this doesn't make yarn available in the PATH so I was using yarn with the complete path /node_modules/yarn/bin/yarn.js everywhere. To solve this a created a symbolic link RUN ln -s /node_modules/yarn/bin/yarn.js /usr/bin/yarn.

After this tree step I achieved this PR.

@cuducos
Copy link
Collaborator

cuducos commented May 10, 2017

Wow… thank you so much for the explanation! So far so good ; )

@cuducos
Copy link
Collaborator

cuducos commented May 10, 2017

I am not a Windows user for a long time. Do you have any tip how could be it Windows friendly?

Me neither (since 2002 BTW) but I wrapping commands in a Makefile because they would only work in Linux and macOS. In sum make devel.run is just a shortcut for these commands that end up working in Windows too:

docker-compose up -d --build
docker-compose run --rm jarbas python manage.py ceapdatasets
docker-compose run --rm jarbas python manage.py migrate
docker-compose run --rm jarbas python manage.py collectstatic --no-input

We can keep the Makefile, but when offering instructions it's good to be more open ; )

@lipemorais
Copy link
Contributor Author

lipemorais commented May 11, 2017

I will take a look at this others PRs and see how I can use them to improve this one.

Does it worked for anyone? @cuducos @anaschwendler @jtemporal @Irio ?

@cuducos
Copy link
Collaborator

cuducos commented May 12, 2017

Does it worked for anyone?

I haven't tested it throughly (I mean, clean staticfiles/, edit Elm files etc.) but it looks like it works ; )

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 15ab50e on lipemorais:master into ** on datasciencebr:master**.

@lipemorais
Copy link
Contributor Author

lipemorais commented May 12, 2017

I added one more change reusing the shared volume between the containers assets to make rest_framework assets available through NGINX. Fixing the first point of the TODO list.

If more explanation is needed to understand which was my approach to solve this issue please, just let me know.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 63529dd on lipemorais:master into ** on datasciencebr:master**.

…omated docker image builds"

This reverts commit 63529dd.
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling ed7a711 on lipemorais:master into ** on datasciencebr:master**.

… of docker-compose will set the right configurarions
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 40a939a on lipemorais:master into ** on datasciencebr:master**.

…more since environment variables are now given through docker-compose or sytem environment variables
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3b73256 on lipemorais:master into ** on datasciencebr:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fd09172 on lipemorais:master into ** on datasciencebr:master**.

@lipemorais
Copy link
Contributor Author

I made a test to solve the TODO list points 2 and 3, about use images and not build it every time. To do this I made 3 docker images for Jarbas, Frontend and NGINX that were the images constructed after run docker-compose.

If you want to take a look:
https://hub.docker.com/r/felipedemorais/auto-jarbas/
https://hub.docker.com/r/felipedemorais/auto-jarbas-frontend/
https://hub.docker.com/r/felipedemorais/aut-jarbas-nginx/

The next step is have this 3 images in Data Science Brigade Docker Hub: https://hub.docker.com/u/datasciencebr/

A second point in this PR is move .env from jarbas dockerfile to docker-compose so the environment variables can be passed through docker-compose make the application adapt itself at each environments(development, production, ...).

@cuducos
Copy link
Collaborator

cuducos commented May 14, 2017

I'm getting ImportError: No module named 'whitenoise' — probably because the master branch when you forked was using WhiteNoise for static files. I reverted it and it fixed the issue — it's working! Can you merge ae6a32c into your branch?

@lipemorais
Copy link
Contributor Author

I'm getting ImportError: No module named 'whitenoise' — probably because the master branch when you forked was using WhiteNoise for static files.

But I do not have any lead of whitenoise in my fork.
There is any way that I could reproduce this error?

I reverted it and it fixed the issue — it's working! Can you merge ae6a32c into your branch?

I can merge it, of course. How can I apply this changes?

@cuducos
Copy link
Collaborator

cuducos commented May 14, 2017

Wow… so I might have messed up the branches here. Never mind. Do you want access to our DockerHub or would you like to help me setting this up?

@lipemorais
Copy link
Contributor Author

If prefer the second option of empower you, so more than people than me hold this knowledge. Sounds good to you @cuducos ?

@cuducos
Copy link
Collaborator

cuducos commented May 14, 2017

Hell yeah 🤘

Copy link
Collaborator

@cuducos cuducos left a comment

Choose a reason for hiding this comment

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

Added some inline comments. Hope they're helpful. Besides them se might delete staticfiles volume (lines 67-68) that seems unused…

@@ -3,7 +3,6 @@ COPY requirements.txt /requirements.txt
RUN python -m pip install -U pip
RUN python -m pip install -r requirements.txt
RUN apt-get update && apt-get install -y postgresql postgresql-contrib
Copy link
Collaborator

Choose a reason for hiding this comment

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

In theory we were installing PostgreSQL because pyscopg2 (PostgreSQL driver for Python) needs one or other library that comes with PostgreSQL. If this apt-get is coming after pip this might not be necessary anymore.

TLDR IMHO we can get rid of line 5

- "./:/code"
- ".env:/code/.env"
environment:
- SECRET_KEY=lets-rock
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's extremely unsafe to use this for production. As the focus is development environment this is not a problem right now… but I decided to let this note here so we can (later) take care of that and of GOOGLE_STREET_VIEW_API_KEY ; )

@anaschwendler
Copy link
Collaborator

Hi @lipemorais !
Thanks for the contribuition :)
I'm only taking a look to this PR by now, but I'm not the best person to talk about Docker but @cuducos is updating us with everything and I will try to run this later and give you feedback :)

@@ -1,5 +1,5 @@
run.jarbas:
docker-compose up -d --build
docker-compose up -d
Copy link
Collaborator

Choose a reason for hiding this comment

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

We must reflect this change in README.md before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed: 8b73b79

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8b73b79 on lipemorais:master into ** on datasciencebr:master**.

@cuducos
Copy link
Collaborator

cuducos commented May 16, 2017

I tested it more today. It works beautifully for development — hell yeah, many many thanks, @lipemorais!

Before merging we would like to see some bugs and issues squashed:

  • Google Street Views are not showing because I couldn't find a way to insert my API key (sensitive data): can we find a way to do it and mention it on the README.md
  • Say I just have a freshly reimbursements.xz that Rosie brewed this morning: how can I pass this file (originally saved in my local/host machine) to be processed by Django in the container (something like docker-compose run --rm jarbas python manage.py reimbursements -d /tmp/serenata-data/reimbursements.xz in which /tmp/serenata-data/refers to local/host file system)? This should be contemplated in the README.md too
  • Update images URLs to point to our images at Docker Hub

Is this feasible?

@lipemorais
Copy link
Contributor Author

It's completely feasible.
I just did the third point right here: f60ea8e

I will work on the next points soon.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f60ea8e on lipemorais:master into ** on datasciencebr:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1cdab6d on lipemorais:master into ** on datasciencebr:master**.

@lipemorais
Copy link
Contributor Author

lipemorais commented May 17, 2017

Theoretically is just export GOOGLE_STREET_VIEW_API_KEY=your-google-api-key, so docker compose will get it from envvar with the same name.
This is not a automatic way but in order to make it be explicit and safe I see this as the easiest way to handle it give that this is a sensitive data.

As I do not have a Api Key I'm just base in docker-compose documentation in: https://docs.docker.com/compose/environment-variables/#passing-environment-variables-through-to-containers

@cuducos, when you have break could you try it?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f2a6f31 on lipemorais:master into ** on datasciencebr:master**.

@lipemorais
Copy link
Contributor Author

About the second point it's not a big change since the file is inside the project folder, everything works very similar. I added some a instruction in README.md just to make it clearer and more explicit.

I also exposed the port 5432 of db container to make possible connect in the database using a postgres client.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f2a6f31 on lipemorais:master into ** on datasciencebr:master**.

@cuducos cuducos merged commit c224085 into okfn-brasil:master May 17, 2017
@cuducos
Copy link
Collaborator

cuducos commented May 17, 2017

Sweet! Many many thanks for all that, @lipemorais!

@cuducos cuducos changed the title [WIP] Make Docker great again Make Docker great again May 17, 2017
@gomex
Copy link
Contributor

gomex commented May 18, 2017

I loved the PR! Thanks @lipemorais

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants