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

Docker for production #245

Merged
merged 17 commits into from
Oct 17, 2017
Merged

Docker for production #245

merged 17 commits into from
Oct 17, 2017

Conversation

cuducos
Copy link
Collaborator

@cuducos cuducos commented Sep 6, 2017

What is the problem?
Our Docker environment currently is focused on development, so we actually cannot use it to try to enhance our deploy pipeline.

How can this be addressed?
I created a different Docker setups do differ development and production environments:

  1. docker-compose.yml has stuff common for both environments
  2. docker-compose.override.yml (loaded by default) has stuff inherent to a development environment
  3. docker-compose.prod.yml (need to be loaded manually) has stuff inherent to a production environment

Differences between both environment are documented in the new version of the README.md file.

Who could help with this issue?
Anyone willing to test it, but specially @Irio @lipemorais @gomex @pedrommone who have helped us a lot with Docker stuff.

Not so obvious things I would test if I were a code reviewer working on the development environment (eg docker-compose up and checking localhost:8000):

  • Am I able edit a .elm file and (after a while, compilation is not instantaneous) see changes refreshing the browser?
  • Am I able edit a .py or .html file and see changes refreshing the browser?

Basic things I would test in both environment (production loads at localhost:80):

  • Am I able to import files from contrib/data/ using paths like /mnt/data/ inside the container?
  • Test basic search in the main view
  • Test basic search in the API
  • Test basic search in the dashboard

Next steps

  • I removed our custom the images from the docker-compose.yml to make code review easier (otherwise docker-compose would load images from Docker Hub), so if this PR gets approved a new PR is needed to get these images back
  • Work with DNS and HTTPS in the production environment
  • Close Update docker container versions #236 as issues raised there are still unaddressed and this PR basically covers the enhancements proposed there by @Irio (agree?)
  • As elm-doc-test is basically deprecated I removed Elm test suit in 5f47f66 and if this PR goes through I'll open an Issue do we remember to bring it back with the new elm-verify-examples

@lipemorais
Copy link
Contributor

I runned just docker-compose up and got this error. :(

image

So I added the 0.0.0.0 to and I was able to see the expect page of Jarbas.


I'm not sure if this is ok for production environment or can be changed based on environment.


I don't understand why there are 3 and no just 2 Docker compose files, something like docker-compose.yml for development and docker-compose-prod.yml for production environment.


Talking about instructions to run the project with Docker on Readme. The sentence below is missing a up on the end of the command and the word development has a typo. Make sense I open a PR with it?

Develoment: simply running docker-compose … will trigger do ...


I was not able to run the production docker-compose using the command docker-compose -f docker-compose.yml -f docker-compose.prod.yml as suggested in Readme. This is what I got.

➜  jarbas git:(cuducos-production-docker) ✗ docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
ERROR: /Users/felipe/projects/serenata/jarbas/.env is not a file.

@cuducos
Copy link
Collaborator Author

cuducos commented Sep 25, 2017

Wow! Many many thanks for this awesome review : )

Let me try to clarify some parts and recognize my mistakes hahaha…


So I added the 0.0.0.0 to and I was able to see the expect page of Jarbas.

Good point: gonna add 0.0.0.0 to the .env.example — sounds like a good thing to do. Low risk and unblocks that error.


I don't understand why there are 3 and no just 2 Docker compose files, something like docker-compose.yml for development and docker-compose-prod.yml for production environment.

There are things we might wan't on development environment but not in production. And also things I'm not sure how to unset in the hypothetical docker-compose-prod.yml: basically unset volumes.

So the combination docker-compose.yml + docker-composer.override.yml (loaded automatically) refers to the development environment and the combination docker-compose.yml + docker-composer.prod.ymlto the production.


Talking about instructions to run the project with Docker on Readme. The sentence below is missing a up on the end of the command and the word development has a typo. Make sense I open a PR with it?

I don't think it's missing a up. It could be docker-compose up, docker-compose build, docker-compose stop… that's why I used the . The point is the distinction between:

  • docker-compose …
  • docker-compose -f file1.yml -f file2.yml …

I was not able to run the production docker-compose using the command docker-compose -f docker-compose.yml -f docker-compose.prod.yml as suggested in Readme. This is what I got […]

Basically the problem is that now Docker uses the .env file too. So we might remove the bold part in the Settings:

If you are not using Docker copy contrib/.env.sample as .env in the project's root folder and adjust your settings. These are the main variables:


In sum, three pending things to be committed for sure:

  • Fix typo
  • Add 0.0.0.0 to .env.example
  • Fix instructions at the Settings section

And I still would like to hear from you about the 3 files (if we keep override and prod or if we can merge in two files).

@cuducos cuducos force-pushed the cuducos-production-docker branch from cf70be9 to ae8fc0d Compare October 14, 2017 13:58
@cuducos
Copy link
Collaborator Author

cuducos commented Oct 14, 2017

As Elm tests were keeping this PR from going through I removed them by now and suggested (editing the opening post) to create an specific issue to update the test suite (basically move from elm-doc-test to elm-verify-example).

@anaschwendler I addressed some of @lipemorais concerns, held back from other (to which @gomex reacted with a 👍 ) so I think we can move on to actually testing it and core reviewing. If you need help with the tests described in the opening post, LMK.

@anaschwendler
Copy link
Collaborator

anaschwendler commented Oct 15, 2017

Hey @cuducos, I'll be taking a look at this PR now!

What I did to test this PR:

  1. Clone the repository:
$ git clone [email protected]:datasciencebr/jarbas.git
  1. Open the repo folder:
$ cd jarbas
  1. Checkout to @cuducos branch:
$ git checkout -b cuducos-production-docker origin/cuducos-production-docker
  1. Update the branch:
$ git merge master
  1. Copy the .env file:
$ cp contrib/.env.sample env
  1. Build and start services:
$ docker-compose up -d

And works fine:

Creating jarbas_postgres_1 ... 
Creating jarbas_elm_1 ... 
Creating jarbas_elm_1
Creating jarbas_postgres_1 ... done
Creating jarbas_django_1 ... 
Creating jarbas_django_1 ... done
  1. Create the database and apply the migrations:
$ docker-compose run --rm django python manage.py migrate
  1. Seeding it with sample data:
$ docker-compose run --rm django python manage.py reimbursements /mnt/data/reimbursements_sample.xz
$ docker-compose run --rm django python manage.py companies /mnt/data/companies_sample.xz
$ docker-compose run --rm django python manage.py suspicions /mnt/data/suspicions_sample.xz
$ docker-compose run --rm django python manage.py tweets
  1. Access localhost:8000, not working :/ am I doing something wrong?
    image

PS.: I'll be updating the comment as long as I keep it going

README.md Outdated
$ docker-compose run --rm jarbas python manage.py reimbursements /mnt/data/reimbursements_sample.xz
$ docker-compose run --rm jarbas python manage.py companies /mnt/data/companies_sample.xz
$ docker-compose run --rm jarbas python manage.py suspicions /mnt/data/suspicions_sample.xz
$ docker-compose run --rm jarbas python manage.py tweets
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change jarbas to django:

$ docker-compose run --rm django python manage.py reimbursements /mnt/data/reimbursements_sample.xz
$ docker-compose run --rm django python manage.py companies /mnt/data/companies_sample.xz
$ docker-compose run --rm django python manage.py suspicions /mnt/data/suspicions_sample.xz
$ docker-compose run --rm django python manage.py tweets

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

Thanks, @anaschwendler — docs fixed in 7029a89

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

About the error on localhost:8000 you might have forgotten to generate your .env (at least it wasn't clear in your step-by-step). There is a sample config file in contrib/ BTW.

And would you mind sharing the logs and outputs?

@lipemorais
Copy link
Contributor

lipemorais commented Oct 16, 2017

Development environment

  • Elm
    I runned the docker-compose up to use the development environment and I was able to access jarbas home, so I tried to make a change on elm code but it was not reflecting on jarbas home, next I tried to refresh the browser, nothing changed, later I restart all compose again but do not had the expected change on jarbas home. :(
elm_1       | Success! Compiled 195 modules.
elm_1       | Successfully generated /tmp/117916-16-fvqc94.qt0tsurf6r.js
django_1    | [16/Oct/2017 12:43:38] "GET / HTTP/1.1" 200 2560
django_1    | [16/Oct/2017 12:43:38] "GET /static/favicon/favicon-32x32.png HTTP/1.1" 200 2518
elm_1       | [14:43:38] Finished 'elm' after 43 s
elm_1       | Done in 44.37s.
jarbas_elm_1 exited with code 0

I believe that this last line does not sounds good and have a relation with this issue.

  • Python
    I did very similar with Python code and I was able to see Django server restarting and the change was reflected. :)

  • Postgres
    I was able to connect to the database and run migrations. :)

Copy link
Contributor

@lipemorais lipemorais left a comment

Choose a reason for hiding this comment

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

I think that be able to see the elm code changes reflected is very important to make it able to be merged. :)

@@ -1,2 +0,0 @@
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/heroku/heroku-buildpack-python.git
Copy link
Contributor

Choose a reason for hiding this comment

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

Are this build packs related to this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. We first launched Jarbas on Heroku and we considered using Dokku together with Digital Ocean. In both cases the .buildpacks file was required. This PR intends to take Docker Machine as the offical way to deploy Jarbas — so the .builpacks are nor necessary anymore.

README.md Outdated
If you're interesting in having a database full of data you can get the datasets running [Rosie](https://github.com/datasciencebr/rosie).
To add a fresh new `reimbursements.xz` or `suspicions.xz` brewed by [Rosie](https://github.com/datasciencebr/rosie), or a `companies.xz` you've got from the [toolbox](https://github.com/datasciencebr/serenata-toolbox), you just need copy these files to `contrib/data` and refer to them inside the container from the path `/mnt/data/`.

#### Acessing Jabas
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo Jabas

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

I believe that this last line does not sounds good and have a relation with this issue.

Definitively this was not supposed to happen. Can you share the logs for this container?

Why am I saying this definetively wasn't supose to happen IMHO:

  • Dockerfile-elm has CMD ["npm", "run", "watch"]
  • The only two files that might change this behavior are docker-compose.yml and docker-compose.overrideyml but they don't (only in production change it)

So I guess there is an error in the conatiner. And that's why I ask for the logs ; )

@anaschwendler
Copy link
Collaborator

anaschwendler commented Oct 16, 2017

About the error on localhost:8000 you might have forgotten to generate your .env (at least it wasn't clear in your step-by-step). There is a sample config file in contrib/ BTW.

Would you mind if I ask you to put something in the installation like we have in serenata-de-amor ?

Oh @lipemorais already sent the logs, faster than me hehe

@lipemorais
Copy link
Contributor

@cuducos Here are the all logs when I run it.

(.jarbas-env) ➜  jarbas git:(cuducos-production-docker) ✗ docker-compose up
Recreating jarbas_postgres_1 ...
Recreating jarbas_elm_1 ...
Recreating jarbas_elm_1
Recreating jarbas_elm_1 ... done
Recreating jarbas_django_1 ...
Recreating jarbas_django_1 ... done
Attaching to jarbas_postgres_1, jarbas_elm_1, jarbas_django_1
postgres_1  | LOG:  database system was shut down at 2017-10-16 15:50:48 UTC
postgres_1  | LOG:  MultiXact member wraparound protections are now enabled
elm_1       | yarn assets v0.23.4
postgres_1  | LOG:  database system is ready to accept connections
elm_1       | $ gulp elm
postgres_1  | LOG:  autovacuum launcher started
elm_1       | [15:51:15] Using gulpfile /code/gulpfile.js
elm_1       | [15:51:15] Starting 'elm'...
django_1    | Performing system checks...
django_1    |
django_1    | System check identified no issues (0 silenced).
django_1    | October 16, 2017 - 13:51:19
django_1    | Django version 1.11.5, using settings 'jarbas.settings'
django_1    | Starting development server at http://0.0.0.0:8000/
django_1    | Quit the server with CONTROL-C.
elm_1       | Success! Compiled 195 modules.
elm_1       | Successfully generated /tmp/117916-18-216zgc.p5iq0vn29.js
elm_1       | [15:51:51] Finished 'elm' after 36 s
elm_1       | Done in 36.58s.
jarbas_elm_1 exited with code 0

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

@anaschwendler, can you be more specific?

Would you mind if I ask you to put something in the installation like we have in serenata-de-amor?

The README.md in this PR was updated to reflect that, specially the first paragraph of the Settings section. What else could we do to be clearer about it?

@lipemorais: can you rebuild the Elm container to make sure you’re not running a container built for production, not development?

@lipemorais
Copy link
Contributor

@lipemorais: can you rebuild the Elm container to make sure you’re not running a container built for production, not development?

I did it running docker-compose up --build, I'm doing anything wrong.

Recreating d4b8e71e7f1f_jarbas_elm_1 ...
Recreating d4b8e71e7f1f_jarbas_elm_1
Recreating d4b8e71e7f1f_jarbas_elm_1 ... error

ERROR: for d4b8e71e7f1f_jarbas_elm_1  no such image: sha256:52eb9b30dd1644e6a1d2f94271a11f29841b0d2fa819dc42f531a92c4548b8dc: No such image: sha256:52eb9b30dd1644e6a1d2f94271a11f29841b0d2fa819dc42f531a92c4548b8dc

ERROR: for elm  no such image: sha256:52eb9b30dd1644e6a1d2f94271a11f29841b0d2fa819dc42f531a92c4548b8dc: No such image: sha256:52eb9b30dd1644e6a1d2f94271a11f29841b0d2fa819dc42f531a92c4548b8dc
ERROR: Encountered errors while bringing up the project.```

@anaschwendler
Copy link
Collaborator

anaschwendler commented Oct 16, 2017

The README.md in this PR was updated to reflect that, specially the first paragraph of the Settings section. What else could we do to be clearer about it?

Found it!
Copy `contrib/.env.sample` as `.env` in the project's root folder and adjust your settings. These are the main variables: ;)

I will try again

@anaschwendler
Copy link
Collaborator

@cuducos @lipemorais Yep! For me it is working now and look good :)

I guess it is ok to merge, can I @cuducos ? Is there something more that you think about doing?

@lipemorais
Copy link
Contributor

Hey @anaschwendler did tried to change elm code and see it working?

@anaschwendler
Copy link
Collaborator

@lipemorais for it is working fine with elm

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

I did it running docker-compose up --build

@lipemorais you might try docker-compose build --no-cache elm so it really builds from scratch (I mean, downloading official images and building the rest from them, not from cache).

I guess it is ok to merge, can I @cuducos ? Is there something more that you think about doing?

@anaschwendler if it's working (@lipemorais says it isn't) I have nothing else to add.

But in my opening post I described two specific ways to manually tests the development environment and four other specific ways to manually test the production server. From your what I did to test this PR post I've got impression you haven't covered them all.

So even if I tested it locally before opening the PR I'm not confident in giving green light if you have not tested those specific points. Specially when @lipemorais tried to and failed. So there might be more work to do, but I do need your help to find out what I got wrong.

@lipemorais
Copy link
Contributor

lipemorais commented Oct 16, 2017

@lipemorais you might try docker-compose build --no-cache elm so it really builds from scratch (I mean, downloading official images and building the rest from them, not from cache).

This approach do not worked for me. :/
But run docker-compose rm && docker-compose up worked fine.

The point now is that elm container starts to watch butd o not continue alive to keep watching.

django_1    | [16/Oct/2017 18:15:19] "GET / HTTP/1.1" 400 61868
elm_1       | [20:15:43] Finished 'elm' after 41 s
elm_1       | [20:15:43] Starting 'watch'...
elm_1       | [20:15:43] Finished 'watch' after 9.77 ms
django_1    | [16/Oct/2017 18:15:48] "GET / HTTP/1.1" 200 2560
django_1    | [16/Oct/2017 18:15:48] "GET /static/app.js HTTP/1.1" 200 217820
django_1    | [16/Oct/2017 18:16:17] "GET / HTTP/1.1" 200 2560
django_1    | [16/Oct/2017 18:16:17] "GET /static/app.js HTTP/1.1" 304 0
django_1    | [16/Oct/2017 18:16:17] "GET /static/favicon/favicon-32x32.png HTTP/1.1" 200 2518
django_1    | [16/Oct/2017 18:16:32] "GET / HTTP/1.1" 200 2560
django_1    | [16/Oct/2017 18:16:32] "GET /static/app.js HTTP/1.1" 304 0
django_1    | [16/Oct/2017 18:16:32] "GET /static/favicon/favicon-32x32.png HTTP/1.1" 200 2518
elm_1       | [20:16:57] Starting 'elm'...
django_1    | [16/Oct/2017 18:17:19] "GET / HTTP/1.1" 200 2560
django_1    | [16/Oct/2017 18:17:19] "GET /static/app.js HTTP/1.1" 304 0
django_1    | [16/Oct/2017 18:17:19] "GET /static/favicon/favicon-32x32.png HTTP/1.1" 200 2518
elm_1       | [20:17:25] Finished 'elm' after 28 s

It starts and finish for some reason:

elm_1       | [20:15:43] Starting 'watch'...
elm_1       | [20:15:43] Finished 'watch' after 9.77 ms

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 16, 2017

But the point now is that elm container starts do not continue.

I'm not sure what you mean there… I don't remember the proper outputs by heart, but Finished 'elm' after 28 s is kind of acceptable if changing a .elm file triggers the re-rendering of the Elm app… does that happens?

@lipemorais
Copy link
Contributor

It's alive!

It worked here and I able to see it working fine.

What I mentioned before about finishing log is a normal behaviour as @cuducos just said.

@cuducos
Copy link
Collaborator Author

cuducos commented Oct 17, 2017

giphy-downsized-large

@anaschwendler
Copy link
Collaborator

Last check and I'll merge!

@anaschwendler
Copy link
Collaborator

image

🎉

@anaschwendler anaschwendler merged commit 62ae6cb into master Oct 17, 2017
@anaschwendler anaschwendler deleted the cuducos-production-docker branch October 17, 2017 16:45
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.

3 participants