trinidad_sandbox_extension 0.4.2 → 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 (28) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +56 -0
  3. data/History.txt +6 -0
  4. data/README +27 -0
  5. data/git-hooks/post-commit +7 -0
  6. data/lib/trinidad_sandbox_extension.rb +24 -3
  7. data/lib/trinidad_sandbox_extension/app/helpers/{sandbox.rb → auth.rb} +20 -19
  8. data/lib/trinidad_sandbox_extension/app/helpers/context.rb +72 -0
  9. data/lib/trinidad_sandbox_extension/app/helpers/deploy.rb +106 -0
  10. data/lib/trinidad_sandbox_extension/app/helpers/view.rb +39 -0
  11. data/lib/trinidad_sandbox_extension/app/model/application_context.rb +48 -4
  12. data/lib/trinidad_sandbox_extension/app/public/css/sandbox.css +187 -0
  13. data/lib/trinidad_sandbox_extension/app/sandbox.rb +56 -39
  14. data/lib/trinidad_sandbox_extension/app/views/actions.html.haml +2 -2
  15. data/lib/trinidad_sandbox_extension/app/views/applications.html.haml +17 -0
  16. data/lib/trinidad_sandbox_extension/app/views/applications.xml.haml +13 -0
  17. data/lib/trinidad_sandbox_extension/app/views/deploy.html.haml +16 -0
  18. data/lib/trinidad_sandbox_extension/app/views/layout.html.haml +10 -6
  19. data/lib/trinidad_sandbox_extension/app/views/navigation.html.haml +10 -0
  20. data/spec/trinidad_sandbox_extension_spec.rb +12 -2
  21. data/trinidad-libs/trinidad-sandbox-extension.jar +0 -0
  22. data/trinidad_sandbox_extension.gemspec +16 -9
  23. metadata +52 -41
  24. data/lib/trinidad_sandbox_extension/app/public/css/main.css +0 -137
  25. data/lib/trinidad_sandbox_extension/app/views/app.html.haml +0 -8
  26. data/lib/trinidad_sandbox_extension/app/views/app.xml.haml +0 -11
  27. data/lib/trinidad_sandbox_extension/app/views/index.html.haml +0 -6
  28. data/lib/trinidad_sandbox_extension/app/views/index.xml.haml +0 -3
@@ -1,7 +1,8 @@
1
1
  require 'delegate'
2
2
  require 'cgi'
3
+ require 'trinidad'
3
4
 
4
- require File.expand_path('../../helpers/sandbox', __FILE__)
5
+ require File.expand_path('../../helpers/context', __FILE__)
5
6
 
6
7
  module Trinidad
7
8
  module Sandbox
@@ -10,9 +11,12 @@ module Trinidad
10
11
 
11
12
  def self.all
12
13
  apps = host ? host.find_children : []
13
- apps.select {|app| app.name != sandbox_context.name }.
14
+ a = apps.select {|app| app.name != sandbox_context.name }.
14
15
  map {|app| ApplicationContext.new(app) }.
15
16
  sort {|app1, app2| app1.slug <=> app2.slug }
17
+
18
+ a = a.select {|app| app.name != 'default'} unless enable_default?
19
+ a
16
20
  end
17
21
 
18
22
  def self.find(name)
@@ -25,6 +29,39 @@ module Trinidad
25
29
  ApplicationContext.new(context) if context
26
30
  end
27
31
 
32
+ def self.find_by_doc_base(base)
33
+ if (apps = host.find_children)
34
+ apps.select {|app| app.doc_base == File.basename(base)}.first
35
+ end
36
+ end
37
+
38
+ def self.create(url, path)
39
+ web_app = Trinidad::WebApp.create({
40
+ :jruby_min_runtimes => 1,
41
+ :jruby_max_runtimes => 1
42
+ }, {
43
+ :context_path => (url == 'default' ? '' : "/#{url}"),
44
+ :web_app_dir => File.basename(path),
45
+ :environment => 'production'
46
+ })
47
+
48
+ context = Trinidad::Tomcat::StandardContext.new
49
+ context.path = web_app.context_path
50
+ context.doc_base = web_app.web_app_dir
51
+
52
+ context.add_lifecycle_listener Trinidad::Tomcat::Tomcat::DefaultWebXmlListener.new
53
+
54
+ config = Trinidad::Tomcat::ContextConfig.new
55
+ config.default_web_xml = 'org/apache/catalin/startup/NO_DEFAULT_XML'
56
+ context.add_lifecycle_listener config
57
+
58
+ context.add_lifecycle_listener Trinidad::Lifecycle::Default.new(web_app)
59
+
60
+ host.add_child context
61
+
62
+ ApplicationContext.new(context)
63
+ end
64
+
28
65
  def initialize(context)
29
66
  super(context)
30
67
  end
@@ -49,12 +86,19 @@ module Trinidad
49
86
  [
50
87
  {:rel => 'start', :href => "#{self_path}/start"},
51
88
  {:rel => 'stop', :href => "#{self_path}/stop"},
52
- {:rel => 'redeploy', :href => "#{self_path}/redeploy"}
89
+ {:rel => 'restart', :href => "#{self_path}/restart"}
53
90
  ]
54
91
  end
55
92
 
56
93
  def parameters
57
- @parameters ||= find_parameters
94
+ @parameters ||= begin
95
+ parameters = {}
96
+ find_parameters.each do |param|
97
+ value = find_parameter(param)
98
+ parameters[param] = value if !value.nil? && !value.empty?
99
+ end
100
+ parameters
101
+ end
58
102
  end
59
103
  end
60
104
  end
@@ -0,0 +1,187 @@
1
+ ul {
2
+ padding: 0px;
3
+ }
4
+
5
+ li {
6
+ list-style: none;
7
+ margin: 0px;
8
+ padding: 0px;
9
+ display: list-item;
10
+ }
11
+
12
+ /* End: Reset */
13
+
14
+ body {
15
+ font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
16
+ font-size:10.5pt;
17
+ margin: 0;
18
+ }
19
+
20
+ h1 {
21
+ color: #383838;
22
+ }
23
+
24
+ a {
25
+ color: silver;
26
+ font-weight: bold;
27
+ text-decoration: none;
28
+ }
29
+
30
+ a:hover {
31
+ color: #383838;
32
+ }
33
+
34
+ p {
35
+ color: #383838;
36
+ font-size: 1.5em;
37
+ padding-left: .5em;
38
+ }
39
+
40
+ .site {
41
+ width: 50em;
42
+ margin: 0 auto;
43
+ padding: 2em 5em;
44
+ }
45
+
46
+ nav {
47
+ position: relative;
48
+ }
49
+
50
+ nav h1 {
51
+ font-size: 4em;
52
+ }
53
+
54
+ #nav {
55
+ position: absolute;
56
+ text-align: right;
57
+ right: 0em;
58
+ top: 2.8em;
59
+ }
60
+
61
+ #nav a {
62
+ padding-left: .8em;
63
+ }
64
+
65
+ span.nav {
66
+ color: #383838;
67
+ font-weight: bold;
68
+ padding-left: .8em;
69
+ }
70
+
71
+
72
+ .container {
73
+ border: 1px solid silver;
74
+ background: #EEE;
75
+ padding: .3em;
76
+ }
77
+
78
+ #applications li {
79
+ position: relative;
80
+ }
81
+
82
+ .application {
83
+ padding: 0em 1em;
84
+ }
85
+
86
+ .actions {
87
+ position: absolute;
88
+ top: 1.3em;
89
+ right: 2em;
90
+ text-align: right;
91
+ }
92
+
93
+ .actions form {
94
+ display: inline;
95
+ }
96
+
97
+ .app {
98
+ margin-bottom: 1em;
99
+ padding: 1em;
100
+ }
101
+
102
+ .header {
103
+ color: #383838;
104
+ font-size: 1.5em;
105
+ }
106
+
107
+
108
+ .started {
109
+ border: 1px solid #32cd32;
110
+ background: #D0EDC7;
111
+ }
112
+
113
+ .stopped {
114
+ border: 1px solid #b22222;
115
+ background: #E6BCB5;
116
+ }
117
+
118
+ .detail {
119
+ border: 1px solid #383838;
120
+ margin-top: .6em;
121
+ background: #silver;
122
+ color: #383838;
123
+ }
124
+
125
+ .detail ul {
126
+ margin: .5em;
127
+ }
128
+
129
+ .detail ul li {
130
+ line-height: 1.2em;
131
+ margin: .3em;
132
+ }
133
+
134
+ .detail ul li.reset {
135
+ margin-top: -4.3em;
136
+ }
137
+
138
+
139
+ .detail ul li.column1 {
140
+ margin-left: .3em;
141
+ }
142
+
143
+ .detail ul li.column2 {
144
+ margin-left: 22em;
145
+ }
146
+
147
+ #git-hook {
148
+ margin-top: 1em;
149
+ border: 1px solid #FF9900;
150
+ background: #FFFF99;
151
+ }
152
+
153
+ #git-hook p {
154
+ padding-left: 2em;
155
+ font-size: .8em;
156
+ }
157
+
158
+ #git-hook p span {
159
+ font-weight: bold;
160
+ font-style: italic;
161
+ }
162
+
163
+ form div {
164
+ padding: .5em 1em;
165
+ }
166
+
167
+ label {
168
+ color: #383838;
169
+ display:block;
170
+ font-size: 1.5em;
171
+ }
172
+
173
+ input {
174
+ background: silver;
175
+ font-size: 2.5em;
176
+ padding: .5em;
177
+ border: 1px solid grey;
178
+ color: #383838;
179
+ }
180
+
181
+ #flash {
182
+ border: 1px solid #b22222;
183
+ background: #E6BCB5;
184
+ color: #383838;
185
+ padding: 1em 1.5em;
186
+ margin-bottom: 1em;
187
+ }
@@ -1,70 +1,68 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra'
3
3
  require 'haml'
4
- require File.expand_path('../helpers/sandbox', __FILE__)
4
+ require File.expand_path('../helpers/auth', __FILE__)
5
+ require File.expand_path('../helpers/context', __FILE__)
6
+ require File.expand_path('../helpers/deploy', __FILE__)
7
+ require File.expand_path('../helpers/view', __FILE__)
5
8
  require File.expand_path('../model/application_context', __FILE__)
6
9
  require 'sinatra/respond_to'
7
10
  require 'sinatra/flash'
8
11
 
12
+ include Trinidad::Sandbox
13
+
9
14
  enable :sessions
10
15
 
11
16
  set :views, File.expand_path('../views', __FILE__)
12
17
 
13
18
  Sinatra::Application.register Sinatra::RespondTo
14
19
 
15
- helpers {
16
- include Trinidad::Sandbox::Helpers::Auth
17
- include Trinidad::Sandbox::Helpers::Context
18
- }
19
- before { login_required }
20
+ helpers do
21
+ include Helpers::Auth
22
+ include Helpers::Context
23
+ include Helpers::Deploy
24
+ include Helpers::View
25
+ end
26
+
27
+ before do
28
+ login_required if !readonly? && basic_auth_required?(request)
29
+
30
+ render_readonly if readonly? &&
31
+ (!request.get? || request.path =~ /deploy$/)
32
+ end
20
33
 
21
34
  get '/' do
22
35
  redirect sandbox_context.path + '/apps'
23
36
  end
24
37
 
25
38
  get '/apps' do
26
- @applications = Trinidad::Sandbox::ApplicationContext.all
27
-
28
- respond_to do |wants|
29
- wants.html { haml :index }
30
- wants.xml { haml :index }
31
- end
32
- end
33
-
34
- get '/apps/:name' do
35
- @app = Trinidad::Sandbox::ApplicationContext.find(params[:name])
36
- context_not_found(params[:name]) unless @app
39
+ @applications = ApplicationContext.all
40
+ @page_id = 'applications'
37
41
 
38
42
  respond_to do |wants|
39
- wants.html { haml :app }
40
- wants.xml { haml :app }
43
+ wants.html { haml :applications }
44
+ wants.xml { haml :applications }
41
45
  end
42
46
  end
43
47
 
44
48
  post '/apps/:name/stop' do
45
- context = Trinidad::Sandbox::ApplicationContext.find(params[:name])
49
+ context = ApplicationContext.find(params[:name])
46
50
 
47
51
  context_not_found(params[:name]) unless context
48
52
 
49
- if context.name == sandbox_context.name
50
- $servet_context.log "can't stop the sandbox application"
51
- respond_to do |wants|
52
- wants.html { redirect sandbox_context.path }
53
- wants.xml { status 500 }
54
- end
53
+ unless available_context?(context)
54
+ $servet_context.log "can't stop the application"
55
+ redirect_to_home 500
55
56
  end
56
57
 
57
58
  context.stop
58
59
  $servlet_context.log "#{context.name} stopped"
59
60
 
60
- respond_to do |wants|
61
- wants.html { redirect sandbox_context.path }
62
- wants.xml { status 204 }
63
- end
61
+ redirect_to_home 204
64
62
  end
65
63
 
66
64
  post '/apps/:name/start' do
67
- context = Trinidad::Sandbox::ApplicationContext.find(params[:name])
65
+ context = ApplicationContext.find(params[:name])
68
66
 
69
67
  context_not_found(params[:name]) unless context
70
68
 
@@ -75,21 +73,40 @@ post '/apps/:name/start' do
75
73
  $servlet_context.log "#{context.name} start failed"
76
74
  end
77
75
 
78
- respond_to do |wants|
79
- wants.html { redirect sandbox_context.path }
80
- wants.xml { status 204 }
81
- end
76
+ redirect_to_home 204
82
77
  end
83
78
 
84
- post '/apps/:name/redeploy' do
85
- context = Trinidad::Sandbox::ApplicationContext.find(params[:name])
79
+ post '/apps/:name/restart' do
80
+ context = ApplicationContext.find(params[:name])
86
81
 
87
82
  context_not_found(params[:name]) unless context
88
83
 
84
+ unless available_context?(context)
85
+ $servet_context.log "can't restart the application"
86
+ redirect_to_home 500
87
+ end
88
+
89
89
  context.reload
90
90
 
91
+ redirect_to_home 204
92
+ end
93
+
94
+ get '/deploy' do
95
+ @page_id = 'deploy'
96
+
91
97
  respond_to do |wants|
92
- wants.html { redirect sandbox_context.path }
93
- wants.xml { status 204 }
98
+ wants.html { haml :deploy }
99
+ end
100
+ end
101
+
102
+ post '/deploy' do
103
+ token_required(params)
104
+
105
+ if params['payload']
106
+ deploy_from_web_hook(params)
107
+ elsif params['repo']
108
+ deploy_from_form(params)
109
+ else
110
+ redirect_to_home 204
94
111
  end
95
112
  end
@@ -1,9 +1,9 @@
1
1
  .actions
2
2
  - if app.available
3
+ %form(method="post" action="#{app.self_path}/restart")
4
+ %button(type="submit") Restart
3
5
  %form(method="post" action="#{app.self_path}/stop")
4
6
  %button(type="submit") Stop
5
- %form(method="post" action="#{app.self_path}/redeploy")
6
- %button(type="submit") Redeploy
7
7
  - else
8
8
  %form(method="post" action="#{app.self_path}/start")
9
9
  %button(type="submit") Start
@@ -0,0 +1,17 @@
1
+ %div(id="applications" class="container")
2
+ - unless @applications.empty?
3
+ %ul
4
+ - @applications.each do |app|
5
+ %li(class="application")
6
+ %div(class="app #{app.state.to_s.downcase}")
7
+ %a(class="header" href="#{app.path}")= app.name
8
+ - unless readonly?
9
+ = haml :actions, :locals => {:app => app}, :layout => false
10
+ - unless app.parameters.empty?
11
+ .detail
12
+ %ul(class="parameters")
13
+ = render_parameters(app.parameters)
14
+ - else
15
+ %p It seems there're not applications running on Trinidad.
16
+ - unless readonly?
17
+ %p You can use Git to #{link_to_deploy} them without stopping the server.