ship_it 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/Gemfile +16 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +46 -0
  6. data/Rakefile +6 -0
  7. data/app/assets/images/.keep +0 -0
  8. data/app/assets/javascripts/application.js +28 -0
  9. data/app/assets/javascripts/polling.coffee +44 -0
  10. data/app/assets/stylesheets/application.css +24 -0
  11. data/app/controllers/application_controller.rb +34 -0
  12. data/app/controllers/branches_controller.rb +2 -0
  13. data/app/controllers/commits_controller.rb +2 -0
  14. data/app/controllers/concerns/.keep +0 -0
  15. data/app/controllers/deploy_options_controller.rb +38 -0
  16. data/app/controllers/deployments_controller.rb +70 -0
  17. data/app/controllers/environments_controller.rb +23 -0
  18. data/app/controllers/projects_controller.rb +51 -0
  19. data/app/controllers/sessions_controller.rb +31 -0
  20. data/app/controllers/users_controller.rb +2 -0
  21. data/app/helpers/application_helper.rb +70 -0
  22. data/app/mailers/.keep +0 -0
  23. data/app/models/.keep +0 -0
  24. data/app/models/branch.rb +15 -0
  25. data/app/models/commit.rb +8 -0
  26. data/app/models/concerns/.keep +0 -0
  27. data/app/models/deploy_option.rb +11 -0
  28. data/app/models/deployment.rb +137 -0
  29. data/app/models/environment.rb +29 -0
  30. data/app/models/project.rb +79 -0
  31. data/app/models/user.rb +18 -0
  32. data/app/views/deploy_options/new.html.slim +15 -0
  33. data/app/views/deployments/_current.html.slim +15 -0
  34. data/app/views/deployments/_deployment.html.slim +15 -0
  35. data/app/views/deployments/_details.html.slim +26 -0
  36. data/app/views/deployments/_progress.html.slim +2 -0
  37. data/app/views/deployments/in_progress.js.erb +1 -0
  38. data/app/views/deployments/show.html.slim +38 -0
  39. data/app/views/deployments/show.js.erb +1 -0
  40. data/app/views/environments/_changes.html.slim +24 -0
  41. data/app/views/environments/changes.js.erb +1 -0
  42. data/app/views/environments/show.html.slim +36 -0
  43. data/app/views/layouts/application.html.slim +30 -0
  44. data/app/views/layouts/homepage.html.slim +10 -0
  45. data/app/views/projects/edit.html.slim +27 -0
  46. data/app/views/projects/index.html.slim +22 -0
  47. data/app/views/projects/new.html.slim +11 -0
  48. data/app/views/projects/show.html.slim +29 -0
  49. data/app/views/sessions/homepage.html.slim +6 -0
  50. data/app/views/sessions/new.html.slim +7 -0
  51. data/bin/bundle +3 -0
  52. data/bin/rails +4 -0
  53. data/bin/rake +4 -0
  54. data/bin/ship_it +44 -0
  55. data/config.ru +4 -0
  56. data/config/application.rb +23 -0
  57. data/config/boot.rb +4 -0
  58. data/config/environment.rb +5 -0
  59. data/config/environments/development.rb +29 -0
  60. data/config/environments/production.rb +80 -0
  61. data/config/environments/test.rb +36 -0
  62. data/config/initializers/backtrace_silencers.rb +7 -0
  63. data/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/config/initializers/inflections.rb +16 -0
  65. data/config/initializers/mime_types.rb +5 -0
  66. data/config/initializers/omniauth_providers_patch.rb +16 -0
  67. data/config/initializers/secret_token.rb +12 -0
  68. data/config/initializers/session_store.rb +3 -0
  69. data/config/initializers/wrap_parameters.rb +14 -0
  70. data/config/locales/en.yml +23 -0
  71. data/config/routes.rb +28 -0
  72. data/db/migrate/20130828221203_create_projects.rb +9 -0
  73. data/db/migrate/20130828232058_create_deployments.rb +16 -0
  74. data/db/migrate/20130828234740_create_users.rb +9 -0
  75. data/db/migrate/20130828234748_create_deploy_options.rb +11 -0
  76. data/db/migrate/20130828234808_create_branches.rb +9 -0
  77. data/db/migrate/20130828234814_create_commits.rb +10 -0
  78. data/db/migrate/20130828234822_create_environments.rb +9 -0
  79. data/db/schema.rb +80 -0
  80. data/db/seeds.rb +7 -0
  81. data/lib/assets/.keep +0 -0
  82. data/lib/ship_it.rb +9 -0
  83. data/lib/ship_it/rails_app.rb +12 -0
  84. data/lib/ship_it/version.rb +3 -0
  85. data/lib/tasks/.keep +0 -0
  86. data/lib/tasks/ship_it.rake +76 -0
  87. data/log/.keep +0 -0
  88. data/public/404.html +58 -0
  89. data/public/422.html +58 -0
  90. data/public/500.html +57 -0
  91. data/public/favicon.ico +0 -0
  92. data/public/robots.txt +5 -0
  93. data/ship_it.gemspec +38 -0
  94. data/templates/project/.gitignore +6 -0
  95. data/templates/project/Gemfile +6 -0
  96. data/templates/project/config.ru +8 -0
  97. data/templates/project/config/database.yml +23 -0
  98. data/templates/project/db/.gitkeep +0 -0
  99. data/templates/project/db/schema.rb +75 -0
  100. data/templates/project/lib/ship_it/railtie.rb +20 -0
  101. data/templates/project/log/.gitkeep +0 -0
  102. data/test/controllers/.keep +0 -0
  103. data/test/controllers/branches_controller_test.rb +7 -0
  104. data/test/controllers/commits_controller_test.rb +7 -0
  105. data/test/controllers/configurations_controller_test.rb +7 -0
  106. data/test/controllers/deploy_options_controller_test.rb +7 -0
  107. data/test/controllers/deployments_controller_test.rb +7 -0
  108. data/test/controllers/environments_controller_test.rb +7 -0
  109. data/test/controllers/projects_controller_test.rb +7 -0
  110. data/test/controllers/users_controller_test.rb +7 -0
  111. data/test/fixtures/.keep +0 -0
  112. data/test/fixtures/branches.yml +11 -0
  113. data/test/fixtures/commits.yml +11 -0
  114. data/test/fixtures/configurations.yml +11 -0
  115. data/test/fixtures/deploy_options.yml +11 -0
  116. data/test/fixtures/deployments.yml +11 -0
  117. data/test/fixtures/environments.yml +11 -0
  118. data/test/fixtures/projects.yml +11 -0
  119. data/test/fixtures/users.yml +11 -0
  120. data/test/helpers/.keep +0 -0
  121. data/test/helpers/branches_helper_test.rb +4 -0
  122. data/test/helpers/commits_helper_test.rb +4 -0
  123. data/test/helpers/configurations_helper_test.rb +4 -0
  124. data/test/helpers/deploy_options_helper_test.rb +4 -0
  125. data/test/helpers/deployments_helper_test.rb +4 -0
  126. data/test/helpers/environments_helper_test.rb +4 -0
  127. data/test/helpers/projects_helper_test.rb +4 -0
  128. data/test/helpers/users_helper_test.rb +4 -0
  129. data/test/integration/.keep +0 -0
  130. data/test/mailers/.keep +0 -0
  131. data/test/models/.keep +0 -0
  132. data/test/models/branch_test.rb +7 -0
  133. data/test/models/commit_test.rb +7 -0
  134. data/test/models/configuration_test.rb +7 -0
  135. data/test/models/deploy_option_test.rb +7 -0
  136. data/test/models/deployment_test.rb +7 -0
  137. data/test/models/environment_test.rb +7 -0
  138. data/test/models/project_test.rb +7 -0
  139. data/test/models/user_test.rb +7 -0
  140. data/test/test_helper.rb +15 -0
  141. data/vendor/assets/javascripts/.keep +0 -0
  142. data/vendor/assets/stylesheets/.keep +0 -0
  143. metadata +431 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f239acdc36ad315076cc0fe76c27ef5c498af50
4
+ data.tar.gz: 4125a112e08ec871289d669550ababfeef6ca860
5
+ SHA512:
6
+ metadata.gz: ffd65149ba515a3604e93590e071fc75fd271e71a2586ffd51ad088245479295399bd65ef3bd1e24380588e90be875b49bbe2a3a8a2cbdcc30e47ead44dd4ddd
7
+ data.tar.gz: 9c6d20584f3bd99e4aab557096cedf40e9dae8a61294a56a16c843ae009dffba9c13d594debce60856e9fc4e7d07a4b328ee93f059cfd56f127c80d5a4169987
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ .DS_Store
5
+ tmp/
6
+ Gemfile.lock
7
+ db/*.sqlite3
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 4.0"
4
+ gem "sass-rails", "~> 4.0.0"
5
+ gem "uglifier", ">= 1.3.0"
6
+ gem "coffee-rails", "~> 4.0.0"
7
+ gem "bootstrap-sass"
8
+ gem "jquery-rails"
9
+ gem "turbolinks"
10
+ gem "slim"
11
+ gem "sqlite3"
12
+ gem "omniauth"
13
+
14
+ gem "cocaine"
15
+ gem "git"
16
+ gem "andand"
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # ShipIt
2
+
3
+ ShipIt is a customizeable rails app that manages deployments to environments from git branches. Not only can it do one click deploys, but it can also save your log files and keep track of the changes deployed to each environment.
4
+
5
+ ## Getting started
6
+
7
+ To initialize a `ship_it` application:
8
+
9
+ ```
10
+ # install the gem
11
+ gem install `ship_it`
12
+
13
+ # initialize a project directory
14
+ ship_it new [PROJECT_NAME]
15
+
16
+ # run the server
17
+ ship_it start
18
+
19
+ # run the deployment runner
20
+ ship_it runner
21
+ ```
22
+
23
+ ## Authentication
24
+
25
+ `ship_it` uses [OmniAuth][omniauth] for authentication. To customize, you can configure within `lib/ship_it/railtie.rb` in your project directory.
26
+
27
+ ```
28
+ module ShipIt
29
+ class Railtie < ::Rails::Railtie
30
+
31
+ initializer "omniauth" do |app|
32
+ app.config.middleware.use OmniAuth::Builder do
33
+ provider :developer unless Rails.env.production?
34
+ provider :github, [GITHUB_CLIENT_ID], [GITHUB_SECRET_KEY]
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ ```
42
+
43
+ Any [OmniAuth][omniauth] strategy is valid as long as it provides a `uid` and a `name`.
44
+
45
+
46
+ [omniauth]: https://github.com/intridea/omniauth
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ ShipIt::Application.load_tasks
File without changes
@@ -0,0 +1,28 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
17
+
18
+ $(function(){
19
+ $('ul.nav a[href="' + window.location.pathname + '"]').parent('li').addClass('active');
20
+
21
+ $("body").on("change", "select[data-change]", function(evt) {
22
+ var select = $(evt.target),
23
+ form = select.parents('form');
24
+ $.ajax(select.attr('data-change'), {
25
+ data: form.serializeArray()
26
+ })
27
+ });
28
+ });
@@ -0,0 +1,44 @@
1
+ $ ->
2
+ logStart = null
3
+ intervals = []
4
+ poll = (url) ->
5
+ $.ajax(url, {
6
+ data: {
7
+ time: (new Date()).getTime()
8
+ }
9
+ })
10
+
11
+ pollLog = (url) ->
12
+ $.ajax(url, {
13
+ data: {
14
+ offset: logStart,
15
+ time: (new Date()).getTime()
16
+ },
17
+ success: (data, status, xhr) ->
18
+ log = $("#log")
19
+ log.append(data).scrollTop(log.prop("scrollHeight")) if data != ""
20
+ log.removeClass('uncompleted') if xhr.getResponseHeader('X-Log-Complete')
21
+ })
22
+
23
+ stopIntervals = () ->
24
+ clearInterval i for i in intervals
25
+ intervals = []
26
+
27
+ setupPollingContent = () ->
28
+ stopIntervals()
29
+ $("*[data-poll]").each (i, el) ->
30
+ el = $(el)
31
+ delay = el.attr('data-poll-delay') || 5000
32
+ intervals.push setInterval () ->
33
+ poll el.attr('data-poll')
34
+ , delay
35
+ $("*[data-poll-log").each (i, el) ->
36
+ el = $(el)
37
+ delay = el.attr('data-poll-delay') || 5000
38
+ logStart = el.attr('data-poll-log-start')
39
+ intervals.push setInterval () ->
40
+ pollLog el.attr('data-poll-log')
41
+ , delay if logStart
42
+
43
+ $(document).bind "page:load", setupPollingContent
44
+ setupPollingContent()
@@ -0,0 +1,24 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require bootstrap
13
+ *= require_tree .
14
+ */
15
+ body {
16
+ padding-top: 60px;
17
+ }
18
+
19
+ pre#log {
20
+ max-height: 500px;
21
+ overflow-y: auto;
22
+ overflow-x: hidden;
23
+ font-size: 10px;
24
+ }
@@ -0,0 +1,34 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+
6
+ before_filter :request_setup, :load_current_user, :load_projects, :authorize, :set_time_zone
7
+
8
+ protected
9
+
10
+ def request_setup
11
+ User.current = nil
12
+ end
13
+
14
+ def load_current_user
15
+ User.current = User.find_by_id(session[:user_id]) if session.has_key?(:user_id)
16
+ end
17
+
18
+ def load_projects
19
+ @projects = Project.all
20
+ end
21
+
22
+ def authorize
23
+ redirect_to login_path unless authorized?
24
+ end
25
+
26
+ def authorized?
27
+ session[:user_id].present?
28
+ end
29
+
30
+ def set_time_zone
31
+ Time.zone = 'Pacific Time (US & Canada)'
32
+ end
33
+
34
+ end
@@ -0,0 +1,2 @@
1
+ class BranchesController < ApplicationController
2
+ end
@@ -0,0 +1,2 @@
1
+ class CommitsController < ApplicationController
2
+ end
File without changes
@@ -0,0 +1,38 @@
1
+ class DeployOptionsController < ApplicationController
2
+
3
+ before_filter :load_project
4
+ before_filter :load_deploy_option, :only => [:destroy]
5
+
6
+ def new
7
+ @deploy_option = @project.deploy_options.build
8
+ end
9
+
10
+ def create
11
+ @deploy_option = @project.deploy_options.build(deploy_option_params)
12
+ if @deploy_option.save
13
+ redirect_to edit_project_path(@project)
14
+ else
15
+ render :new
16
+ end
17
+ end
18
+
19
+ def destroy
20
+ @deploy_option.destroy
21
+ redirect_to edit_project_path(@project)
22
+ end
23
+
24
+ protected
25
+
26
+ def load_project
27
+ @project = ShipIt::Project.find(params[:project_id])
28
+ end
29
+
30
+ def load_deploy_option
31
+ @deploy_option = @project.deploy_options.find(params[:id])
32
+ end
33
+
34
+ def deploy_option_params
35
+ params.require(:deploy_option).permit(:name, :value, :visible)
36
+ end
37
+
38
+ end
@@ -0,0 +1,70 @@
1
+ class DeploymentsController < ApplicationController
2
+
3
+ before_filter :load_project, only: [:create, :show, :log, :terminate]
4
+ before_filter :load_environment, only: [:create, :show, :log, :terminate]
5
+ before_filter :load_deployment, only: [:show, :log, :terminate]
6
+ before_filter :build_deployment, only: [:create]
7
+
8
+ def show
9
+ end
10
+
11
+ def log
12
+ content = ""
13
+ offset = params.fetch(:offset) || 0
14
+
15
+ if @deployment.log_file
16
+ f = File.open(@deployment.log_file, "r")
17
+ f.seek(offset.to_i)
18
+ content = f.read
19
+ end
20
+
21
+ response.headers["X-Log-Complete"] = "1" if @deployment.completed?
22
+ response.headers["X-Log-Length"] = content.length.to_s
23
+ render :text => content
24
+ end
25
+
26
+ def create
27
+ if @deployment.save
28
+ redirect_to [@project, @deployment.environment, @deployment]
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ def terminate
35
+ @deployment.terminate!
36
+
37
+ respond_to do |format|
38
+ format.js { render :text => '' }
39
+ end
40
+ end
41
+
42
+ def in_progress
43
+ respond_to do |format|
44
+ format.js
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def load_project
51
+ @project = Project.find(params[:project_id])
52
+ end
53
+
54
+ def load_environment
55
+ @environment = @project.environments.find(params[:environment_id])
56
+ end
57
+
58
+ def load_deployment
59
+ @deployment = @environment.deployments.find(params[:id])
60
+ end
61
+
62
+ def build_deployment
63
+ @deployment = @environment.deployments.build(deployment_params)
64
+ end
65
+
66
+ def deployment_params
67
+ deployment_params = params.require(:deployment).permit(:branch_id, :environment, :started_at, :log_file, :finished_at, :success, :revision, :user_terminated)
68
+ end
69
+
70
+ end
@@ -0,0 +1,23 @@
1
+ class EnvironmentsController < ApplicationController
2
+
3
+ before_filter :load_project
4
+ before_filter :load_environment
5
+
6
+ def show
7
+ end
8
+
9
+ def changes
10
+ @branch = Branch.find(params[:deployment][:branch_id])
11
+ end
12
+
13
+ protected
14
+
15
+ def load_project
16
+ @project = Project.find(params[:project_id])
17
+ end
18
+
19
+ def load_environment
20
+ @environment = @project.environments.find(params[:id])
21
+ end
22
+
23
+ end
@@ -0,0 +1,51 @@
1
+ class ProjectsController < ApplicationController
2
+
3
+ before_filter :load_project, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @projects = Project.all
7
+ end
8
+
9
+ def new
10
+ @project = Project.new
11
+ end
12
+
13
+ def create
14
+ @project = Project.new(project_params)
15
+ if @project.save
16
+ redirect_to @project
17
+ else
18
+ render :new
19
+ end
20
+ end
21
+
22
+ def show
23
+ end
24
+
25
+ def edit
26
+ end
27
+
28
+ def update
29
+ if @project.update_attributes(project_params)
30
+ redirect_to @project
31
+ else
32
+ render :edit
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ @project.destroy
38
+ redirect_to projects_path
39
+ end
40
+
41
+ protected
42
+
43
+ def project_params
44
+ params.require(:project).permit(:name, :git_repo_url)
45
+ end
46
+
47
+ def load_project
48
+ @project = Project.find(params[:id])
49
+ end
50
+
51
+ end