Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support docker-compose push #51

Open
jamiejackson opened this issue Jul 20, 2018 · 4 comments
Open

Support docker-compose push #51

jamiejackson opened this issue Jul 20, 2018 · 4 comments

Comments

@jamiejackson
Copy link

Please consider supporting docker-compose push.

@leighmcculloch
Copy link
Owner

@jamiejackson Thanks for the suggestion! How would you imagine it working?

@jamiejackson
Copy link
Author

I'm new to pushing images, so I'm not sure I'm considering everybody's workflow, but I think this is how I'd expect it to work:

config.vm.provision :docker_compose,
  env: { "PORT" => "#{port}" },
  yml: ["/vagrant/docker-compose-base.yml","/vagrant/docker-compose.yml"],
  command_options: {
    up: "-d --remove-orphans",
    push: "service_a service_d service_f"
  },
  rebuild: true,
  push: true,
  project_name: "myproject",
  run: "always"

provisioner.rb

require_relative "errors/docker_compose_error"
require_relative "installer"
require_relative "docker_compose"

module VagrantPlugins
  module DockerComposeProvisioner
    class Provisioner < Vagrant.plugin("2", :provisioner)
      def initialize(machine, config, installer = nil, docker_compose = nil)
        super(machine, config)

        @installer = installer || Installer.new(@machine, @config)
        @docker_compose = docker_compose || DockerCompose.new(@machine, @config)
      end

      def provision
        @installer.ensure_installed

        return unless @config.yml

        if @config.rebuild
          @docker_compose.rm
          @docker_compose.build
        end

        if @config.push
          @docker_compose.push
        end

        @docker_compose.up
      end
    end
  end
end

@leighmcculloch
Copy link
Owner

leighmcculloch commented Jul 21, 2018

Hmm, if it was added in this way it would push images automatically everytime you brought up a vagrant image, which might be out of scope of the main use cases of using this plugin. It might make sense. While we see if anyone else comments on this issue, you should be able to get essentially the same behavior by adding something like the following to your Vagrantfile after the :docker_compose entry.

config.vm.provision :shell, inline: "cd /vagrant && docker-compose push"

@jamiejackson
Copy link
Author

My workaround is similar:

  main_stack_ymls_inline = main_stack_ymls.map{ |x| main_stack_ymls_inline += "-f #{x}" }.join(' ')
  compose_env_vars_inline = compose_env_vars.map{ |key, value| "#{key}='#{value}'" }.join(' ')
  services_to_push_inline = services_to_push.join(' ')

  config.vm.provision "docker_compose_build",
    type: "shell",
    inline: "#{compose_env_vars_inline} docker-compose  #{main_stack_ymls_inline} build #{services_to_push_inline}"
  config.vm.provision "docker_compose_push",
    type: "shell",
    inline: "#{compose_env_vars_inline} docker-compose  #{main_stack_ymls_inline} push #{services_to_push_inline}"
    
  config.vm.provision  :docker_compose,
    options: "-p docker",
    yml: main_stack_ymls,
    command_options: { up: "-d --remove-orphans" },
    env: compose_env_vars,
    rebuild: true,
    run: "always",
    compose_version: docker_compose_version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants