capistrano-rails-artifact 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22521537c54403392131a5708d7e1dcb107bb562
4
+ data.tar.gz: 95a16e59e2c3b934ec89ba678ddf7cf0400c5f96
5
+ SHA512:
6
+ metadata.gz: 8c6b20785363b01cd92843bacc926a255d3aef35d8243ef8af591658912140f42cc6d2adc12abc8abc062fcf9da02328c1952eed1920919bc91e830c28038f96
7
+ data.tar.gz: bb23e28cee2c0e9b78e9e9d63a9c9a5435ab8dd145edac0e2211383fb297547aacbacc8045a875bd362b3e9e8a18b5511d7897a3c42d1baf513c28b40b2f4e8b
@@ -0,0 +1 @@
1
+ none
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .vagrant
data/Capfile ADDED
@@ -0,0 +1,26 @@
1
+ # Allows cap to have its config in 'test' to reduce confusion
2
+ set :deploy_config_path, 'test/config/deploy.rb'
3
+ set :stage_config_path, 'test/config/deploy'
4
+
5
+ # Load DSL and Setup Up Stages
6
+ require 'capistrano/setup'
7
+
8
+ # Includes default deployment tasks
9
+ require 'capistrano/deploy'
10
+
11
+ # Includes tasks from other gems included in your Gemfile
12
+ #
13
+ # For documentation on these, see for example:
14
+ #
15
+ # https://github.com/capistrano/rvm
16
+ # https://github.com/capistrano/rbenv
17
+ # https://github.com/capistrano/chruby
18
+ # https://github.com/capistrano/bundler
19
+ # https://github.com/capistrano/rails
20
+ #
21
+ # require 'capistrano/rvm'
22
+ # require 'capistrano/rbenv'
23
+ # require 'capistrano/chruby'
24
+ # require 'capistrano/bundler'
25
+ # require 'capistrano/rails/assets'
26
+ # require 'capistrano/rails/migrations'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-rails-artifact.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Case Taintor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # CapistranoRailsArtifact
2
+
3
+ A gem to allow you to package your Rails app into a .tar.gz and deploy it easily. This works by creating a
4
+ new type of 'scm' for Capistrano 3.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'capistrano-rails-artifact'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install capistrano-rails-artifact
21
+
22
+ ## Usage
23
+
24
+ This gem assumes that you have a tar.gz file in an accessible place. This .tar.gz should contain all the gems
25
+ vendored into vendor/bundle as well as the compiled assets. An example command to build this archive is:
26
+
27
+ ```sh
28
+ export RAILS_ENV=production
29
+ rm -rf vendor/bundle
30
+ bundle install --without development test --deployment
31
+ bundle exec rake assets:precompile
32
+ echo `git rev-parse HEAD` > REVISION
33
+ mkdir -p dist
34
+ tar -cvzf dist/release.tar.gz --exclude .git --exclude log --exclude "./vendor/bundle/ruby/2.1.0/cache" --exclude "./vendor/bundle/ruby/2.1.0/doc" --exclude .envrc --exclude dist --exclude tmp --exclude coverage --exclude features --exclude spec --exclude vagrants --exclude Vagrantfile --exclude README.md .
35
+
36
+ # TODO: put dist/release.tar.gz somewhere that is accessible from your application machines
37
+ ```
38
+
39
+ In your `config/deploy.rb`, you just need to set two variables
40
+
41
+ ```ruby
42
+ set :rails_artifact_archive_location, '<URL TO TAR GZ>'
43
+
44
+ set :scm, :rails_artifact
45
+ ```
46
+
47
+ ## Testing
48
+
49
+ Testing is done by spinning up a vagrant box, deploying to it, and then checking the result. You must
50
+ have Virtualbox and Vagrant installed, then run:
51
+
52
+ ```sh
53
+ bundle exec rake
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it ( https://github.com/ctaintor/capistrano-rails-artifact/fork )
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create a new Pull Request
63
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/**/*_test.rb"
6
+ end
7
+
8
+ task :default => :test
data/Vagrantfile ADDED
@@ -0,0 +1,27 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+
9
+ config.vm.define "deploy_target" do |deploy_target|
10
+ deploy_target.vm.box = "CentOS-6.5-x86_64-v20140504.box"
11
+ deploy_target.vm.box_url = "https://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.5-x86_64-v20140504.box"
12
+ deploy_target.vbguest.auto_update = false
13
+ deploy_target.vm.provider "virtualbox" do |v|
14
+ v.memory = 512
15
+ v.cpus = 1
16
+ end
17
+ script = <<BLOCK
18
+ #Creates a simple http server to server the files in '/vagrant/test'
19
+ cd /vagrant/test;
20
+ nohup python -m SimpleHTTPServer 8080 >/dev/null 2>&1 &
21
+ sleep 5
22
+ BLOCK
23
+ deploy_target.vm.provision "shell", inline: script
24
+ deploy_target.ssh.forward_agent = true
25
+ end
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano-rails-artifact/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-rails-artifact"
8
+ spec.version = CapistranoRailsArtifact::VERSION
9
+ spec.authors = ["Case Taintor"]
10
+ spec.email = ["case.taintor@klarna.com"]
11
+ spec.summary = %q{A gem to allow you to deploy using a .tar.gz}
12
+ spec.description = %q{A gem to allow you to deploy using a .tar.gz}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "pry"
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_dependency "capistrano", "~> 3.0"
26
+ end
@@ -0,0 +1,13 @@
1
+ # This file will be included by default when someone sets the scm to be :rails_artifact
2
+
3
+ load File.expand_path('../tasks/rails_artifact.rake', __FILE__)
4
+
5
+ # These two tasks are unnecessary for this strategy
6
+ Rake::Task['deploy:log_revision'].clear
7
+ Rake::Task['deploy:set_current_revision'].clear
8
+ namespace :deploy do
9
+ task :set_current_revision do
10
+ end
11
+ task :log_revision do
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ namespace :rails_artifact do
2
+ desc 'Check that the repo is reachable'
3
+ task :check do
4
+ end
5
+
6
+ desc 'Copy repo to releases'
7
+ task :create_release do
8
+ on release_roles :all do
9
+ archive_url = fetch(:rails_artifact_archive_location)
10
+ file_location = '/tmp/build-artifact-files/build-artifact.tar.gz'
11
+ execute :mkdir, '-p', File.dirname(file_location)
12
+ execute :rm, "-f #{file_location}"
13
+
14
+ execute :mkdir, '-p', release_path
15
+ execute :wget, "--no-check-certificate -q -O '#{file_location}' '#{archive_url}'"
16
+ within release_path do
17
+ execute :tar, "-xzf '#{file_location}'"
18
+ end
19
+ execute :rm, file_location
20
+ end
21
+ end
22
+
23
+ desc 'Determine the revision that will be deployed'
24
+ task :set_current_revision do
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoRailsArtifact
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1 @@
1
+ require_relative 'capistrano-rails-artifact/version'
@@ -0,0 +1,83 @@
1
+ require 'minitest/autorun'
2
+ require 'sshkit'
3
+ require 'sshkit/dsl'
4
+
5
+ class CapistranoRailsArtifactSpec < MiniTest::Unit::TestCase
6
+ def setup
7
+ system("vagrant up")
8
+ configure_sshkit_for_vagrant
9
+ end
10
+
11
+ def teardown
12
+ #system("vagrant destroy -f")
13
+ end
14
+
15
+ # This is the sole test that is run. Of course it'd be nicer to have more tests, but each one adds
16
+ # time, so... meh
17
+ def test_deploy_works
18
+ puts "Deploying once"
19
+ result = `bundle exec cap testing deploy`
20
+ assert_equal true, $?.success?, "Deployment failed. Output was:\n#{result}"
21
+
22
+ check_file_and_permissions
23
+
24
+ puts "Deploying twice"
25
+ result = `bundle exec cap testing deploy`
26
+ assert_equal true, $?.success?, "2nd Deployment failed. Output was:\n#{result}"
27
+
28
+ puts "Deploying the last time"
29
+ result = `bundle exec cap testing deploy`
30
+ assert_equal true, $?.success?, "3rd Deployment failed - likely a permissions error. Output was:\n#{result}"
31
+
32
+ puts "Testing rollback"
33
+ result = `bundle exec cap testing deploy:rollback`
34
+ assert_equal true, $?.success?, "Rollback failed. Output was:\n#{result}"
35
+ check_only_one_release
36
+ end
37
+
38
+ def check_file_and_permissions
39
+ release_dir_writable = false
40
+ release_dir_readable = false
41
+ release_artifact_writable = false
42
+ release_artifact_readable = false
43
+ on('deploy_target') do
44
+ releases_dir = '/tmp/capistrano-rails-artifact/releases'
45
+ timestamp = capture("ls #{releases_dir}").lines[0].chomp
46
+ release_dir = File.join(releases_dir,timestamp)
47
+
48
+ release_dir_writable = test("[ -w #{release_dir} ]")
49
+ release_dir_readable= test("[ -r #{release_dir} ]")
50
+ release_artifact_writable = test("[ -w #{release_dir}/ARTIFACT ]")
51
+ release_artifact_readable = test("[ -r #{release_dir}/ARTIFACT ]")
52
+ end
53
+ assert_equal true, release_dir_writable, "release dir is not writable"
54
+ assert_equal true, release_dir_readable, "release dir is not readable"
55
+ assert_equal true, release_artifact_writable, "release artifact is not writable"
56
+ assert_equal true, release_artifact_readable, "release artifact is not readable"
57
+ end
58
+
59
+ def check_only_one_release
60
+ dirs_in_releases = []
61
+ on('deploy_target') do
62
+ dirs_in_releases = capture("ls /tmp/capistrano-rails-artifact/releases").lines.map(&:chomp)
63
+ end
64
+ assert_equal 1, dirs_in_releases.size
65
+ end
66
+
67
+ def configure_sshkit_for_vagrant
68
+ require 'tempfile'
69
+ tempfile = Tempfile.open('vagrant-ssh-config')
70
+
71
+ system("vagrant ssh-config > #{tempfile.path}")
72
+
73
+ unless $?.success?
74
+ puts "You need to `vagrant up` first!"
75
+ exit(1)
76
+ end
77
+
78
+ SSHKit.config.backend.configure do |config|
79
+ config.ssh_options = {config: tempfile.path}
80
+ end
81
+ end
82
+ end
83
+
@@ -0,0 +1,17 @@
1
+ role :app, %w{deploy_target}
2
+ role :web, %w{deploy_target}
3
+
4
+ # Sets up Capistrano to be able to deploy into your vagrant box
5
+ require 'tempfile'
6
+ tempfile = Tempfile.open('vagrant-ssh-config')
7
+
8
+ system("vagrant ssh-config > #{tempfile.path}")
9
+
10
+ unless $?.success?
11
+ puts "You need to `vagrant up` first!"
12
+ exit(1)
13
+ end
14
+
15
+ set :ssh_options, {
16
+ config: [tempfile.path]
17
+ }
@@ -0,0 +1,12 @@
1
+ set :application, 'capistrano-rails-artifact'
2
+
3
+ #The Vagrantfile used python to start a simple server serving contents of /vagrant/test (which is actually this project's test directory)
4
+ set :rails_artifact_archive_location, 'http://127.0.0.1:8080/test-build-artifact.tar.gz'
5
+
6
+ set :rails_artifact_group, 'rails_runners'
7
+
8
+ set :deploy_to, '/tmp/capistrano-rails-artifact'
9
+
10
+ set :scm, :rails_artifact
11
+
12
+ set :keep_releases, 2 #we make this low so we can test that the cleanup of release dirs works
Binary file
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-rails-artifact
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Case Taintor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capistrano
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: A gem to allow you to deploy using a .tar.gz
70
+ email:
71
+ - case.taintor@klarna.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".capistrano/metrics"
77
+ - ".gitignore"
78
+ - Capfile
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - Vagrantfile
84
+ - capistrano-rails-artifact.gemspec
85
+ - lib/capistrano-rails-artifact.rb
86
+ - lib/capistrano-rails-artifact/version.rb
87
+ - lib/capistrano/rails_artifact.rb
88
+ - lib/capistrano/tasks/rails_artifact.rake
89
+ - test/capistrano-rails-artifact_test.rb
90
+ - test/config/deploy.rb
91
+ - test/config/deploy/testing.rb
92
+ - test/test-build-artifact.tar.gz
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A gem to allow you to deploy using a .tar.gz
117
+ test_files:
118
+ - test/capistrano-rails-artifact_test.rb
119
+ - test/config/deploy.rb
120
+ - test/config/deploy/testing.rb
121
+ - test/test-build-artifact.tar.gz