Revision 387babdd
Added by Daniel Lobato Garcia over 8 years ago
app/controllers/containers_controller.rb | ||
---|---|---|
1 | 1 |
class ContainersController < ::ApplicationController |
2 |
before_filter :find_resource, :only => [:show, :auto_complete_image, :auto_complete_image_tags] |
|
2 |
before_filter :find_resource, :only => [:show, :auto_complete_image, :auto_complete_image_tags, |
|
3 |
:commit] |
|
3 | 4 |
|
4 | 5 |
def index |
5 | 6 |
@container_resources = allowed_resources.select { |cr| cr.provider == 'Docker' } |
... | ... | |
54 | 55 |
render :json => images.flatten |
55 | 56 |
end |
56 | 57 |
|
58 |
def commit |
|
59 |
Docker::Container.get(@container.uuid).commit(:author => params[:commit][:author], |
|
60 |
:repo => params[:commit][:repo], |
|
61 |
:tag => params[:commit][:tag], |
|
62 |
:comment => params[:commit][:comment]) |
|
63 |
|
|
64 |
process_success :success_redirect => :back, |
|
65 |
:success_msg => _("%{container} commit was successful") % |
|
66 |
{ :container => @container } |
|
67 |
rescue => e |
|
68 |
process_error :redirect => :back, :error_msg => _("Failed to commit %{container}: %{e}") % |
|
69 |
{ :container => @container, :e => e } |
|
70 |
end |
|
71 |
|
|
57 | 72 |
private |
58 | 73 |
|
59 | 74 |
def action_permission |
60 | 75 |
case params[:action] |
61 | 76 |
when 'auto_complete_image', 'auto_complete_image_tags' |
62 |
'view' |
|
77 |
:view |
|
78 |
when 'commit' |
|
79 |
:commit |
|
63 | 80 |
else |
64 | 81 |
super |
65 | 82 |
end |
app/helpers/containers_helper.rb | ||
---|---|---|
33 | 33 |
@compute_resource = container.compute_resource |
34 | 34 |
title_actions( |
35 | 35 |
button_group( |
36 |
link_to_if_authorized(_("Commit"), hash_for_container_path(:id => container) |
|
37 |
.merge(:auth_object => container, |
|
38 |
:permission => 'commit_containers'), |
|
39 |
:title => _('Saves differences between image' \ |
|
40 |
'and current state of container' \ |
|
41 |
'as a new image')) |
|
36 |
link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal') |
|
42 | 37 |
), |
43 | 38 |
button_group(vm_power_action(container.in_fog)), |
44 | 39 |
button_group( |
app/views/containers/show.html.erb | ||
---|---|---|
102 | 102 |
<% end %> |
103 | 103 |
</div> |
104 | 104 |
</div> |
105 |
|
|
106 |
<div id="commit-modal" class="modal fade"> |
|
107 |
<div class="modal-dialog"> |
|
108 |
<div class="modal-content"> |
|
109 |
<div class="modal-header"> |
|
110 |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
|
111 |
<h4 class="modal-title"><%= _('Commit this container state') %></h4> |
|
112 |
</div> |
|
113 |
<div class="modal-body"> |
|
114 |
This will save your current container state to an image. |
|
115 |
<hr/> |
|
116 |
<%= form_tag commit_container_path(:id => @container.id), :id => 'commit-form', :class => 'form-horizontal' do %> |
|
117 |
<div class="form-group"> |
|
118 |
<%= label_tag "commit[repo]", _("Repo"), :class=>"col-sm-2 control-label" %> |
|
119 |
<%= text_field :commit, :repo, { :class => "col-sm-8", :focus_on_load => true, |
|
120 |
:placeholder => _('docker/my-committed-image') } %> |
|
121 |
</div> |
|
122 |
<div class="form-group"> |
|
123 |
<%= label_tag "commit[tag]", _("Tag"), :class=>"col-sm-2 control-label" %> |
|
124 |
<%= text_field :commit, :tag, { :class => "col-sm-8", :focus_on_load => true, |
|
125 |
:placeholder => _('latest') } %> |
|
126 |
</div> |
|
127 |
<div class="form-group"> |
|
128 |
<%= label_tag "commit[author]", _("Author"), :class=>"col-sm-2 control-label" %> |
|
129 |
<%= text_field :commit, :author, { :class => "col-sm-8", |
|
130 |
:placeholder => _('Foreman user <foremaner@theforeman.org>') } %> |
|
131 |
</div> |
|
132 |
<div class="form-group"> |
|
133 |
<%= label_tag "commit[comment]", _("Comment"), :class=>"col-sm-2 control-label" %> |
|
134 |
<%= text_field :commit, :comment, { :class => "col-sm-8", |
|
135 |
:placeholder => _('Description of the commit') } %> |
|
136 |
</div> |
|
137 |
<div class="modal-footer"> |
|
138 |
<button type="button" class="btn btn-default" data-dismiss="modal"><%= _('Cancel') %></button> |
|
139 |
<%= button_tag(:type => 'submit', :class => 'btn btn-primary') do %> |
|
140 |
<%= _('Submit') %> <span class="glyphicon glyphicon-cloud-upload"></span> |
|
141 |
<% end %> |
|
142 |
</div> |
|
143 |
<% end %> |
|
144 |
</div> |
|
145 |
</div> |
|
146 |
</div> |
config/routes.rb | ||
---|---|---|
1 | 1 |
Rails.application.routes.draw do |
2 | 2 |
resources :containers, :only => [:index, :new, :show, :destroy] do |
3 |
member do |
|
4 |
post :commit |
|
5 |
end |
|
3 | 6 |
resources :steps, :controller => 'containers/steps', :only => [:show, :update] |
4 | 7 |
get :auto_complete_image, :on => :member |
5 | 8 |
get :auto_complete_image_tags, :on => :member |
lib/foreman_docker/engine.rb | ||
---|---|---|
3 | 3 |
require 'fog' |
4 | 4 |
require 'fog/fogdocker' |
5 | 5 |
require 'wicked' |
6 |
require 'docker' |
|
6 | 7 |
|
7 | 8 |
module ForemanDocker |
8 | 9 |
# Inherit from the Rails module of the parent app (Foreman), not the plugin. |
... | ... | |
48 | 49 |
permission :view_containers, :containers => [:index, :show, |
49 | 50 |
:auto_complete_image, |
50 | 51 |
:auto_complete_image_tags] |
52 |
permission :commit_containers, :containers => [:commit] |
|
51 | 53 |
permission :create_containers, :'containers/steps' => [:show, :update], |
52 | 54 |
:containers => [:new] |
53 | 55 |
permission :destroy_containers, :containers => [:destroy] |
test/functionals/container_controller_test.rb | ||
---|---|---|
24 | 24 |
:id => container.id }, set_session_user |
25 | 25 |
assert_redirected_to containers_path |
26 | 26 |
end |
27 |
|
|
28 |
test 'committing a managed container' do |
|
29 |
container = FactoryGirl.create(:container) |
|
30 |
request.env['HTTP_REFERER'] = container_path(:id => container.id) |
|
31 |
commit_hash = { :author => 'a', :repo => 'b', :tag => 'c', :comment => 'd' } |
|
32 |
|
|
33 |
mock_container = mock |
|
34 |
::Docker::Container.expects(:get).with(container.uuid).returns(mock_container) |
|
35 |
mock_container.expects(:commit).with(commit_hash) |
|
36 |
|
|
37 |
post :commit, { :commit => commit_hash, |
|
38 |
:id => container.id }, set_session_user |
|
39 |
end |
|
27 | 40 |
end |
Also available in: Unified diff
Fixes #8035: Commit container changes