unfold 1.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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/uf +16 -0
  3. data/lib/unfold.rb +100 -0
  4. metadata +75 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60b7400582a701247f1a4eff588c1c1466a56d9c
4
+ data.tar.gz: b3f59cbf2f4492a42745ba678c0886772c2f227d
5
+ SHA512:
6
+ metadata.gz: d0add756ea37a281bb44758b72dc4998b002e6a9a4fd87fbb2e44d47c47f2289b9ee157c5acbc5bff0c5cd80bbe177d50aa5ebb186423ee981c7246462cd30fb
7
+ data.tar.gz: d9771451840810bcc1f5e36cc40c34b385a0dec8037d18995152bb59a1373c00f361dd4d55295ef2698ea64ef8ff0bb83576d00aaa0434879a08451a23281164
data/bin/uf ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require "unfold"
3
+
4
+ case ARGV[0]
5
+ when "setup"
6
+ case ARGV[1]
7
+ when "remote"
8
+ Unfold.setup_remote()
9
+ when "local"
10
+ Unfold.setup_local()
11
+ else
12
+ puts "Invalid setup location."
13
+ end
14
+ else
15
+ puts "Invalid command."
16
+ end
data/lib/unfold.rb ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ require "net/ssh"
3
+ require "net/scp"
4
+ require "stringio"
5
+
6
+ module Unfold
7
+
8
+ # the method used in the config file
9
+ def self.config(env_arrays)
10
+ return nil if block_given? == false
11
+ configs = []
12
+ env_arrays.each do |env|
13
+ config = Config.new
14
+ config.env = env.to_s
15
+ yield(config,env.to_s)
16
+ configs << config
17
+ end
18
+ return configs
19
+ end
20
+
21
+ class Config
22
+ attr_accessor :remote_host, :remote_user, :remote_destination, :appname, :env
23
+
24
+ # hashify config object
25
+ # not used anywhere
26
+ def to_hash
27
+ hash = {}
28
+ self.instance_variables.each do |ivar|
29
+ hash[ivar.to_s.delete("@")] = self.instance_variable_get(ivar)
30
+ end
31
+ return hash
32
+ end
33
+ end
34
+
35
+ # creates a post-receive hook script from a config file
36
+ def self.post_receive_script(c)
37
+ log_location = "~/.unfold/logs/#{c.appname}-#{c.env}/deploy.log"
38
+ postdep = "#{c.remote_destination}/config/unfold_postdeploy.rb"
39
+ return %{
40
+ #!/bin/bash\n
41
+ read oldrev newrev refname\n
42
+ if [ "$refname" = "refs/heads/master" ]; then\n
43
+ unset GIT_DIR\n
44
+ echo "Unfold: Deploying $newrev" >> #{log_location}\n
45
+ cd #{c.remote_destination}; git pull origin master\n
46
+ echo "Unfold: SUCCESS! Deployed $newrev" >> #{log_location}\n
47
+ if [ -e #{postdep} ]; then\n
48
+ bash -lc "ruby #{postdep}"\n
49
+ fi\n
50
+ fi
51
+ }
52
+ end
53
+
54
+ def self.read_config
55
+ eval(File.read("#{`git rev-parse --show-toplevel`.strip}/config/unfold.rb"))
56
+ end
57
+
58
+ def self.setup_local
59
+ configs = Unfold.read_config
60
+
61
+ # set up the local git repo's remotes
62
+ configs.each do |c|
63
+ # add it as a remote to the local git repo
64
+ repo_path = "~/.unfold/repos/#{c.appname}-#{c.env}.git"
65
+ `git remote add #{c.env} #{c.remote_user}@#{c.remote_host}:#{repo_path}`
66
+ end
67
+ end
68
+
69
+ def self.setup_remote()
70
+ # load configs from config file
71
+ configs = Unfold.read_config
72
+
73
+ configs.each do |c|
74
+ # SSH into the remote
75
+ Net::SSH.start(c.remote_host, c.remote_user) do |ssh|
76
+ # get the home directory
77
+ path = ssh.exec!("cd; pwd").strip
78
+
79
+ # setup
80
+ repo_path = "#{path}/.unfold/repos/#{c.appname}-#{c.env}.git" # doesn't include ~/ so that it can be used in the remote url
81
+ logs_path = "#{path}/.unfold/logs/#{c.appname}-#{c.env}/"
82
+
83
+ # create the remote repo
84
+ print ssh.exec!("mkdir -p #{repo_path}; mkdir -p #{logs_path}")
85
+ print ssh.exec!("cd #{repo_path}; git --bare init")
86
+
87
+ # upload the post-receive hook
88
+ script = StringIO.new(Unfold.post_receive_script(c))
89
+ dest = "#{repo_path.sub("~",path)}/hooks/post-receive"
90
+ ssh.scp.upload!(script, dest)
91
+
92
+ # make it executable
93
+ print ssh.exec!("chmod 775 #{repo_path}/hooks/post-receive")
94
+
95
+ # move to the deployment target and locally clone the repo
96
+ print ssh.exec!("cd #{c.remote_destination}; git clone #{repo_path} .")
97
+ end
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unfold
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Symer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-scp
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: Dead simple git deployment with minimal config.
42
+ email:
43
+ - nate@natesymer.com
44
+ executables:
45
+ - uf
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/uf
50
+ - lib/unfold.rb
51
+ homepage: https://github.com/fhsjaagshs/unfold
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.2.1
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Deploy using git like a boss
75
+ test_files: []