faradayio / cage

Develop and deploy complex Docker applications
http://cage.faraday.io
Apache License 2.0
307 stars 26 forks source link

Support docker-compose named volumes #37

Closed luislavena closed 7 years ago

luislavena commented 7 years ago

Hello!

Thank you for creating and releasing this project to the world! :smile: :heart_eyes:

Was playing around and found that while docker-compose v2 file format is supported (version: 2) it is not possible to define named volumes instead of locally mapped ones.

Take the following change to example db.yml:

version: "2"
services:
  db:
    image: "mini/postgresql:9.3"
    volumes:
    - "postgresql:/data"

volumes:
  postgresql:

Result in the following error:

$ cage pull
Error: Error parsing /home/luis/code/_experiments/myproject/pods/db.yml: error reading file '/home/luis/code/_experiments/myproject/pods/db.yml'

Removal of volumes section result in the following error from docker-compose:

ERROR: Named volume "postgresql:/data:rw" is used in service "db" but no declaration was found in the volumes section.
Error: error running 'docker-compose -p myproject -f /home/luis/code/_experiments/myproject/.cage/pods/db.yml pull'

The following is the entire debug output:

DEBUG:cage: Arguments: ArgMatches { args: {}, subcommand: Some(SubCommand { name: "pull", matches: ArgMatches { args: {}, subcommand: None, usage: Some("USAGE:\n    cage pull [<POD_OR_SERVICE>]") } }), usage: Some("USAGE:\n    cage [OPTIONS] [SUBCOMMAND]") }
DEBUG:cage::pod: Parsing /home/luis/code/_experiments/myproject/pods/db.yml
Error: Error parsing /home/luis/code/_experiments/myproject/pods/db.yml: error reading file '/home/luis/code/_experiments/myproject/pods/db.yml'
stack backtrace:
   0:           0x6b1e1d - backtrace::backtrace::trace::h35ac923e26dc1b92
   1:           0x6b1da5 - backtrace::capture::Backtrace::new::h3a3d5e9defd7d407
   2:           0x6b1115 - error_chain::make_backtrace::h886cfbd0fcafaf76
   3:           0x4c0f48 - cage::pod::FileInfo::unnormalized::h790320cb80fb0307
   4:           0x5481c6 - cage::pod::Pod::new::hacf75a1c55be9ec8
   5:           0x5365e9 - cage::project::Project::from_dirs::h89ca20e1a0d8447f
   6:           0x544690 - cage::project::Project::from_current_dir::h9cd0302df0062b3e
   7:           0x403835 - cage::run::h5d2f081c3f60c97d
   8:           0x4416f3 - cage::main::hc0adf28a6e0d6b0d
   9:           0x917a68 - std::panicking::try::call::hca715a47aa047c49
  10:           0x91f89b - __rust_try
  11:           0x91f83e - __rust_maybe_catch_panic
  12:           0x9176c1 - std::rt::lang_start::h162055cb2e4b9fe7

Platform details: Linux Ubuntu 15.10 (Willy) x64 Cage: 0.1.2 Docker: 1.12.2 Docker-Compose: 1.8.1

Please note that I'm also using docker-machine and not native docker service. While still is possible to mount local directories across VM/native, I was aiming to ease usage of existing data in some projects.

Please let me know if other details are required.

Once again, thank you for creating and making this tool available! :heart: :heart: :heart:

emk commented 7 years ago

Thank you for trying out cage and for the kind words!

I've added basic support for volumes at the top-level of a file and I'm releasing cage 0.1.3. There are a few limitations:

  1. You may need to write volumename: {} instead of volumename: if you're not setting any options on the volume. I can work around this, but doing so will require some custom serde deserializers, which can be a bit fiddly.
  2. If you use driver_opts, the value fields must all be strings. Again, serde issues.
  3. If you access the same volume from multiple pods (which I'd personally recommend avoiding), you'll probably need to declare it once per pod with identical name and options or use an external volume.

Note that all our target-specific functionality should be supported. For example, you should be able to use an ordinary volume in development, but an external named volume with a specific driver in production. Let me know if you need any help setting this up.

This feature is brand new, and I haven't tested it beyond basic unit tests, so please let me know whether it works in the real world!

emk commented 7 years ago

Also, as one of the first non-Faraday users of cage, your feedback is really valuable! Please let us know what works, what doesn't, and what's just plain confusing. :confused: :question:

If you have any questions or ideas for new features, please don't hesitate to open up a new issue! You're also welcome to browse through our existing "RFC" issues which propose ideas for new features, and let us know what you think.

Depending on the time of day, you may also be able to reach us on our Gitter channel and ask us questions directly. Our focus right now is making cage as easy as possible for non-Faraday people use, and so your questions are really valuable.

emk commented 7 years ago

Travis CI is back online, and you should be able to get binary builds of cage 0.1.3.

luislavena commented 7 years ago

Thank you @emk for the promptly and detailed response!

re: volumes caveat, :+1:

Will definitely send around feedback or jump on Gitter to ask question. I like that some of the questions I had yesterday in my mind were already covered by some of the RFC :smile:

Now need to test out against a real life project and will have me poking around :wink:

Once again, thank you for the promptly response and making cage available to the world! :heart: :heart: :heart:

emk commented 7 years ago

Also, as one of the first non-Faraday users of cage, your feedback is really valuable! Please let us know what works, what doesn't, and what's just plain confusing. :confused:

If you have any questions or ideas for new features, please don't hesitate to open up a new issue! You're also welcome to browser through our existing "RFC" issues ( https://github.com/faradayio/cage/issues ) which propose ideas for new features, and let us know what you think.

Depending on the time of day, you may also be able to reach us on our Gitter channel ( https://gitter.im/faradayio/cage ) and ask us questions directly. Our focus right now is making cage as easy as possible for non-Faraday people use, and so your questions are really valuable.

emk commented 7 years ago

@luislavena I just wanted to thank you for the suggestion to use named volumes!. We've entirely switched over to them in-house and we're very happy with them.

You might also be interested that we have an experimental Windows port, and a new up --init command that makes it easier to initialize databases when users first install a project.

If there are any other features that would make cage easier to use, please don't hesitate to let us know about them. Most things that other people suggest actually end up benefiting our own in-house team sooner or later, so we're very interested in feedback.

luislavena commented 7 years ago

Thank you for the follow up @emk, I'm testing things out and will take a look to the RFC issues as I go.

:heart: :heart: :heart: