leighmcculloch / vagrant-docker-compose

A Vagrant provisioner for docker compose.
ISC License
677 stars 72 forks source link

Set docker-compose version to latest #30

Open nickelozz opened 8 years ago

nickelozz commented 8 years ago

Is there any way to achieve setting docker-compose version to latest stable? Just like the docker installation defaults to latest stable version.

leighmcculloch commented 8 years ago

Unfortunately the download URLs for docker-compose don't have a latest URL that will always get the latest. But you can configure the version being downloaded by setting compose_version and I also try and keep this project up to date with the latest version. If you're using the latest version of this plugin, whenever you update the plugin it will auto-update docker-compose inside your vagrant instance (unless you override and lock the compose_version to something specific).

prilka commented 5 years ago

@leighmcculloch It's possible to determine the latest docker-compose version. The URL https://github.com/docker/compose/releases/latest will always redirect to the latest version, so the Location-Header contains the needed informationen.

I'm not an ruby developer, but i think it's possible to replace this line https://github.com/leighmcculloch/vagrant-docker-compose/blob/482f103bbcb27c69a6fce6ca7b94e2b03c24fa45/lib/vagrant-docker-compose/cap/linux/docker_compose_install.rb#L8

with something like this

version = config.compose_version
if version == 'latest'
    version = Net::HTTP.get_response(URI('https://github.com/docker/compose/releases/latest'))['Location'].split('/').last
end
comm.sudo("curl -L https://github.com/docker/compose/releases/download/#{version}/docker-compose-`uname -s`-`uname -m` > #{config.executable_install_path}")

The default value for the compose_version config should then be changed to latest.

I would create a pull-request, but i have no idea how to test/debug a vagrant plugin.

leighmcculloch commented 5 years ago

@prilka Thanks for the suggestion! That's a great idea.

leighmcculloch commented 5 years ago

One downside to doing this is it will make using the package unpredictable. If you have a specific version of the plugin installed, over time the version of docker-compose changes, which makes a development environment unpredictable.

I'm guessing not a lot of people are pinning vagrant plugin versions though, so this is probably mute, and latest is more likely to help than hinder folks.

I'm working on adding latest using the above idea.

prilka commented 5 years ago

One downside to doing this is it will make using the package unpredictable. If you have a specific version of the plugin installed, over time the version of docker-compose changes, which makes a development environment unpredictable.

That's true, but it's the same behavior as with most package-managers (e.g. pip install docker-compose). Developers who prefer a predictable version can set the desired version in their config via compose_version.

I'm working on adding latest using the above idea.

nice, thank you 👍

leighmcculloch commented 5 years ago

I think the approach I'll take is to use the GitHub API, with something akin to the following:

curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r '.name'

Right now this returns 1.24.1.

The downside to using the GitHub API is that rate limiting will set in if someone, or the NAT they are behind, is hitting the API a lot.

Using the 301/302 redirect on the URL won't have the rate limit.

prilka commented 5 years ago

The rate limit is really annoying for agencies with a shared ip. The solution with the redirect parsing works well and stable. I use it in some provisioning-scripts for quite a while.

leighmcculloch commented 5 years ago

That's a good point. 👍