Project

General

Profile

Revision 16234b27

Added by Daniel Lobato Garcia over 6 years ago

Fixes #8409 - Pull docker image asynchronously

View differences:

app/models/container.rb
1 1
class Container < ActiveRecord::Base
2 2
  include Authorizable
3 3
  include Taxonomix
4
  include ForemanTasks::Concerns::ActionSubject
4 5

  
5 6
  belongs_to :compute_resource
6 7
  belongs_to :registry, :class_name => "DockerRegistry", :foreign_key => :registry_id
app/models/service/actions/compute_resource/pull.rb
1
module Service
2
  module Actions
3
    module ComputeResource
4
      class Pull < ::Actions::EntryAction
5
        def plan(container)
6
          #container.disable_auto_reindex!
7
          action_subject(container)
8
          container.compute_resource.create_image(:fromImage => container.repository_pull_url)
9
        end
10

  
11
        def humanized_name
12
          _('Pull')
13
        end
14

  
15
        def finalize
16
          logger.info('Finished pulling Docker image')
17
        end
18
      end
19
    end
20
  end
21
end
app/models/service/containers.rb
25 25
    end
26 26

  
27 27
    def self.pull_image(container)
28
      container.compute_resource.create_image(:fromImage => container.repository_pull_url)
28
      ForemanTasks.async_task(::Service::Actions::ComputeResource::Pull, container)
29 29
    end
30 30

  
31 31
    def self.start_container(container)
foreman_docker.gemspec
20 20

  
21 21
  s.add_dependency 'docker-api', '~> 1.13'
22 22
  s.add_dependency 'wicked', '~> 1.1'
23
  s.add_dependency 'foreman-tasks'
23 24
  s.add_development_dependency 'rubocop', '~> 0.26'
24 25
end
lib/foreman_docker/engine.rb
14 14
    config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
15 15
    config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
16 16

  
17
    initializer "foreman_docker.require_dynflow",
18
                :before => "foreman_tasks.initialize_dynflow" do |app|
19
      ForemanTasks.dynflow.require!
20
    end
21

  
17 22
    initializer 'foreman_docker.load_app_instance_data' do |app|
18 23
      app.config.paths['db/migrate'] += ForemanDocker::Engine.paths['db/migrate'].existent
19 24
    end

Also available in: Unified diff