Early draft of a docker compose deployment

We have just managed to finish a Docker-only of OFN at https://ofn.allmende.io
It is built from GitHub - allmende/ofn-docker: Open Food Network production deployment, based on Docker Compose
A lot of inspiration about what to do came from

https://github.com/openfoodfoundation/ofn-install/blob/master/roles/app/templates/post-receive.j2

It still misses configuration of a cron container and a setup for the delayed_job, as well as usage of OpenStreetMap instead of Google Maps.

Please also note my comment to this pull request:

Hi @almereyda, looks interesting! Could you please comment a bit on how you see this in relation to the ofn-install project? Are you proposing it is a useful companion approach, a replacement, etc?

@maikel your thoughts on use of Docker welcome.

FYI, Iā€™ve increased the number of links and images a new user can post.

1 Like

When we worked on it yesterday night, our intention was not to replace anything but to provide another way of deploying production environment (than the ansible solution), straight from a dockercompose file.
I can hear the critics on Docker, but we believe multiple solutions is key to enhancement, so why not a Docker recipe.

It still miss some documentation (especially on assets compilation aka assets:precompile:primary && assets:precompile:nondigest .

Do you have a tutorial for installing OFN using this Docker config?

Kitematic is a good first place to start because it allows you to turn on
and off test docker machines. I agree it could help get more developers
involved

Greg

Cool. Thanks for your contribution. I agree that itā€™s nice to have an alternative. But it will also increase the maintenance work.

A very successful project using Docker is Discourse. That is the only one I have worked with so far. And I did come across some difficulties with disk space. Itā€™s also not ideal that some configuration changes require a rebuild of the container which involves downtime. I guess you could work around that, I just followed the official instructions.

Iā€™m looking forward to having an alternative and hope that it will mean improvements of the Ansible scripts as well.

1 Like

We will get back to writing documentation soonā€™ish.

Would that mean I can direct my programmer to Docker if I get one to volenter to contribute?

@JozeHladnik for development setup I started modifying @almereyda composer file, you can find my current version here: https://gitlab.com/hackers4peace/ofn-devenv (it has some OSX specific stuff, Iā€™ll make Linux variant as well)

This looks very modular and flexible!

@almereyda Did you get memcached working? Linking a (standard image) container (in the same way like postgres) results in ā€˜dalliā€™ gem not finding memcached expected at localhost:11211
It seems to work when adding the container/host name in config/environments/production.rb like this: config.cache_store = :dalli_store, ā€˜memcacheā€™

What is the docker compose way to configure the memcached host?

bundle exec rake assets:precompile:primary
results in: rake aborted!
Sprockets::FileNotFound: couldnā€™t find file ā€˜angular-rails-templatesā€™

@pmackay Could this have to do with symlinking assets into public? https://github.com/openfoodfoundation/ofn-install/blob/master/roles/deploy/tasks/main.yml#L48-L57

@jozelHladnik Docker allows all of us to run a copy of the live software so
that bugs and new solutions can be worked on by a bigger group

g

Docker for production?

I was asked what I think about Docker for OFN production servers. So Iā€™m sharing my thoughts here.

I totally get the point of having a virtual environment for development. Even though the OFN works on Linux and OSX natively, it would enable Windows users, it would keep environments separate, it would be a good place to test staging and production environments locally and so on. It would actually be good to document a list of advantages and disadvantages somewhere as a reference.

And then there is a good point in saying: ā€œIf we use Docker for dev and testing, why not use the same environment in production?ā€

But I think:

  • We have one VPS per OFN instance at the moment. So you have your own environment already.
  • We have a well working provisioning with Ansible already. We even have a configuration management there so that everybody knows which servers there are and which settings they use.
  • We would still need a provisioning tool like Ansible for the Docker setup on the server.
  • Docker is an additional layer adding more complexity.
  • Software updates (e.g. nginx) are simple to install on a VPS. They affect all native apps installed and they are permanent. With Docker we would need to rebuild/replace all containers.
  • Itā€™s a good practice to keep the OFN software flexible enough to work in multiple environments, not just the default OFN Docker image.

Summary: I donā€™t think that Docker is ideal for OFN production use. But it is great to emulate a production environment on another machine.

@maikel Thanks for those interesting remarks!

I was thinking of docker to be that VPS for me. Maybe thatā€™s my misconception?

My server runs debian. The ansible scripts require some ubuntu dependencies (that I could not figure out how to install). Thatā€™s why I used a docker ubuntu image which worked fine (almost).

There is a wordpress site and some nodejs apps already running on that server. Nginx is (virtual multi host) configured to distribute incoming http requests between them. I tried to install an OFN instance beside that. How would you do that? Simply renting another vps? possibly switching the hosting provider to find one that offers the fitting ubuntu version?

Do you think it would be a good idea to share the nginx and postgres db that is already running? Docker-compose seemed to ā€œpromiseā€ that by modularizing the different os processes. This would also enable to upgrade, replace or reconfigure them separately without having to run that huge ansible thing again which contains everything.

Iā€™m not a sysadmin. Just trying to figure out how to set up OFN.

Thank you for sharing the background. That helps me understand your situation.

I was thinking of docker to be that VPS for me.

Okay, cool. Itā€™s a good solution to create a separate environment. It saves you renting another VPS and lowers your costs. Great. More environments just means that you have more systems to take care of and to keep up-to-date.

My server runs debian. The ansible scripts require some ubuntu dependencies

Debian is my favourite. :slight_smile: Ideally, we would make the Ansible scripts general enough to work with Debian as well. That was the idea behind Ansible. And itā€™s not that difficult. It just hasnā€™t been a priority, because people just chose Ubuntu.

In the meantime, itā€™s a good idea to use Docker as a compatibility tool. Thatā€™s a strength of Docker. But wouldnā€™t it be better if we didnā€™t need Docker? That was the point I tried to make.

There is a wordpress site and some nodejs apps already running on that server.

We do the same on openfoodnetwork.org.au (OFN) also running openfoodnetwork.org (Wordpress). The difference is that itā€™s Ubuntu. We just have several configurations listening to different server names. The OFN config accesses the Unicorn processes (started by an unprivileged user) via FCGI. Thatā€™s how the Ansible scripts set it up.

Do you think it would be a good idea to share the nginx and postgres db that is already running?

I donā€™t know if itā€™s a good idea. We do it that way. I guess itā€™s more efficient and thatā€™s why database software supports multiple databases and multiple users with access management.

Another summary: I think that Docker is a great tool. And I think you made a good decision to use that tool to get the OFN working in your environment. But I also think we should make the OFN compatible with any setup people want to run. It should make the OFN cleaner, more flexible, faster and more powerful. But thatā€™s just my opinion. We also have to be careful that the OFN doesnā€™t become full of workarounds to live in every possible environment. What are your thoughts, everyone?

wouldnā€™t it be better if we didnā€™t need Docker?

fully agree! Initially I just manually set up a rails environment on my laptop which worked fine (although this might be more difficult if youā€™re not used to rails). Then I tried the (awesome) ansible scripts on the server and documented the experience here Ansible deploy on debian / docker - #3 by orangeman The only reason to use docker had been the ubuntu dependencies.

make the OFN compatible with any setup people want to run

Thatā€™s what docker - how I understood it - promised to do: make OFN run anywhere by just running a ready build image inside an isolated (movable) container. I was really inspired of how simple and quick(!) it was to setup wordpress in seconds: docker-compose up -d and done. The whole ā€œsetupā€ is isolated and can easily be moved to another server. The ansible scripts have been rather slow and it took a lot of attempts until they finally ran through. Then I tried docker commit and thought this would save all the workā€¦ but it didnā€™t. After running the committed docker image on my local machine it was necessary to start nginx, postgres, unicorn, memcached services manually and I couldnā€™t get the background job runner to work (ā€¦) Probably I was doing docker wrong :confused:

be careful that the OFN doesnā€™t become full of workarounds to live in every possible environment.

Very true! Keep it simple. Iā€™m not excited about docker the tool. Iā€™m excited about the promise to quickly spin up OFN instances and being able to easily stop/start an instance or move it to a different machine. Maybe docker container is not the right tool for this? @enricostn talked about plain linux containers LXC. Any thoughts about that?

I was talking about using LXC for development environments, not production.

Regarding your case, re-using an existent VPS with other distro than Ubuntu, maybe you could contribute on adding Debian compatibility to ofn-install repo. Sharing same nginx and DB can be an option, but outside of ofn-install IMHO.

I want todo install OFN in a debian laptop. Can i use this docker?
Do You have a guide?
PreRequistes, etc.

If I had got ofn running on debian I would (happily) contribute it @enricostn . But I gave up after two days. IIRC there are just some language l10n packages that are missing on debian and I could not figure out how to install them. Probably only minor issues @Rulosanti but I went with an ubuntu docker container at the time (which I can not recommend [ā€¦]). The easiest is imho to ā€œsimplyā€ use an ubuntu 14.04 VPS