foreman_docker 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -3
  3. data/app/assets/javascripts/foreman_docker/image_step.js +44 -5
  4. data/app/controllers/concerns/foreman_docker/find_container.rb +19 -0
  5. data/app/controllers/containers/steps_controller.rb +25 -39
  6. data/app/controllers/containers_controller.rb +10 -43
  7. data/app/controllers/image_search_controller.rb +88 -0
  8. data/app/controllers/registries_controller.rb +47 -0
  9. data/app/helpers/container_steps_helper.rb +21 -4
  10. data/app/helpers/containers_helper.rb +19 -7
  11. data/app/models/concerns/foreman_docker/parameter_validators.rb +11 -0
  12. data/app/models/container.rb +20 -7
  13. data/app/models/docker_container_wizard_state.rb +30 -0
  14. data/app/models/docker_container_wizard_states/configuration.rb +7 -0
  15. data/app/models/docker_container_wizard_states/environment.rb +21 -0
  16. data/app/models/docker_container_wizard_states/environment_variable.rb +7 -0
  17. data/app/models/docker_container_wizard_states/image.rb +11 -0
  18. data/app/models/docker_container_wizard_states/preliminary.rb +11 -0
  19. data/app/models/docker_registry.rb +28 -0
  20. data/app/models/environment_variable.rb +5 -0
  21. data/app/models/foreman_docker/docker.rb +22 -3
  22. data/app/models/service/containers.rb +38 -0
  23. data/app/models/service/registry_api.rb +26 -0
  24. data/app/views/containers/_list.html.erb +19 -18
  25. data/app/views/containers/index.html.erb +11 -6
  26. data/app/views/containers/show.html.erb +26 -7
  27. data/app/views/containers/steps/_form_buttons.html.erb +1 -1
  28. data/app/views/containers/steps/configuration.html.erb +2 -2
  29. data/app/views/containers/steps/environment.html.erb +19 -6
  30. data/app/views/containers/steps/image.html.erb +58 -39
  31. data/app/views/containers/steps/preliminary.html.erb +21 -4
  32. data/app/views/foreman_docker/common_parameters/_environment_variable.html.erb +18 -0
  33. data/app/views/image_search/_repository_search_results.html.erb +12 -0
  34. data/app/views/registries/_form.html.erb +26 -0
  35. data/app/views/registries/edit.html.erb +3 -0
  36. data/app/views/registries/index.html.erb +28 -0
  37. data/app/views/registries/new.html.erb +3 -0
  38. data/config/routes.rb +11 -2
  39. data/db/migrate/20141024163003_create_docker_registries.rb +22 -0
  40. data/db/migrate/20141120123003_add_user_credentials_to_docker_registries.rb +6 -0
  41. data/db/migrate/20141209182008_remove_docker_tables.rb +72 -0
  42. data/db/migrate/20141222113313_create_wizard_states.rb +42 -0
  43. data/lib/foreman_docker/engine.rb +25 -5
  44. data/lib/foreman_docker/version.rb +1 -1
  45. data/test/factories/containers.rb +2 -0
  46. data/test/factories/docker_registry.rb +16 -0
  47. data/test/functionals/containers_steps_controller_test.rb +7 -40
  48. data/test/integration/container_steps_test.rb +24 -0
  49. data/test/integration/container_test.rb +18 -0
  50. data/test/units/container_test.rb +0 -7
  51. data/test/units/containers_service_test.rb +21 -0
  52. data/test/units/docker_registry_test.rb +24 -0
  53. metadata +45 -22
  54. data/app/models/docker_image.rb +0 -9
  55. data/app/models/docker_tag.rb +0 -8
  56. data/test/factories/docker_image.rb +0 -5
  57. data/test/factories/docker_tag.rb +0 -6
  58. data/test/units/docker_image_test.rb +0 -23
  59. data/test/units/docker_tag_test.rb +0 -35
@@ -0,0 +1,42 @@
1
+ class CreateWizardStates < ActiveRecord::Migration
2
+ # rubocop:disable Metrics/MethodLength
3
+ def change
4
+ create_table :docker_container_wizard_states do |t|
5
+ t.timestamps
6
+ end
7
+
8
+ create_table :docker_container_wizard_states_preliminaries do |t|
9
+ t.integer :compute_resource_id, :null => false
10
+ t.references :docker_container_wizard_state, :null => false
11
+ t.timestamps
12
+ end
13
+
14
+ create_table :docker_container_wizard_states_images do |t|
15
+ t.integer :registry_id
16
+ t.string :repository_name, :null => false
17
+ t.string :tag, :null => false
18
+ t.references :docker_container_wizard_state, :null => false
19
+ t.timestamps
20
+ end
21
+
22
+ create_table :docker_container_wizard_states_configurations do |t|
23
+ t.string :name
24
+ t.string :command
25
+ t.string :entrypoint
26
+ t.integer :cpu_set
27
+ t.float :cpu_shares
28
+ t.string :memory
29
+ t.references :docker_container_wizard_state, :null => false
30
+ t.timestamps
31
+ end
32
+
33
+ create_table :docker_container_wizard_states_environments do |t|
34
+ t.boolean :tty
35
+ t.boolean :attach_stdin, :default => true
36
+ t.boolean :attach_stdout, :default => true
37
+ t.boolean :attach_stderr, :default => true
38
+ t.references :docker_container_wizard_state, :null => false
39
+ t.timestamps
40
+ end
41
+ end
42
+ end
@@ -11,17 +11,23 @@ module ForemanDocker
11
11
  class Engine < ::Rails::Engine
12
12
  engine_name 'foreman_docker'
13
13
 
14
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
15
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
16
+
14
17
  initializer 'foreman_docker.load_app_instance_data' do |app|
15
18
  app.config.paths['db/migrate'] += ForemanDocker::Engine.paths['db/migrate'].existent
16
19
  end
17
20
 
18
21
  initializer "foreman_docker.assets.precompile" do |app|
19
- app.config.assets.precompile += %w(foreman_docker/terminal.css foreman_docker/image_step.js)
22
+ app.config.assets.precompile += %w(foreman_docker/autocomplete.css
23
+ foreman_docker/terminal.css
24
+ foreman_docker/image_step.js)
20
25
  end
21
26
 
22
27
  initializer 'foreman_docker.configure_assets', :group => :assets do
23
28
  SETTINGS[:foreman_docker] =
24
- { :assets => { :precompile => ['foreman_docker/terminal.css',
29
+ { :assets => { :precompile => ['foreman_docker/autocomplete.css',
30
+ 'foreman_docker/terminal.css',
25
31
  'foreman_docker/image_step.js'] } }
26
32
  end
27
33
 
@@ -45,17 +51,31 @@ module ForemanDocker
45
51
  menu :top_menu, :new_container, :caption => N_('New container'),
46
52
  :url_hash => { :controller => :containers,
47
53
  :action => :new }
54
+ menu :top_menu, :registries, :caption => N_('Registries'),
55
+ :url_hash => { :controller => :registries,
56
+ :action => :index }
48
57
  end
49
58
 
50
59
  security_block :containers do
51
- permission :view_containers, :containers => [:index, :show,
52
- :auto_complete_image,
53
- :auto_complete_image_tags]
60
+ permission :view_containers, :containers => [:index, :show]
54
61
  permission :commit_containers, :containers => [:commit]
55
62
  permission :create_containers, :'containers/steps' => [:show, :update],
56
63
  :containers => [:new]
57
64
  permission :destroy_containers, :containers => [:destroy]
58
65
  end
66
+
67
+ security_block :registries do
68
+ permission :view_registries, :registries => [:index, :show]
69
+ permission :create_registries, :registries => [:new, :create, :update, :edit]
70
+ permission :destroy_registries, :registries => [:destroy]
71
+ end
72
+
73
+ security_block :image_search do
74
+ permission :search_repository_image_search,
75
+ :image_search => [:auto_complete_repository_name,
76
+ :auto_complete_image_tag,
77
+ :search_repository]
78
+ end
59
79
  end
60
80
 
61
81
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanDocker
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -2,5 +2,7 @@ FactoryGirl.define do
2
2
  factory :container do
3
3
  sequence(:name) { |n| "container_#{n}" }
4
4
  association :compute_resource, :factory => :docker_cr
5
+ sequence(:repository_name) { |n| "repo#{n}" }
6
+ sequence(:tag) { |n| "tag#{n}" }
5
7
  end
6
8
  end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :docker_registry do
3
+ sequence(:name) { |n| "hub#{n}" }
4
+ sequence(:url) { |n| "http://localhost/#{n}" }
5
+ sequence(:username) { |n| "username#{n}" }
6
+ sequence(:password) { |n| "password#{n}" }
7
+ end
8
+
9
+ trait :with_location do
10
+ locations { [FactoryGirl.build(:location)] }
11
+ end
12
+
13
+ trait :with_organization do
14
+ organizations { [FactoryGirl.build(:organization)] }
15
+ end
16
+ end
@@ -6,47 +6,14 @@ module Containers
6
6
  @container = FactoryGirl.create(:container)
7
7
  end
8
8
 
9
- test 'sets a docker image and tag for a new container' do
10
- put :update, { :id => :image,
11
- :container_id => @container.id,
12
- :image => 'centos',
13
- :container => { :tag => 'latest' } }, set_session_user
14
- assert_response :found
15
- assert_redirected_to container_step_path(:container_id => @container.id,
16
- :id => :configuration)
17
- assert_equal DockerImage.find_by_image_id('centos'), @container.reload.image
18
- assert_equal DockerTag.find_by_tag('latest'), @container.tag
19
- end
20
-
21
- context 'container creation' do
22
- setup do
23
- @container.update_attribute(:image, (image = FactoryGirl.create(:docker_image,
24
- :image_id => 'centos')))
25
- @container.update_attribute(:tag, FactoryGirl.create(:docker_tag, :image => image,
26
- :tag => 'latest'))
27
- end
28
-
29
- test 'uuid of the created container is saved at the end of the wizard' do
30
- Fog.mock!
31
- fake_container = @container.compute_resource.send(:client).servers.first
32
- ForemanDocker::Docker.any_instance.expects(:create_container).returns(fake_container)
33
- put :update, { :id => :environment,
34
- :container_id => @container.id }, set_session_user
35
- assert_equal fake_container.id, Container.find(@container.id).uuid
36
- end
37
-
38
- test 'errors are displayed when container creation fails' do
39
- Docker::Container.expects(:create).raises(Docker::Error::DockerError, 'some error')
40
- put :update, { :id => :environment,
41
- :container_id => @container.id }, set_session_user
42
- assert_template 'environment'
43
- assert_match(/some error/, flash[:error])
44
- end
45
- end
46
-
47
9
  test 'wizard finishes with a redirect to the managed container' do
48
- get :show, { :id => :wicked_finish,
49
- :container_id => @container.id }, set_session_user
10
+ state = DockerContainerWizardState.create!
11
+ Service::Containers.expects(:start_container!).with(equals(state)).returns(@container)
12
+ put :update, { :wizard_state_id => state.id,
13
+ :id => :environment,
14
+ :docker_container_wizard_states_environment => { :tty => false } },
15
+ set_session_user
16
+
50
17
  assert_redirected_to container_path(:id => @container.id)
51
18
  end
52
19
  end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class ContainerStepsTest < ActionDispatch::IntegrationTest
4
+ test 'shows a link to a new compute resource if none is available' do
5
+ visit new_container_path
6
+ assert has_selector?("div.alert", :text => 'Please add a new one')
7
+ end
8
+
9
+ test 'shows taxonomies tabs' do
10
+ visit new_container_path
11
+ assert has_selector?("a", :text => 'Locations')
12
+ assert has_selector?("a", :text => 'Organizations')
13
+ end
14
+ # test 'clicking on search loads repositories' do
15
+ # Capybara.javascript_driver = :webkit
16
+ # container = FactoryGirl.create(:container)
17
+ # visit container_step_path(:container_id => container.id, :id => :repository)
18
+ # ComputeResource.any_instance.expects(:search).returns([{'name' => 'my_fake_repository_result',
19
+ # 'star_count' => 300,
20
+ # 'description' => 'fake repository'}])
21
+ # click_button 'search_repository'
22
+ # assert has_link? 'my_fake_repository_result'
23
+ # end
24
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class ContainerIntegrationTest < ActionDispatch::IntegrationTest
4
+ test 'redirects to a new compute resource if none is available' do
5
+ visit containers_path
6
+ assert_equal current_path, new_compute_resource_path
7
+ end
8
+
9
+ context 'available compute resource' do
10
+ test 'shows containers list if compute resource is available' do
11
+ ComputeResource.any_instance.stubs(:vms).returns([])
12
+ FactoryGirl.create(:docker_cr)
13
+ visit containers_path
14
+ assert page.has_link? 'New container'
15
+ refute_equal current_path, new_compute_resource_path
16
+ end
17
+ end
18
+ end
@@ -1,11 +1,4 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class ContainerTest < ActiveSupport::TestCase
4
- test 'validations do not happen if inactive' do
5
- FactoryGirl.build(:container)
6
- end
7
-
8
- test 'attributes are validated when active' do
9
- FactoryGirl.build(:container)
10
- end
11
4
  end
@@ -0,0 +1,21 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ContainersServiceTest < ActiveSupport::TestCase
4
+ setup do
5
+ @state = DockerContainerWizardState.create! do |s|
6
+ s.build_preliminary(:compute_resource_id => FactoryGirl.create(:docker_cr).id,
7
+ :locations => [taxonomies(:location1)],
8
+ :organizations => [taxonomies(:organization1)])
9
+ s.build_image(:repository_name => 'test', :tag => 'test')
10
+ s.build_configuration(:name => 'test')
11
+ s.build_environment(:tty => false)
12
+ end
13
+ end
14
+
15
+ test 'removes current state after successful container creation' do
16
+ ForemanDocker::Docker.any_instance.expects(:create_container)
17
+ .returns(OpenStruct.new(:uuid => 1))
18
+ Service::Containers.start_container!(@state)
19
+ assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class DockerRegistryTest < ActiveSupport::TestCase
4
+ test 'used_location_ids should return correct location ids' do
5
+ location = FactoryGirl.build(:location)
6
+ r = as_admin do
7
+ FactoryGirl.create(:docker_registry, :locations => ([location]))
8
+ end
9
+ assert r.used_location_ids.include?(location.id)
10
+ end
11
+
12
+ test 'used_organization_ids should return correct organization ids' do
13
+ organization = FactoryGirl.build(:organization)
14
+ r = as_admin do
15
+ FactoryGirl.create(:docker_registry, :organizations => ([organization]))
16
+ end
17
+ assert r.used_organization_ids.include?(organization.id)
18
+ end
19
+
20
+ test 'password is stored encrypted' do
21
+ r = as_admin { FactoryGirl.create(:docker_registry) }
22
+ assert r.is_decryptable?(r.password_in_db)
23
+ end
24
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato, Amos Benari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.13'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: wicked
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.26'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.26'
55
55
  description: Provision and manage Docker containers and images from Foreman.
@@ -65,16 +65,28 @@ files:
65
65
  - app/assets/javascripts/foreman_docker/image_step.js
66
66
  - app/assets/stylesheets/foreman_docker/autocomplete.css.scss
67
67
  - app/assets/stylesheets/foreman_docker/terminal.css.scss
68
+ - app/controllers/concerns/foreman_docker/find_container.rb
68
69
  - app/controllers/containers/steps_controller.rb
69
70
  - app/controllers/containers_controller.rb
71
+ - app/controllers/image_search_controller.rb
72
+ - app/controllers/registries_controller.rb
70
73
  - app/helpers/container_steps_helper.rb
71
74
  - app/helpers/containers_helper.rb
72
75
  - app/models/concerns/fog_extensions/fogdocker/image.rb
73
76
  - app/models/concerns/fog_extensions/fogdocker/server.rb
77
+ - app/models/concerns/foreman_docker/parameter_validators.rb
74
78
  - app/models/container.rb
75
- - app/models/docker_image.rb
76
- - app/models/docker_tag.rb
79
+ - app/models/docker_container_wizard_state.rb
80
+ - app/models/docker_container_wizard_states/configuration.rb
81
+ - app/models/docker_container_wizard_states/environment.rb
82
+ - app/models/docker_container_wizard_states/environment_variable.rb
83
+ - app/models/docker_container_wizard_states/image.rb
84
+ - app/models/docker_container_wizard_states/preliminary.rb
85
+ - app/models/docker_registry.rb
86
+ - app/models/environment_variable.rb
77
87
  - app/models/foreman_docker/docker.rb
88
+ - app/models/service/containers.rb
89
+ - app/models/service/registry_api.rb
78
90
  - app/views/api/v1/compute_resources/docker.json
79
91
  - app/views/api/v2/compute_resources/docker.json
80
92
  - app/views/compute_resources/form/_docker.html.erb
@@ -91,7 +103,13 @@ files:
91
103
  - app/views/containers/steps/environment.html.erb
92
104
  - app/views/containers/steps/image.html.erb
93
105
  - app/views/containers/steps/preliminary.html.erb
106
+ - app/views/foreman_docker/common_parameters/_environment_variable.html.erb
107
+ - app/views/image_search/_repository_search_results.html.erb
94
108
  - app/views/images/form/_docker.html.erb
109
+ - app/views/registries/_form.html.erb
110
+ - app/views/registries/edit.html.erb
111
+ - app/views/registries/index.html.erb
112
+ - app/views/registries/new.html.erb
95
113
  - config/routes.rb
96
114
  - db/migrate/20140930175337_add_email_to_compute_resource.rb
97
115
  - db/migrate/20141005233312_create_containers.rb
@@ -100,8 +118,12 @@ files:
100
118
  - db/migrate/20141009011026_add_attributes_to_container.rb
101
119
  - db/migrate/20141010173220_create_docker_images.rb
102
120
  - db/migrate/20141018110810_add_uuid_to_containers.rb
121
+ - db/migrate/20141024163003_create_docker_registries.rb
103
122
  - db/migrate/20141028164206_change_memory_in_container.rb
104
123
  - db/migrate/20141028164633_change_cpuset_in_container.rb
124
+ - db/migrate/20141120123003_add_user_credentials_to_docker_registries.rb
125
+ - db/migrate/20141209182008_remove_docker_tables.rb
126
+ - db/migrate/20141222113313_create_wizard_states.rb
105
127
  - lib/foreman_docker.rb
106
128
  - lib/foreman_docker/engine.rb
107
129
  - lib/foreman_docker/tasks/test.rake
@@ -109,14 +131,15 @@ files:
109
131
  - locale/Makefile
110
132
  - test/factories/compute_resources.rb
111
133
  - test/factories/containers.rb
112
- - test/factories/docker_image.rb
113
- - test/factories/docker_tag.rb
134
+ - test/factories/docker_registry.rb
114
135
  - test/functionals/container_controller_test.rb
115
136
  - test/functionals/containers_steps_controller_test.rb
137
+ - test/integration/container_steps_test.rb
138
+ - test/integration/container_test.rb
116
139
  - test/test_plugin_helper.rb
117
140
  - test/units/container_test.rb
118
- - test/units/docker_image_test.rb
119
- - test/units/docker_tag_test.rb
141
+ - test/units/containers_service_test.rb
142
+ - test/units/docker_registry_test.rb
120
143
  homepage: http://github.com/theforeman/foreman-docker
121
144
  licenses:
122
145
  - GPL-3
@@ -127,29 +150,29 @@ require_paths:
127
150
  - lib
128
151
  required_ruby_version: !ruby/object:Gem::Requirement
129
152
  requirements:
130
- - - '>='
153
+ - - ">="
131
154
  - !ruby/object:Gem::Version
132
155
  version: '0'
133
156
  required_rubygems_version: !ruby/object:Gem::Requirement
134
157
  requirements:
135
- - - '>='
158
+ - - ">="
136
159
  - !ruby/object:Gem::Version
137
160
  version: '0'
138
161
  requirements: []
139
162
  rubyforge_project:
140
- rubygems_version: 2.2.2
163
+ rubygems_version: 2.4.5
141
164
  signing_key:
142
165
  specification_version: 4
143
166
  summary: Provision and manage Docker containers and images from Foreman
144
167
  test_files:
145
168
  - test/functionals/containers_steps_controller_test.rb
146
169
  - test/functionals/container_controller_test.rb
147
- - test/factories/docker_image.rb
170
+ - test/factories/docker_registry.rb
148
171
  - test/factories/compute_resources.rb
149
- - test/factories/docker_tag.rb
150
172
  - test/factories/containers.rb
151
- - test/units/docker_image_test.rb
152
173
  - test/units/container_test.rb
153
- - test/units/docker_tag_test.rb
174
+ - test/units/docker_registry_test.rb
175
+ - test/units/containers_service_test.rb
154
176
  - test/test_plugin_helper.rb
155
- has_rdoc:
177
+ - test/integration/container_steps_test.rb
178
+ - test/integration/container_test.rb