pebblescape-receiver 0.0.1

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: a380d3820dab3615abcb768811f0bd41a4231fe1
4
+ data.tar.gz: 95a1ec851151b8b59f48e21c8d26a727eeae3e34
5
+ SHA512:
6
+ metadata.gz: c61dce284afb81b43c45d27c6a6acb16b213f3e087e5db058d7aa7cd6fcb62d6e03067e994b070bf6bc8a370752c3ad8db2e6d0f842ce01cf66d49138fbed9e6
7
+ data.tar.gz: f7b620746c664bc160737e8194a94a7ba21c8585db0d4128f2d752a3279a1f4d7b434d07d50061546a08eeda523ae9653a3fa21c2c0b48e3d6f6759531967fa4
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pebblescape-receiver.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kristjan Rang
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,29 @@
1
+ # Pebblescape::Receiver
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pebblescape-receiver'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pebblescape-receiver
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/pebblescape-receiver/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require "pebblescape/receiver"
3
+
4
+ # sync output
5
+ $stdout.sync = true
6
+
7
+ Pebblescape::Receiver.start ARGV[0], ARGV[1], ARGV
@@ -0,0 +1,66 @@
1
+ require "shellwords"
2
+ require "pebblescape/receiver/version"
3
+ require "pebblescape/receiver/shell_helpers"
4
+
5
+ module Pebblescape
6
+ module Receiver
7
+ def self.start(command, app, commandline=nil)
8
+ Receiver.new(command, app, commandline)
9
+ end
10
+
11
+ class Receiver
12
+ include Pebblescape::Receiver::ShellHelpers
13
+
14
+ attr_accessor :app, :app_path, :home
15
+
16
+ def initialize(command, app, commandline)
17
+ @app = app.gsub('\'', '')
18
+ @home = env("HOME")
19
+ @app_path = File.join(home, app)
20
+
21
+ # Pass through to git
22
+ if command.start_with?("git-")
23
+ if command == "git-receive-pack" && !repo_exists?
24
+ setup_hook
25
+ end
26
+
27
+ exec_git(commandline)
28
+ end
29
+
30
+ deploy if command == "deploy"
31
+ end
32
+
33
+ def deploy
34
+ old_rev, new_rev, ref_name = STDIN.gets.split
35
+
36
+ if ref_name == "refs/heads/master"
37
+ puts new_rev
38
+ exit 1
39
+ else
40
+ error("WARNING: deploy did not complete, you must push to master.")
41
+ end
42
+ end
43
+
44
+ def exec_git(command)
45
+ exec(user_env_hash, "git-shell -c #{command.join(" ").shellescape}")
46
+ end
47
+
48
+ def setup_hook
49
+ run! "git init --bare #{app_path}"
50
+ hook_path = File.join(app_path, "hooks", "pre-receive")
51
+ hook = <<EOF
52
+ #!/usr/bin/env bash
53
+ set -e; set -o pipefail;
54
+ cat | PEBBLES_ROOT="#{home}" pebblescape-receive deploy #{app} | sed -u "s/^/"$'\e[1G'"/"
55
+ EOF
56
+
57
+ File.open(hook_path, 'w+') { |f| f.write(hook) }
58
+ File.chmod(0777, hook_path)
59
+ end
60
+
61
+ def repo_exists?
62
+ Dir.exists?(File.join(app_path, "refs"))
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,143 @@
1
+ require "shellwords"
2
+ require "pathname"
3
+
4
+ module Pebblescape
5
+ module Receiver
6
+ module ShellHelpers
7
+ @@user_env_hash = {}
8
+
9
+ def self.user_env_hash
10
+ @@user_env_hash
11
+ end
12
+
13
+ def user_env_hash
14
+ @@user_env_hash
15
+ end
16
+
17
+ def env(var)
18
+ ENV[var] || user_env_hash[var]
19
+ end
20
+
21
+ def self.blacklist?(key)
22
+ %w(PATH GEM_PATH GEM_HOME GIT_DIR).include?(key)
23
+ end
24
+
25
+ def self.initialize_env(path)
26
+ env_dir = Pathname.new("#{path}")
27
+ if env_dir.exist? && env_dir.directory?
28
+ env_dir.each_child do |file|
29
+ key = file.basename.to_s
30
+ value = file.read.strip
31
+ user_env_hash[key] = value unless blacklist?(key)
32
+ end
33
+ end
34
+ end
35
+
36
+ # display error message and stop the build process
37
+ # @param [String] error message
38
+ def error(message)
39
+ Kernel.puts " !"
40
+ message.split("\n").each do |line|
41
+ Kernel.puts " ! #{line.strip}"
42
+ end
43
+ Kernel.puts " !"
44
+ log "exit", :error => message if respond_to?(:log)
45
+ exit 1
46
+ end
47
+
48
+ def run!(command, options = {})
49
+ result = run(command, options)
50
+ error("Command: '#{command}' failed unexpectedly:\n#{result}") unless $?.success?
51
+ return result
52
+ end
53
+
54
+ # doesn't do any special piping. stderr won't be redirected.
55
+ # @param [String] command to be run
56
+ # @return [String] output of stdout
57
+ def run_no_pipe(command, options = {})
58
+ run(command, options.merge({:out => ""}))
59
+ end
60
+
61
+ # run a shell command and pipe stderr to stdout
62
+ # @param [String] command
63
+ # @option options [String] :out the IO redirect of the command
64
+ # @option options [Hash] :env explicit environment to run command in
65
+ # @option options [Boolean] :user_env whether or not a user's environment variables will be loaded
66
+ def run(command, options = {})
67
+ %x{ #{command_options_to_string(command, options)} }
68
+ end
69
+
70
+ # run a shell command and pipe stderr to /dev/null
71
+ # @param [String] command to be run
72
+ # @return [String] output of stdout
73
+ def run_stdout(command, options = {})
74
+ options[:out] ||= '2>/dev/null'
75
+ run(command, options)
76
+ end
77
+
78
+ def command_options_to_string(command, options)
79
+ options[:env] ||= {}
80
+ options[:out] ||= "2>&1"
81
+ options[:env] = user_env_hash.merge(options[:env]) if options[:user_env]
82
+ env = options[:env].map {|key, value| "#{key.shellescape}=#{value.shellescape}" }.join(" ")
83
+ "/usr/bin/env #{env} bash -c #{command.shellescape} #{options[:out]} "
84
+ end
85
+
86
+ # run a shell command and stream the output
87
+ # @param [String] command to be run
88
+ def pipe(command, options = {})
89
+ output = ""
90
+ IO.popen(command_options_to_string(command, options)) do |io|
91
+ until io.eof?
92
+ buffer = io.gets
93
+ output << buffer
94
+ options[:no_indent] ? Kernel.puts(buffer) : puts(buffer)
95
+ end
96
+ end
97
+
98
+ output
99
+ end
100
+
101
+ def pipe!(command, options = {})
102
+ pipe(command, options)
103
+ exit 1 unless $?.success?
104
+ end
105
+
106
+ # display a topic message
107
+ # (denoted by ----->)
108
+ # @param [String] topic message to be displayed
109
+ def topic(message)
110
+ Kernel.puts "-----> #{message}"
111
+ $stdout.flush
112
+ end
113
+
114
+ # display a message in line
115
+ # (indented by 6 spaces)
116
+ # @param [String] message to be displayed
117
+ def puts(message)
118
+ message.split("\n").each do |line|
119
+ super " #{line.strip}"
120
+ end
121
+ $stdout.flush
122
+ end
123
+
124
+ def warn(message, options = {})
125
+ if options.key?(:inline) ? options[:inline] : false
126
+ topic "Warning:"
127
+ puts message
128
+ end
129
+ @warnings ||= []
130
+ @warnings << message
131
+ end
132
+
133
+ def deprecate(message)
134
+ @deprecations ||= []
135
+ @deprecations << message
136
+ end
137
+
138
+ def noshellescape(string)
139
+ NoShellEscape.new(string)
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,5 @@
1
+ module Pebblescape
2
+ module Receiver
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pebblescape/receiver/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pebblescape-receiver"
8
+ spec.version = Pebblescape::Receiver::VERSION
9
+ spec.authors = ["Kristjan Rang"]
10
+ spec.email = ["mail@rang.ee"]
11
+ spec.summary = %q{Receives git pushes and deploys them to pebblescape}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/pebblescape/pebblescape"
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 "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pebblescape-receiver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kristjan Rang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-02 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: rake
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
+ description: ''
42
+ email:
43
+ - mail@rang.ee
44
+ executables:
45
+ - pebblescape-receiver
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/pebblescape-receiver
55
+ - lib/pebblescape/receiver.rb
56
+ - lib/pebblescape/receiver/shell_helpers.rb
57
+ - lib/pebblescape/receiver/version.rb
58
+ - pebblescape-receiver.gemspec
59
+ homepage: https://github.com/pebblescape/pebblescape
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Receives git pushes and deploys them to pebblescape
83
+ test_files: []