emanchado / narrows

Online storytelling system
http://hardcorenarrativist.org/narrows/
BSD 3-Clause "New" or "Revised" License
113 stars 7 forks source link

Dockerfile and docker-compose #4

Closed interlock closed 7 years ago

interlock commented 7 years ago

So I love this concepts but my first run at it was a little frustrating the setup. Most of that is sorted now, but I figured some people would appreciate a simple way to get things going and see what Narrows is all about. With that in mind, I create a simple Dockerfile and docker-compose.yaml to get people going.

As the update to the readme says, not suitable for hosting at the moment. I am working towards that myself and can push a patch when it is sorted out.

emanchado commented 7 years ago

Thank you so much! I wanted to make a Dockerfile myself but I never found the time, and I have very little experience with it anyway.

I'll review and test it out a bit when I can (I might not get the chance until late next week). When the time comes for merge, do you mind if I squash all commits into one? I'll try to keep all information in the commit messages when I do so.

interlock commented 7 years ago

Yay! Also, I was lazy not to squash in the first place. I'll do that in the mean time :-)

I am going to have another PR that will support more than sendmail. Docker and sendmail are not friends.

emanchado commented 7 years ago

OK, I finally had a moment to try this out. As it's not (yet) a production-ready configuration, and has the possible problem with having to run by hand the docker-compose start narrows afterwards... do you mind moving it to a new directory contrib or similar? I'm unsure if that will break stuff because of changed paths and such.

I can take care of the changes in the README if you want to do the contrib thing (I'll probably move your notes inside the Installation section and tweak them a bit).

interlock commented 7 years ago

Thanks for the feedback. I think I have addressed the need for a second docker-compose start narrows by using pm2 to start narrows. I should of updated the readme to reflect that.

I can adjust the PR to move the Dockerfile and docker-compose.yml to contrib, but I think it makes sense to keep the .dockerignore in the repo root? It is possible to specify an ignore in an alt path, but it complicates docker build and any docker-compose that builds.

Or, since it does work proper now maybe not needed. I am running it in production like settings with the submitted files. I do have a branch that updates nodemailer and allows env configuration of sending mail so I can use an external smtp server. That PR is coming, but I haven't tested it for regressions in using local sendmail yet.

emanchado commented 7 years ago

Sounds good! I wouldn't want to break compatibility with the mail sending thing for whoever may have installed NARROWS already. But if you PR will support both, that's great.

If the Docker setup is going to end up being production-quality then I would leave the files in the root folder, or wherever it's normal to have them. The only issue I have is that I'm not currently using Docker so I'm afraid I may break things in the future... But let's run with it and see how it goes.

emanchado commented 7 years ago

Oh, BTW, I can help you test for sendmail regressions.

emanchado commented 7 years ago

Any news on this BTW?

interlock commented 7 years ago

Ah shoot! Sorry life has carried me away :-)

I've been running narrows in a docker compose for nearly a month now. I have a few tweaks to apply back to my branch/PR and some documentation to update.

I'll even test sendmail (friend suggested I stub sendmail on my system to test, great idea). I should mention I don't think sendmail in a docker container should ever be done, so in the docker-compose setup we'll require smtp credentials. That's fairly common in docker.

emanchado commented 7 years ago

Sounds amazing, looking forward to it!

Regarding the sendmail stuff, the only thing I want to avoid is breaking current installations (like mine, TBH). It's ok if the Docker version requires an external SMTP server.

interlock commented 7 years ago

I believe this covers it. Give it a whirl and let me know if you hit any issues.

Tested sendmail locally and it worked!

I have been running the dockerfile/compose in "production" for a month now with some local modifications for my setup.

Feel free to rebase this one :-)

emanchado commented 7 years ago

Excellent! I've tried a bit and the sendmail fallback seems to work fine (although now NARROWS needs Node >= 6 because of the updated Nodemailer dependency).

Can you help me test something? The config module has a standard way to mark which environment variables override which settings, and I've tried to use that (see commit f86097e4f1574bdcce5648678bd6a28a2d84dcc2)... but I'm struggling to understand how to pass environment variables to Docker/Docker-compose. Can you have a look at my dockerize branch and see if it works? If that works, I imagine config/docker.js should be modified to use the same override system.

interlock commented 7 years ago

I merged your change in and updated it for all appropriate env variables.

In terms of passing env variables to docker-compose, you will want to add them to the environment section OR add an env_file. See here for how to use both: https://docs.docker.com/compose/environment-variables/

If you were running the docker image straight up there are similar ways to pass environment configurations via the CLI or file.

emanchado commented 7 years ago

Bah, I have tried again from scratch with the .env file (in a different machine) but it still doesn't work for me: I'm trying to pass NODEMAILER but it still complains that there's no sendmail.

I'm trying to pass the -e switch to create or up but they don't seem to accept it. Have you actually tested it and can confirm it works? In any case, it would be nice to have instructions in the README about how to actually pass the environment variables to the commands documented in there (the create and the up -d).

Sorry, Docker still feels like a big mystery to me :-(

interlock commented 7 years ago

Here is the configuration I use on my setup:

version: '2'

services:
  narrows:
    build: .
    env_file: .env
    links:
      - mysql
    depends_on:
      - mysql
    ports:
      - "3334:3334"
    volumes:
      - narrows_data:/opt/narrows/files
    network_mode: bridge
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: narrows
      MYSQL_USER: narrows
      MYSQL_PASSWORD: *******
      MYSQL_ROOT_PASSWORD: *******
    volumes:
      - mysql_data:/var/lib/mysql
    network_mode: bridge
volumes:
  mysql_data:
  narrows_data:

Notice I have customized it with network_mode and added env_file to the narrows section (which inserts environment variables as declared from .env)

Each setup can vary a fair bit when it comes to docker. What works with my setup (as above) may not work well for another user. It is not usually in the scope to choose how someone would configure their docker deployment.

If they use a docker manager (Rancher/kubernetes/etc) it takes care of setting environment variables at the right stage of deployment. Each has it's own approach, so it's hard to make a one file fits all.

I would consider the docker-compose file a local demo, as such sending emails shouldn't work right out the gate. As for configuring it, we could add an env_file directive to the compose file, but if the file in absent docker stops on an error. It makes the easy preview a little more complicated to require it, but there is nothing preventing someone from adding it.

So, what's the balance here? Up to you, no harm in adding more docs on how to take that sample docker to the next step of hosting it. Perhaps links to resources on how to host with docker are more helpful overall?

Off topic, we could setup a prebuild docker image on docker hub that is triggered by updates to this repo once this is merged. Making the deployments considerably faster (a download vs an actual build). More on that later :-)

emanchado commented 7 years ago

Ah, I see! I thought it had to work without modifying the file. I get it now. I made some extra tests and it seems to work great (I cannot actually send mail, but it seems to be an issue between Nodemailer and my mail server when using the URL-style configuration).

OK, I'll do some clean-ups and merge. Thanks a lot again!

emanchado commented 7 years ago

Just to confirm: if I'm not mistaken this PR has an obsolete branch. The one I should work on and merge is the one ending in commit eb4b7a6, called "updated config to use custom-environment-variables as appropriate", correct?

interlock commented 7 years ago

Yes. I must of merged in a stale branch?

On Tue, Aug 29, 2017 at 8:20 AM Esteban Manchado Velázquez < notifications@github.com> wrote:

Just to confirm: if I'm not mistaken this PR has an obsolete branch. The one I should work on and merge is the one ending in commit eb4b7a6, called "updated config to use custom-environment-variables as appropriate", correct?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/emanchado/narrows/pull/4#issuecomment-325698436, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHNQcAzoAtCx3aARPA8HF1ZGMefSau4ks5sdCw9gaJpZM4OZCgI .

emanchado commented 7 years ago

Cool, just making sure I was merging the right stuff. It's done now, closing this. Thanks again!

The final, squashed commit is 629bae0.