Commit 2b927dc3 authored by MAUPETIT Charly's avatar MAUPETIT Charly
Browse files

first step to have faster build with pre-build docker images w/ our factory

parent f09de872
......@@ -77,38 +77,22 @@ end
## frontend gem
##-------
# Use jquery as the JavaScript library
#gem 'jquery-rails'
#for markdown support
gem "redcarpet"
#to avoid files in javascript folder
gem "jquery-fileupload-rails"
#include bootstrap
#gem 'bootstrap-sass'
# Use SCSS for stylesheets
#gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier'
# Use CoffeeScript for .js.coffee assets and views
#gem 'coffee-rails'
#d3.js + nvd3
#gem 'novus-nvd3-rails'
#more icons
gem 'font-awesome-sass'
source 'https://rails-assets.org' do
gem 'rails-assets-bootstrap'
gem 'rails-assets-jquery'
gem 'rails-assets-jquery-ujs'
#gem 'rails-assets-jquery-color' #needed for border-color animation
gem 'rails-assets-bootstrap-sass'
gem 'rails-assets-coffee-script'
gem 'rails-assets-nvd3'
gem 'rails-assets-nvd3' #needed for statistics
#gem 'font-awesome-sass'
end
......@@ -202,8 +202,6 @@ GEM
flog (4.2.1)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.4)
font-awesome-sass (4.4.0)
sass (>= 3.2)
formtastic (3.1.3)
actionpack (>= 3.2.13)
formtastic_i18n (0.4.1)
......@@ -307,6 +305,8 @@ GEM
rails-assets-coffee-script (1.10.0)
rails-assets-d3 (3.5.6)
rails-assets-jquery (2.1.4)
rails-assets-jquery-ujs (1.1.0)
rails-assets-jquery (> 1.8)
rails-assets-nvd3 (1.8.1)
rails-assets-d3 (>= 3.4.4, < 4)
rails-deprecated_sanitizer (1.0.3)
......@@ -476,7 +476,6 @@ DEPENDENCIES
celluloid (= 0.17.1.1)
cucumber
devise
font-awesome-sass
jbuilder
jquery-fileupload-rails
mysql2 (~> 0.3.18)
......@@ -487,6 +486,7 @@ DEPENDENCIES
rails-assets-bootstrap-sass!
rails-assets-coffee-script!
rails-assets-jquery!
rails-assets-jquery-ujs!
rails-assets-nvd3!
rails_best_practices
redcarpet
......
......@@ -17,7 +17,9 @@
//= require_tree
//= require bootstrap
//= require jquery_ujs
//= require jquery-color
// require bootstrap-sprockets
// require self
/* jobs/index.html.erb
* make the all tr from the tab clickable */
......@@ -30,18 +32,3 @@ $('.table-hover tbody tr').click(function (e) {
$(this).css('cursor','pointer');
});
}
/* view/webapps/index */
function webapps_index()
{
$(".thumbnail").hover(function() {
$(this).css("cursor","pointer");
$(this).animate({"border-color": "#999999"}, 50);
}, function() {
$(this).animate({"border-color": "#cccccc"}, 50);
});
$('.thumbnail').click(function(e){
e.preventDefault();
window.location.href = $(this).find("a:first").attr("href");
});
}
/*! jQuery Color v@2.1.2 http://github.com/jquery/jquery-color | jquery.org/license */
(function(a,b){function m(a,b,c){var d=h[b.type]||{};return a==null?c||!b.def?null:b.def:(a=d.floor?~~a:parseFloat(a),isNaN(a)?b.def:d.mod?(a+d.mod)%d.mod:0>a?0:d.max<a?d.max:a)}function n(b){var c=f(),d=c._rgba=[];return b=b.toLowerCase(),l(e,function(a,e){var f,h=e.re.exec(b),i=h&&e.parse(h),j=e.space||"rgba";if(i)return f=c[j](i),c[g[j].cache]=f[g[j].cache],d=c._rgba=f._rgba,!1}),d.length?(d.join()==="0,0,0,0"&&a.extend(d,k.transparent),c):k[b]}function o(a,b,c){return c=(c+1)%1,c*6<1?a+(b-a)*c*6:c*2<1?b:c*3<2?a+(b-a)*(2/3-c)*6:a}var c="backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",d=/^([\-+])=\s*(\d+\.?\d*)/,e=[{re:/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(a){return[a[1],a[2],a[3],a[4]]}},{re:/rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(a){return[a[1]*2.55,a[2]*2.55,a[3]*2.55,a[4]]}},{re:/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,parse:function(a){return[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16)]}},{re:/#([a-f0-9])([a-f0-9])([a-f0-9])/,parse:function(a){return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)]}},{re:/hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,space:"hsla",parse:function(a){return[a[1],a[2]/100,a[3]/100,a[4]]}}],f=a.Color=function(b,c,d,e){return new a.Color.fn.parse(b,c,d,e)},g={rgba:{props:{red:{idx:0,type:"byte"},green:{idx:1,type:"byte"},blue:{idx:2,type:"byte"}}},hsla:{props:{hue:{idx:0,type:"degrees"},saturation:{idx:1,type:"percent"},lightness:{idx:2,type:"percent"}}}},h={"byte":{floor:!0,max:255},percent:{max:1},degrees:{mod:360,floor:!0}},i=f.support={},j=a("<p>")[0],k,l=a.each;j.style.cssText="background-color:rgba(1,1,1,.5)",i.rgba=j.style.backgroundColor.indexOf("rgba")>-1,l(g,function(a,b){b.cache="_"+a,b.props.alpha={idx:3,type:"percent",def:1}}),f.fn=a.extend(f.prototype,{parse:function(c,d,e,h){if(c===b)return this._rgba=[null,null,null,null],this;if(c.jquery||c.nodeType)c=a(c).css(d),d=b;var i=this,j=a.type(c),o=this._rgba=[];d!==b&&(c=[c,d,e,h],j="array");if(j==="string")return this.parse(n(c)||k._default);if(j==="array")return l(g.rgba.props,function(a,b){o[b.idx]=m(c[b.idx],b)}),this;if(j==="object")return c instanceof f?l(g,function(a,b){c[b.cache]&&(i[b.cache]=c[b.cache].slice())}):l(g,function(b,d){var e=d.cache;l(d.props,function(a,b){if(!i[e]&&d.to){if(a==="alpha"||c[a]==null)return;i[e]=d.to(i._rgba)}i[e][b.idx]=m(c[a],b,!0)}),i[e]&&a.inArray(null,i[e].slice(0,3))<0&&(i[e][3]=1,d.from&&(i._rgba=d.from(i[e])))}),this},is:function(a){var b=f(a),c=!0,d=this;return l(g,function(a,e){var f,g=b[e.cache];return g&&(f=d[e.cache]||e.to&&e.to(d._rgba)||[],l(e.props,function(a,b){if(g[b.idx]!=null)return c=g[b.idx]===f[b.idx],c})),c}),c},_space:function(){var a=[],b=this;return l(g,function(c,d){b[d.cache]&&a.push(c)}),a.pop()},transition:function(a,b){var c=f(a),d=c._space(),e=g[d],i=this.alpha()===0?f("transparent"):this,j=i[e.cache]||e.to(i._rgba),k=j.slice();return c=c[e.cache],l(e.props,function(a,d){var e=d.idx,f=j[e],g=c[e],i=h[d.type]||{};if(g===null)return;f===null?k[e]=g:(i.mod&&(g-f>i.mod/2?f+=i.mod:f-g>i.mod/2&&(f-=i.mod)),k[e]=m((g-f)*b+f,d))}),this[d](k)},blend:function(b){if(this._rgba[3]===1)return this;var c=this._rgba.slice(),d=c.pop(),e=f(b)._rgba;return f(a.map(c,function(a,b){return(1-d)*e[b]+d*a}))},toRgbaString:function(){var b="rgba(",c=a.map(this._rgba,function(a,b){return a==null?b>2?1:0:a});return c[3]===1&&(c.pop(),b="rgb("),b+c.join()+")"},toHslaString:function(){var b="hsla(",c=a.map(this.hsla(),function(a,b){return a==null&&(a=b>2?1:0),b&&b<3&&(a=Math.round(a*100)+"%"),a});return c[3]===1&&(c.pop(),b="hsl("),b+c.join()+")"},toHexString:function(b){var c=this._rgba.slice(),d=c.pop();return b&&c.push(~~(d*255)),"#"+a.map(c,function(a){return a=(a||0).toString(16),a.length===1?"0"+a:a}).join("")},toString:function(){return this._rgba[3]===0?"transparent":this.toRgbaString()}}),f.fn.parse.prototype=f.fn,g.hsla.to=function(a){if(a[0]==null||a[1]==null||a[2]==null)return[null,null,null,a[3]];var b=a[0]/255,c=a[1]/255,d=a[2]/255,e=a[3],f=Math.max(b,c,d),g=Math.min(b,c,d),h=f-g,i=f+g,j=i*.5,k,l;return g===f?k=0:b===f?k=60*(c-d)/h+360:c===f?k=60*(d-b)/h+120:k=60*(b-c)/h+240,h===0?l=0:j<=.5?l=h/i:l=h/(2-i),[Math.round(k)%360,l,j,e==null?1:e]},g.hsla.from=function(a){if(a[0]==null||a[1]==null||a[2]==null)return[null,null,null,a[3]];var b=a[0]/360,c=a[1],d=a[2],e=a[3],f=d<=.5?d*(1+c):d+c-d*c,g=2*d-f;return[Math.round(o(g,f,b+1/3)*255),Math.round(o(g,f,b)*255),Math.round(o(g,f,b-1/3)*255),e]},l(g,function(c,e){var g=e.props,h=e.cache,i=e.to,j=e.from;f.fn[c]=function(c){i&&!this[h]&&(this[h]=i(this._rgba));if(c===b)return this[h].slice();var d,e=a.type(c),k=e==="array"||e==="object"?c:arguments,n=this[h].slice();return l(g,function(a,b){var c=k[e==="object"?a:b.idx];c==null&&(c=n[b.idx]),n[b.idx]=m(c,b)}),j?(d=f(j(n)),d[h]=n,d):f(n)},l(g,function(b,e){if(f.fn[b])return;f.fn[b]=function(f){var g=a.type(f),h=b==="alpha"?this._hsla?"hsla":"rgba":c,i=this[h](),j=i[e.idx],k;return g==="undefined"?j:(g==="function"&&(f=f.call(this,j),g=a.type(f)),f==null&&e.empty?this:(g==="string"&&(k=d.exec(f),k&&(f=j+parseFloat(k[2])*(k[1]==="+"?1:-1))),i[e.idx]=f,this[h](i)))}})}),f.hook=function(b){var c=b.split(" ");l(c,function(b,c){a.cssHooks[c]={set:function(b,d){var e,g,h="";if(d!=="transparent"&&(a.type(d)!=="string"||(e=n(d)))){d=f(e||d);if(!i.rgba&&d._rgba[3]!==1){g=c==="backgroundColor"?b.parentNode:b;while((h===""||h==="transparent")&&g&&g.style)try{h=a.css(g,"backgroundColor"),g=g.parentNode}catch(j){}d=d.blend(h&&h!=="transparent"?h:"_default")}d=d.toRgbaString()}try{b.style[c]=d}catch(j){}}},a.fx.step[c]=function(b){b.colorInit||(b.start=f(b.elem,c),b.end=f(b.end),b.colorInit=!0),a.cssHooks[c].set(b.elem,b.start.transition(b.end,b.pos))}})},f.hook(c),a.cssHooks.borderColor={expand:function(a){var b={};return l(["Top","Right","Bottom","Left"],function(c,d){b["border"+d+"Color"]=a}),b}},k=a.Color.names={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00",transparent:[null,null,null,0],_default:"#ffffff"}})(jQuery);
/* view/webapps/index */
function webapps_index()
{
$(".thumbnail").hover(function() {
$(this).css("cursor","pointer");
$(this).animate({"border-color": "#999999"}, 50);
}, function() {
$(this).animate({"border-color": "#cccccc"}, 50);
});
$('.thumbnail').click(function(e){
e.preventDefault();
window.location.href = $(this).find("a:first").attr("href");
});
}
......@@ -16,8 +16,8 @@
*/
//@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome-sprockets";
@import "font-awesome";
//@import "font-awesome-sprockets";
//@import "font-awesome";
@import url(https://fonts.googleapis.com/css?family=Lato:300,400|Offside);
/* Body */
......
class AdminController < ApplicationController
before_filter :verify_is_admin
private
def verify_is_admin
(current_user.nil?) ? redirect_to(root_path) : (redirect_to(root_path) unless current_user.admin?)
......
class FactoryController < AdminController
def index
#get all the images from the registry starting by factory/
end
end
class FactoryController < AdminController
def index
#get all the images from the registry
@images = "#{config.connect_sandbox} curl -X GET #{config.docker_registry}/v1/search"
end
def create
@dos_all = DockerOs.all
@dos = DockerOs.new
render html
end
private
def build_allgo_factory
end
end
# -*- encoding : utf-8 -*-
class WebappsCreateContainerWorker < ActiveJob::Base
queue_as :apps_queue
#before performing the job, we send the Dockerfile to sid
before_enqueue do |webapp|
# w = webapp.arguments.first
# w.generate_dockerfile
# cmd = "scp #{Rails.configuration.dockerfiles_path}#{w.docker_name}/Dockerfile "
# cmd += "#{Rails.configuration.user}@#{Rails.configuration.sandbox}:#{Rails.configuration.dockerfiles_sandbox_path}#{w.docker_name}"
# system cmd
end
# this worker launch an empty container in the sandbox,
# right after the form being valid for a new app creation,
# so the user can install his app in the docker container
def perform(webapp)
# path_ssh = "#{Rails.configuration.dockerfiles_sandbox_path}"
# cmd = "#{Rails.configuration.connect_sandbox} \"docker build -t sandbox/#{webapp.docker_name} "
# cmd += "-f #{path_ssh}#{webapp.docker_name} #{path_ssh} && "
# cmd += "docker run -d -P --name sandbox_#{webapp.docker_name} sandbox/#{webapp.docker_name}\""
# #back = `#{cmd}`
# system cmd
end
after_perform do |webapp|
w = webapp.arguments.first
port = `#{Rails.configuration.connect_sandbox} docker port sandbox_#{w.docker_name} 22`.squish()
w.update(ipadress: port)
w.save
end
rescue_from Exception do |exception|
# Do something with the exception
puts exception
end
end
......@@ -4,23 +4,29 @@ class WebappsCreateContainerWorker < ActiveJob::Base
#before performing the job, we send the Dockerfile to sid
before_enqueue do |webapp|
w = webapp.arguments.first
w.generate_dockerfile
cmd = "scp #{Rails.configuration.dockerfiles_path}#{w.docker_name}/Dockerfile "
cmd += "#{Rails.configuration.user}@#{Rails.configuration.sandbox}:#{Rails.configuration.dockerfiles_sandbox_path}#{w.docker_name}"
system cmd
# w = webapp.arguments.first
# w.generate_dockerfile
# cmd = "scp #{Rails.configuration.dockerfiles_path}#{w.docker_name}/Dockerfile "
# cmd += "#{Rails.configuration.user}@#{Rails.configuration.sandbox}:#{Rails.configuration.dockerfiles_sandbox_path}#{w.docker_name}"
# system cmd
end
# this worker launch an empty container in the sandbox,
# right after the form being valid for a new app creation,
# so the user can install his app in the docker container
def perform(webapp)
#@w = Webapp.find(app_id) #now = serialization
path_ssh = "#{Rails.configuration.dockerfiles_sandbox_path}"
cmd = "#{Rails.configuration.connect_sandbox} \"docker build -t sandbox/#{webapp.docker_name} "
cmd += "-f #{path_ssh}#{webapp.docker_name} #{path_ssh} && "
cmd += "docker run -d -P --name sandbox_#{webapp.docker_name} sandbox/#{webapp.docker_name}\""
#back = `#{cmd}`
# path_ssh = "#{Rails.configuration.dockerfiles_sandbox_path}"
# cmd = "#{Rails.configuration.connect_sandbox} \"docker build -t sandbox/#{webapp.docker_name} "
# cmd += "-f #{path_ssh}#{webapp.docker_name} #{path_ssh} && "
# cmd += "docker run -d -P --name sandbox_#{webapp.docker_name} sandbox/#{webapp.docker_name}\""
# #back = `#{cmd}`
# system cmd
#move into async job
dos = DockerOs.find(webapp.docker_os_id)
#user = User.find(webapp.user_id).select('sshkey')
cmd = "#{Rails.configuration.connect_sandbox} \"
docker run -d -P --name sandbox_#{webapp.docker_name} allgo/factory_#{dos.name}:#{dos.version} /usr/sbin/sshd -D &&
docker exec -it sandbox_#{webapp.docker_name} bash -c 'touch #{webapp.entrypoint}' && chmod +x #{webapp.entrypoint} && echo #{webapp.user.sshkey.to_s.squish()} >> /root/.ssh/authorized_keys'\" "
system cmd
end
......@@ -28,7 +34,12 @@ class WebappsCreateContainerWorker < ActiveJob::Base
w = webapp.arguments.first
port = `#{Rails.configuration.connect_sandbox} docker port sandbox_#{w.docker_name} 22`.squish()
w.update(ipadress: port)
w.save #last 3 lines could be in an after_perform method
w.save
end
rescue_from Exception do |exception|
# Do something with the exception
puts exception
end
end
......@@ -21,6 +21,10 @@ class WebappsCreateImageWorker < ActiveJob::Base
system cmd
end
def after_perform
end
def notify()
#@webapp.update!(ipadress: nil, status: 2)
end
......
......@@ -11,11 +11,11 @@ class WebappsUpdateContainerWorker < ActiveJob::Base
def perform(webapp, new_v)
prefix = Rails.configuration.connect_sandbox
#new_v = webapp.webapp_versions.last.number
cmd = "#{prefix} \"docker stop upgrade_#{webapp_inst.docker_name} && "
cmd += "docker commit upgrade_#{webapp_inst.docker_name} #{Rails.configuration.docker_registry}/allgo/#{webapp_inst.docker_name}:#{new_v} && "
cmd = "#{prefix} \"docker stop upgrade_#{webapp.docker_name} && "
cmd += "docker commit upgrade_#{webapp.docker_name} #{Rails.configuration.docker_registry}/allgo/#{webapp.docker_name}:#{new_v} && "
#cmd += "tag allgo/#{webapp_inst.docker_name} #{Rails.configuration.docker_registry_path}/#{webapp_inst.docker_name}:#{webapp_inst.version}"
cmd += "docker push #{Rails.configuration.docker_registry}/allgo/#{webapp_inst.docker_name}:#{new_v} && "
cmd += "docker rm upgrade_#{webapp_inst.docker_name}\""
cmd += "docker push #{Rails.configuration.docker_registry}/allgo/#{webapp.docker_name}:#{new_v} && "
cmd += "docker rm upgrade_#{webapp.docker_name}\""
back = `#{cmd}`
##with gem docker api
......
......@@ -28,4 +28,36 @@ class DockerOs < ActiveRecord::Base
end
return cmd+":"+self.version+"\n"
end
def build_factory
#choose softwares
filename = "/tmp/#{self.name}#{self.version}"
content =
self.choose_os+
self.build_dockerfile+
"# # Setting openssh \n"+
"RUN mkdir -p /var/run/sshd \n "+
"RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config \n "+
"RUN sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd \n"+
"ENV NOTVISIBLE \"in users profile\" \n"+
"RUN echo \"export VISIBLE=now\" >> /etc/profile \n"+
"RUN mkdir -p /root/.ssh \n"+
"RUN touch /root/.ssh/authorized_keys \\"
#"RUN echo '#{user.sshkey.to_s.squish()}' >> /root/.ssh/authorized_keys \n"+
User.where(admin: true).each do |toto|
content += " echo #{toto.sshkey.to_s.squish()} >> /root/.ssh/authorized_keys \\"
end
content +=
" chmod 700 /root/.ssh/ \\"+
" chmod 644 /root/.ssh/authorized_keys \n"+
"RUN sed -i s#/root:/bin/false#/root:/bin/bash# /etc/passwd \n"+
"EXPOSE 22\n"+
"CMD [\"/usr/sbin/sshd\", \"-D\"]\n"
File.open(filename, "w+") { |f| f.write(content) }
if File.exist?(filename)
system "scp #{filename} #{Rails.configuration.user}@#{Rails.configuration.sandbox}:#{Rails.configuration.dockerfiles_sandbox_path}#{self.name}#{self.version}"
system "#{Rails.configuration.connect_sandbox} docker build -t allgo/factory_#{self.name}:#{self.version} -f #{Rails.configuration.dockerfiles_sandbox_path}#{self.name}#{self.version} #{Rails.configuration.dockerfiles_sandbox_path}"
end
end
end
......@@ -2,6 +2,7 @@
class Webapp < ActiveRecord::Base
belongs_to :user
#accepts_nested_attributes_for :user
has_many :jobs, dependent: :delete_all
has_many :users, :through => :jobs
......@@ -54,68 +55,73 @@ class Webapp < ActiveRecord::Base
#generate the dockerfile to create the webapp
def generate_dockerfile
puts "docker name : #{self.docker_name}"
user = User.find(self.user_id)
dos = DockerOs.find(self.docker_os_id)
filename = "#{Rails.configuration.dockerfiles_path}#{self.docker_name}/Dockerfile"
#File.open(filename, "w+") { |f| f.write(content) }
#t = "#!/bin/bash\nfor i in * ;\n do\n run /home/#{self.name}/whatever_path/#{self.name}\n done;"
#"RUN echo '#{t}' > /bin/#{self.docker_name}\n"+
#admin = User.select('sshkey').where(admin: true) #in docker factory
system 'mkdir', '-p', "#{Rails.configuration.dockerfiles_path}#{self.docker_name}" #on créé le dossier pour recevoir le dockerfile
content = "############################################################\n"+
"# Dockerfile to build Allgo container images\n"+
"# Based on #{dos.name}:#{dos.version}\n"+
"# App : #{self.name}\n"+
"############################################################\n"+
"\n"+
"# Image : \n"+
dos.choose_os+
"\n"+
"# File Author / Maintainer\n"+
"MAINTAINER Allgo\n"+
"\n\n"+
dos.build_dockerfile+
"# # Setting openssh \n\n"+
"RUN mkdir -p /var/run/sshd\n"+
"RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/#PasswordAuthentication yes/PasswordAuthentication no/'"+
" /etc/ssh/sshd_config\n"+
"RUN sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n"+
"\n"+
"ENV NOTVISIBLE \"in users profile\" \n"+
"RUN echo \"export VISIBLE=now\" >> /etc/profile\n"+
"\n"+
#"RUN adduser #{self.docker_name}\n"+ #test new user
"# Clearing and setting authorized ssh keys \n"+
"RUN mkdir -p /root/.ssh \n"+
"RUN echo '' > /root/.ssh/authorized_keys \n"+
"RUN echo '#{user.sshkey.to_s.squish()}' >> /root/.ssh/authorized_keys \n"+
# admins = User.select('sshkey').where(admin: :true)
# admins.each do |a|
#end
"RUN chmod 700 /root/.ssh/\n"+
"RUN chmod 644 /root/.ssh/authorized_keys\n"+
#creating the entrypoint
"RUN mkdir -p $(dirname #{self.entrypoint}) && touch #{self.entrypoint} \n"+
"RUN chmod 766 #{self.entrypoint} && chmod +x #{self.entrypoint} \n"+
"# Updating shell to bash \n"+
"RUN sed -i s#/root:/bin/false#/root:/bin/bash# /etc/passwd \n"+
"EXPOSE 22\n"+
"CMD [\"/usr/sbin/sshd\", \"-D\"]\n"
File.open(filename, "w+") { |f| f.write(content) }
if File.exist?(filename)
return true
else
puts "an error occur"
return false
end
#move into async job
#docker --name sandbox_docker_name run factory/dos.name:dos.version
#docker exec -it sandbox_docker_name bash -c 'touch self.entrypoint && chmod +x 766 self.entrypoint && echo '#{self.user.sshkey.to_s.squish()}' >> /root/.ssh/authorized_keys'
end
# def generate_dockerfile
# user = User.find(self.user_id)
# dos = DockerOs.find(self.docker_os_id)
# filename = "#{Rails.configuration.dockerfiles_path}#{self.docker_name}/Dockerfile"
# #File.open(filename, "w+") { |f| f.write(content) }
# #t = "#!/bin/bash\nfor i in * ;\n do\n run /home/#{self.name}/whatever_path/#{self.name}\n done;"
# #"RUN echo '#{t}' > /bin/#{self.docker_name}\n"+
#
# #admin = User.select('sshkey').where(admin: true) #in docker factory
# system 'mkdir', '-p', "#{Rails.configuration.dockerfiles_path}#{self.docker_name}" #on créé le dossier pour recevoir le dockerfile
# content = "############################################################\n"+
# "# Dockerfile to build Allgo container images\n"+
# "# Based on #{dos.name}:#{dos.version}\n"+
# "# App : #{self.name}\n"+
# "############################################################\n"+
# "\n"+
# "# Image : \n"+
# dos.choose_os+
# "\n"+
# "# File Author / Maintainer\n"+
# "MAINTAINER Allgo\n"+
# "\n\n"+
# dos.build_dockerfile+
# "# # Setting openssh \n\n"+
#
# "RUN mkdir -p /var/run/sshd\n"+
# "RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/#PasswordAuthentication yes/PasswordAuthentication no/'"+
# " /etc/ssh/sshd_config\n"+
# "RUN sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n"+
# "\n"+
# "ENV NOTVISIBLE \"in users profile\" \n"+
# "RUN echo \"export VISIBLE=now\" >> /etc/profile\n"+
# "\n"+
# #"RUN adduser #{self.docker_name}\n"+ #test new user
#
# "# Clearing and setting authorized ssh keys \n"+
#
# "RUN mkdir -p /root/.ssh \n"+
# "RUN echo '' > /root/.ssh/authorized_keys \n"+
# "RUN echo '#{user.sshkey.to_s.squish()}' >> /root/.ssh/authorized_keys \n"+
# # admins = User.select('sshkey').where(admin: :true)
# # admins.each do |a|
# #end
# "RUN chmod 700 /root/.ssh/\n"+
# "RUN chmod 644 /root/.ssh/authorized_keys\n"+
#
# #creating the entrypoint
# "RUN mkdir -p $(dirname #{self.entrypoint}) && touch #{self.entrypoint} \n"+
# "RUN chmod 766 #{self.entrypoint} && chmod +x #{self.entrypoint} \n"+
#
# "# Updating shell to bash \n"+
# "RUN sed -i s#/root:/bin/false#/root:/bin/bash# /etc/passwd \n"+
#
# "EXPOSE 22\n"+
# "CMD [\"/usr/sbin/sshd\", \"-D\"]\n"
# File.open(filename, "w+") { |f| f.write(content) }
# if File.exist?(filename)
# return true
# else
# puts "an error occur"
# return false
# end
# end
end
<!-- here, render all our "official" docker images pre-built -->
......@@ -2,38 +2,43 @@
<% if @job.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@job.errors.count, "error") %> prohibited this job from being saved:</h2>
<ul>
<% @job.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<label class="col-sm-2 control-label">Webapp : </label>
<div class="col-sm-3">
<%= f.collection_select :webapp_id, Webapp.where(status: 2).all, :id, :name, {}, {class: 'form-control'} %>
</div>
<div class="row">
<%= f.label :param, "Files: ", class: "control-label col-md-2 col-md-offset-1 lead" %>
<%= render 'jobs/upload' %>
<div class="col-md-3"></div> <!-- to display uploaded file -->
</div>
<br /><br />
<div class="form-group">
<label class="col-sm-2 control-label">Parameters :</label>
<div class="col-sm-10">
<%= f.text_field :param, class: "form-control" %>
<%= f.hidden_field :id, value: '' %>
<%= f.hidden_field :webapp_id, value: @webapp.id %>
<div class="row">
<%= f.label :version, "Version: ", class: "control-label col-md-2 col-md-offset-1 lead" %>
<div class="col-md-2">
<%= f.collection_select :webapp, @webapp.webapp_versions,:number,:number, {}, {class: "form-control",name: "version"} %>
</div>
<div class="col-md-4">
<span class="help-block">It's the last one by default</span>
</div>
</div>
<br /><br />
<div class="actions">
<div class="col-sm-offset-2 col-sm-10">
<%= f.submit 'Upload your data', class: 'btn btn-success' %>
<div class="row">
<%= f.label :param, "Parameters: ", class: "control-label col-md-2 col-md-offset-1 lead" %>
<div class="col-md-7">
<%= f.text_field :param, class: "form-control", id: "text_param" %>
</div>
<div class="pull-right">
<%= render @webapp.webapp_parameters %> <!-- match /view/webapp_parameters/webapp_parameter.html.erb -->
</div>
</div>
<div class="row">
<div class="control-label col-md-2 col-md-offset-1 lead">
<%= f.submit "Run this job", class: 'btn btn-success' %>
</div>
</div>
<% end %>
\ No newline at end of file
<% end %>