capistrano-scm-gitbuild 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/capistrano-scm-gitbuild.gemspec +27 -0
- data/lib/capistrano/gitbuild.rb +69 -0
- data/lib/capistrano/gitbuild/version.rb +5 -0
- data/lib/capistrano/tasks/gitbuild.rake +118 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2017caa89477864994ae16126283a80252575c11
|
4
|
+
data.tar.gz: 7ebf88ddd079a63ff1001173954dea4ff4d74732
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92b124e5f0afcb505b7ae3fa8266242ab5763dfc14b883f0770ca435734a23bd65f04f4996c74505d2b80f2edddcdc701955022894d8b09139e4f4c4710d6612
|
7
|
+
data.tar.gz: 0b72945b07cd6f2a1322464cfd84d6274854803525254af0d2a6d49ea85d81e032ac9dbaecfbb55a27c281537dd2bc70e6bbdd387e12067098d28e782ba5ba65
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jochen Verdeyen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Capistrano::GitBuild
|
2
|
+
|
3
|
+
A Capistrano 3.x deploy strategy.
|
4
|
+
|
5
|
+
The idea behind this strategy is to checkout the Git repository in a temporary directory first, on the local machine (the one which started the deploy task).
|
6
|
+
|
7
|
+
Hereafter, custom build tasks can be implemented on the checkout code (e.g. compile your static site with [Jekyll](http://jekyllrb.com/), compile [SASS](http://sass-lang.com/) or import some external modules using [Composer](https://getcomposer.org/) for your project or anything else).
|
8
|
+
|
9
|
+
Finally, the code will be archived in a tarball, uploaded to the servers and extracted in the release directory like normal.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'capistrano-scm-gitbuild'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install capistrano-scm-gitbuild
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Tell Capistrano to use the GitBuild deploy strategy, in `deploy.rb` like so:
|
30
|
+
```ruby
|
31
|
+
# Copy strategy
|
32
|
+
set :scm, :gitbuild
|
33
|
+
```
|
34
|
+
|
35
|
+
To deploy a subdirectory instead of the full root of the project, you can of course use `:repo_tree` which is supported by default in Capistrano, in `deploy.rb` like so:
|
36
|
+
```ruby
|
37
|
+
# Deploy subdirectory
|
38
|
+
set :repo_tree, 'project'
|
39
|
+
```
|
40
|
+
|
41
|
+
To implement your own build logic before the tarball is created and uploaded to the servers, you must implement the `gitbuild:build` task like so:
|
42
|
+
```ruby
|
43
|
+
namespace :gitbuild do
|
44
|
+
task :build do
|
45
|
+
run_locally do
|
46
|
+
# Implement custom build logic.
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
When you deploy, the repository will be checked out first in a temporary directory (locally - on the machine which started the deploy task).
|
53
|
+
After that you have the ability to implement custom build tasks.
|
54
|
+
Finally, a tarball will be created, uploaded to all servers and extracted.
|
55
|
+
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jover/capistrano-scm-gitbuild. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
|
66
|
+
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
71
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capistrano/gitbuild"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/gitbuild/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-scm-gitbuild"
|
8
|
+
spec.version = Capistrano::Gitbuild::VERSION
|
9
|
+
spec.authors = ["Jochen Verdeyen"]
|
10
|
+
spec.email = ["jochenverdeyen@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{GitBuild strategy for Capistrano 3}
|
13
|
+
spec.description = %q{Capistrano 3 build and copy strategy for git (checkout branch, apply build steps and deploy to server)}
|
14
|
+
spec.homepage = "https://github.com/jover/capistrano-scm-gitbuild"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'capistrano', '~> 3.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
load File.expand_path('../tasks/gitbuild.rake', __FILE__)
|
2
|
+
|
3
|
+
require "capistrano/scm"
|
4
|
+
require "capistrano/gitbuild/version"
|
5
|
+
|
6
|
+
set_if_empty :repo_path, -> { "#{fetch(:tmp_dir)}/#{fetch(:application)}-repo" }
|
7
|
+
|
8
|
+
class Capistrano::GitBuild < Capistrano::SCM
|
9
|
+
|
10
|
+
# execute git with argument in the context
|
11
|
+
#
|
12
|
+
def git(*args)
|
13
|
+
args.unshift :git
|
14
|
+
context.execute(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
module DefaultStrategy
|
18
|
+
def test
|
19
|
+
test! " [ -f #{repo_path}/HEAD ] "
|
20
|
+
end
|
21
|
+
|
22
|
+
def check
|
23
|
+
git :'ls-remote --heads', repo_url
|
24
|
+
end
|
25
|
+
|
26
|
+
def clone
|
27
|
+
if (depth = fetch(:git_shallow_clone))
|
28
|
+
git :clone, '--mirror', '--depth', depth, '--no-single-branch', repo_url, repo_path
|
29
|
+
else
|
30
|
+
git :clone, '--mirror', repo_url, repo_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
# Note: Requires git version 1.9 or greater
|
36
|
+
if (depth = fetch(:git_shallow_clone))
|
37
|
+
git :fetch, '--depth', depth, 'origin', fetch(:branch)
|
38
|
+
else
|
39
|
+
git :remote, :update
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def local_build_path
|
44
|
+
"#{fetch(:repo_path)}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def local_tarfile
|
48
|
+
"#{fetch(:tmp_dir)}/#{fetch(:application)}-#{fetch(:current_revision).strip}.tar.gz"
|
49
|
+
end
|
50
|
+
|
51
|
+
def remote_tarfile
|
52
|
+
"#{fetch(:tmp_dir)}/#{fetch(:application)}-#{fetch(:current_revision).strip}.tar.gz"
|
53
|
+
end
|
54
|
+
|
55
|
+
def release
|
56
|
+
if (tree = fetch(:repo_tree))
|
57
|
+
tree = tree.slice %r#^/?(.*?)/?$#, 1
|
58
|
+
components = tree.split('/').size
|
59
|
+
git :archive, fetch(:branch), tree, "| tar -x --strip-components #{components} -f - -C", local_build_path
|
60
|
+
else
|
61
|
+
git :archive, fetch(:branch), '| tar -x -f - -C', local_build_path
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch_revision
|
66
|
+
context.capture(:git, "rev-list --max-count=1 --abbrev-commit --abbrev=12 #{fetch(:branch)}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
namespace :gitbuild do
|
2
|
+
|
3
|
+
def strategy
|
4
|
+
@strategy ||= Capistrano::GitBuild.new(self, fetch(:git_strategy, Capistrano::GitBuild::DefaultStrategy))
|
5
|
+
end
|
6
|
+
|
7
|
+
set :git_environmental_variables, ->() {
|
8
|
+
{
|
9
|
+
git_askpass: "/bin/echo",
|
10
|
+
git_ssh: "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
desc 'Upload the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
|
15
|
+
task :wrapper do
|
16
|
+
run_locally do
|
17
|
+
execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
|
18
|
+
File.open("#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh", "w") do |file|
|
19
|
+
file.write ("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n")
|
20
|
+
end
|
21
|
+
execute :chmod, "+rx", "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Check that the repository is reachable'
|
26
|
+
task check: :'gitbuild:wrapper' do
|
27
|
+
fetch(:branch)
|
28
|
+
run_locally do
|
29
|
+
with fetch(:git_environmental_variables) do
|
30
|
+
strategy.check
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Clone the repo to the cache'
|
36
|
+
task clone: :'gitbuild:wrapper' do
|
37
|
+
run_locally do
|
38
|
+
execute :mkdir, '-p', repo_path
|
39
|
+
if strategy.test
|
40
|
+
info t(:mirror_exists, at: repo_path)
|
41
|
+
else
|
42
|
+
within repo_path do
|
43
|
+
with fetch(:git_environmental_variables) do
|
44
|
+
strategy.clone
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Update the repo mirror to reflect the origin state'
|
52
|
+
task update: :'gitbuild:clone' do
|
53
|
+
run_locally do
|
54
|
+
within repo_path do
|
55
|
+
with fetch(:git_environmental_variables) do
|
56
|
+
strategy.update
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'Create tarfile'
|
63
|
+
task :create_tarfile => [:'gitbuild:update', :'gitbuild:set_current_revision'] do
|
64
|
+
run_locally do
|
65
|
+
within repo_path do
|
66
|
+
with fetch(:git_environmental_variables) do
|
67
|
+
strategy.release
|
68
|
+
invoke 'gitbuild:build'
|
69
|
+
execute :tar, '--create --verbose --file', strategy.local_tarfile, '--directory', strategy.local_build_path, '.'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Build hook'
|
76
|
+
task :build do
|
77
|
+
# Custom build logic, to be implemented by the project which uses this deploy strategy.
|
78
|
+
#
|
79
|
+
# Implement like:
|
80
|
+
# | namespace :gitbuild do
|
81
|
+
# | task :build do
|
82
|
+
# | run_locally do
|
83
|
+
# | execute :jekyll, "build -s '#{fetch(:repo_path)}' -d '#{fetch(:repo_path)}/_site'"
|
84
|
+
# | end
|
85
|
+
# | end
|
86
|
+
# | end
|
87
|
+
end
|
88
|
+
|
89
|
+
desc 'Copy repo to releases'
|
90
|
+
task create_release: :'gitbuild:create_tarfile' do
|
91
|
+
on release_roles :all do
|
92
|
+
within deploy_to do
|
93
|
+
execute :mkdir, '-p', release_path
|
94
|
+
upload! strategy.local_tarfile, strategy.remote_tarfile
|
95
|
+
execute :tar, '--extract --verbose --file', strategy.remote_tarfile, '--directory', release_path
|
96
|
+
execute :rm, strategy.remote_tarfile
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
run_locally do
|
101
|
+
if File.exists? strategy.local_tarfile
|
102
|
+
execute :rm, strategy.local_tarfile
|
103
|
+
end
|
104
|
+
if Dir.exists? strategy.local_build_path
|
105
|
+
execute :rm, '-r', strategy.local_build_path
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Determine the revision that will be deployed'
|
111
|
+
task :set_current_revision do
|
112
|
+
run_locally do
|
113
|
+
with fetch(:git_environmental_variables) do
|
114
|
+
set :current_revision, strategy.fetch_revision
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-scm-gitbuild
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jochen Verdeyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Capistrano 3 build and copy strategy for git (checkout branch, apply
|
70
|
+
build steps and deploy to server)
|
71
|
+
email:
|
72
|
+
- jochenverdeyen@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- capistrano-scm-gitbuild.gemspec
|
85
|
+
- lib/capistrano/gitbuild.rb
|
86
|
+
- lib/capistrano/gitbuild/version.rb
|
87
|
+
- lib/capistrano/tasks/gitbuild.rake
|
88
|
+
homepage: https://github.com/jover/capistrano-scm-gitbuild
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.8
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: GitBuild strategy for Capistrano 3
|
112
|
+
test_files: []
|