syncwrap 1.5.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/History.rdoc +19 -0
  3. data/Manifest.txt +82 -34
  4. data/README.rdoc +96 -48
  5. data/Rakefile +0 -65
  6. data/bin/syncwrap +27 -0
  7. data/examples/LAYOUT.rdoc +70 -0
  8. data/examples/Rakefile +16 -0
  9. data/examples/ec2.rb +44 -0
  10. data/examples/hello.rb +14 -0
  11. data/examples/hello_binding.rb +27 -0
  12. data/examples/jruby.rb +11 -0
  13. data/examples/private/aws.json +4 -0
  14. data/examples/rput.rb +24 -0
  15. data/examples/sync/home/bob/.ssh/authorized_keys +1 -0
  16. data/examples/sync/tmp/sample.erb +3 -0
  17. data/lib/syncwrap/amazon_ec2.rb +236 -0
  18. data/lib/syncwrap/amazon_ws.rb +308 -0
  19. data/lib/syncwrap/base.rb +4 -2
  20. data/lib/syncwrap/cli.rb +328 -0
  21. data/lib/syncwrap/component.rb +443 -0
  22. data/lib/syncwrap/components/commercial_jdk.rb +76 -0
  23. data/lib/syncwrap/components/cruby_vm.rb +144 -0
  24. data/lib/syncwrap/components/etc_hosts.rb +44 -0
  25. data/lib/syncwrap/{geminabox.rb → components/geminabox.rb} +12 -17
  26. data/lib/syncwrap/components/hashdot.rb +97 -0
  27. data/lib/syncwrap/components/iyyov.rb +144 -0
  28. data/lib/syncwrap/components/iyyov_daemon.rb +125 -0
  29. data/lib/syncwrap/components/jruby_vm.rb +122 -0
  30. data/lib/syncwrap/components/mdraid.rb +204 -0
  31. data/lib/syncwrap/components/network.rb +99 -0
  32. data/lib/syncwrap/components/open_jdk.rb +70 -0
  33. data/lib/syncwrap/components/postgresql.rb +159 -0
  34. data/lib/syncwrap/components/qpid.rb +303 -0
  35. data/lib/syncwrap/components/rhel.rb +71 -0
  36. data/lib/syncwrap/components/run_user.rb +99 -0
  37. data/lib/syncwrap/components/ubuntu.rb +85 -0
  38. data/lib/syncwrap/components/users.rb +200 -0
  39. data/lib/syncwrap/context.rb +260 -0
  40. data/lib/syncwrap/distro.rb +53 -60
  41. data/lib/syncwrap/formatter.rb +149 -0
  42. data/lib/syncwrap/host.rb +134 -0
  43. data/lib/syncwrap/main.rb +62 -0
  44. data/lib/syncwrap/path_util.rb +55 -0
  45. data/lib/syncwrap/rsync.rb +227 -0
  46. data/lib/syncwrap/ruby_support.rb +110 -0
  47. data/lib/syncwrap/shell.rb +207 -0
  48. data/lib/syncwrap.rb +367 -1
  49. data/{etc → sync/etc}/gemrc +1 -3
  50. data/sync/etc/hosts.erb +8 -0
  51. data/{etc/init.d/iyyov → sync/etc/init.d/iyyov.erb} +35 -7
  52. data/sync/etc/sysconfig/pgsql/postgresql.erb +2 -0
  53. data/sync/src/hashdot/Makefile.erb +98 -0
  54. data/sync/src/hashdot/profiles/default.hdp.erb +25 -0
  55. data/sync/src/hashdot/profiles/jruby-common.hdp +28 -0
  56. data/sync/src/hashdot/profiles/jruby-shortlived.hdp +9 -0
  57. data/sync/src/hashdot/profiles/jruby.hdp.erb +13 -0
  58. data/sync/src/hashdot/profiles/shortlived.hdp +6 -0
  59. data/sync/var/iyyov/default/config.rb +1 -0
  60. data/sync/var/iyyov/default/daemon.rb.erb +15 -0
  61. data/sync/var/iyyov/jobs.rb.erb +4 -0
  62. data/test/muddled_sync.rb +13 -0
  63. data/test/setup.rb +39 -0
  64. data/test/sync/d1/bar +1 -0
  65. data/test/sync/d1/foo.erb +1 -0
  66. data/test/sync/d3/d2/bar +1 -0
  67. data/test/sync/d3/d2/foo.erb +1 -0
  68. data/test/test_components.rb +108 -0
  69. data/test/test_context.rb +107 -0
  70. data/test/test_context_rput.rb +289 -0
  71. data/test/test_rsync.rb +138 -0
  72. data/test/test_shell.rb +233 -0
  73. data/test/test_space.rb +218 -0
  74. data/test/test_space_main.rb +40 -0
  75. data/test/zfile +1 -0
  76. metadata +204 -71
  77. data/etc/sysconfig/pgsql/postgresql +0 -2
  78. data/lib/syncwrap/aws.rb +0 -448
  79. data/lib/syncwrap/common.rb +0 -161
  80. data/lib/syncwrap/ec2.rb +0 -59
  81. data/lib/syncwrap/hashdot.rb +0 -70
  82. data/lib/syncwrap/iyyov.rb +0 -139
  83. data/lib/syncwrap/java.rb +0 -61
  84. data/lib/syncwrap/jruby.rb +0 -118
  85. data/lib/syncwrap/postgresql.rb +0 -135
  86. data/lib/syncwrap/qpid.rb +0 -251
  87. data/lib/syncwrap/remote_task.rb +0 -199
  88. data/lib/syncwrap/rhel.rb +0 -67
  89. data/lib/syncwrap/ubuntu.rb +0 -78
  90. data/lib/syncwrap/user_run.rb +0 -102
  91. data/test/test_syncwrap.rb +0 -202
  92. data/var/iyyov/jobs.rb +0 -11
  93. /data/{etc → sync/etc}/corosync/corosync.conf +0 -0
  94. /data/{etc → sync/etc}/corosync/uidgid.d/qpid +0 -0
  95. /data/{etc → sync/etc}/init.d/qpidd +0 -0
  96. /data/{etc → sync/etc}/sysctl.d/61-postgresql-shm.conf +0 -0
  97. /data/{usr/local → sync/jruby}/bin/jgem +0 -0
  98. /data/{postgresql → sync/postgresql}/rhel/pg_hba.conf +0 -0
  99. /data/{postgresql → sync/postgresql}/rhel/pg_ident.conf +0 -0
  100. /data/{postgresql → sync/postgresql}/rhel/postgresql.conf +0 -0
  101. /data/{postgresql → sync/postgresql}/ubuntu/environment +0 -0
  102. /data/{postgresql → sync/postgresql}/ubuntu/pg_ctl.conf +0 -0
  103. /data/{postgresql → sync/postgresql}/ubuntu/pg_hba.conf +0 -0
  104. /data/{postgresql → sync/postgresql}/ubuntu/pg_ident.conf +0 -0
  105. /data/{postgresql → sync/postgresql}/ubuntu/postgresql.conf +0 -0
  106. /data/{postgresql → sync/postgresql}/ubuntu/start.conf +0 -0
  107. /data/{usr → sync/usr}/local/etc/qpidd.conf +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7750e1149348fc952ef8d2dd124282861961bc4f
4
+ data.tar.gz: 1c183faa0793ee65741b64366e1463b3c4593e51
5
+ SHA512:
6
+ metadata.gz: db6263d45a815839d43aed07c08a22cfc5dc578cbcb9c3438e3ab74ba619ba78dd3d8780beaf4648d27336284192cd4112b9e2ce6edd7d3029b5089d6db441fa
7
+ data.tar.gz: 694c6a0e63d9358f6831f21f16bfe9f2caffcf51c27080689e85545e24a9ce1f4b0c0ec3a44fcaa5610586e92545e1b7ad11c52e4fb696405fdde281fc0c6b1f
data/History.rdoc CHANGED
@@ -1,3 +1,22 @@
1
+ === 2.0.0 (2014-2-26)
2
+ * Major rewrite with only very limited conceptual compatibility with
3
+ 1.x. See README, LAYOUT, and examples.
4
+ * Now requires ruby 1.9 stdlib. Internally makes extensive use of new
5
+ Hash syntax.
6
+ * New CLI, `syncwrap` command and sync.rb file replaces
7
+ Vlad/RemoteTask and rake (though rake integration is still
8
+ possible.) SyncWrap 2 is a standalone complete solution.
9
+ * Component classes and dynamic binding replaces the subject-oriented
10
+ module mixins.
11
+ * Block oriented, thread safe, colored console output
12
+ * SyncWrap::Component#sh replaces `run`, includes a command queue
13
+ and compossible scripts.
14
+ * SyncWrap::Component#rput with multiple sync_paths and transparent
15
+ ERB template support.
16
+ * Extensive updates, templating, reliability improvements, and
17
+ optimization of existing provisions (now Components)
18
+ * New Iyyov jobs.d support and standardized SyncWrap::IyyovDeamon
19
+
1
20
  === 1.5.2 (2013-4-10)
2
21
  * Add check for init, aws_configure only if aws_config_json file
3
22
  exists.
data/Manifest.txt CHANGED
@@ -2,40 +2,88 @@ History.rdoc
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
- etc/gemrc
6
- etc/corosync/corosync.conf
7
- etc/corosync/uidgid.d/qpid
8
- etc/init.d/iyyov
9
- etc/init.d/qpidd
10
- etc/sysconfig/pgsql/postgresql
11
- etc/sysctl.d/61-postgresql-shm.conf
5
+ bin/syncwrap
6
+ examples/LAYOUT.rdoc
7
+ examples/Rakefile
8
+ examples/ec2.rb
9
+ examples/hello.rb
10
+ examples/hello_binding.rb
11
+ examples/jruby.rb
12
+ examples/rput.rb
13
+ examples/private/aws.json
14
+ examples/sync/home/bob/.ssh/authorized_keys
15
+ examples/sync/tmp/sample.erb
12
16
  lib/syncwrap/base.rb
13
17
  lib/syncwrap.rb
14
- lib/syncwrap/aws.rb
15
- lib/syncwrap/common.rb
18
+ lib/syncwrap/amazon_ec2.rb
19
+ lib/syncwrap/amazon_ws.rb
20
+ lib/syncwrap/cli.rb
21
+ lib/syncwrap/component.rb
22
+ lib/syncwrap/context.rb
16
23
  lib/syncwrap/distro.rb
17
- lib/syncwrap/ec2.rb
18
- lib/syncwrap/geminabox.rb
19
- lib/syncwrap/hashdot.rb
20
- lib/syncwrap/iyyov.rb
21
- lib/syncwrap/java.rb
22
- lib/syncwrap/jruby.rb
23
- lib/syncwrap/postgresql.rb
24
- lib/syncwrap/qpid.rb
25
- lib/syncwrap/remote_task.rb
26
- lib/syncwrap/rhel.rb
27
- lib/syncwrap/ubuntu.rb
28
- lib/syncwrap/user_run.rb
29
- postgresql/rhel/pg_hba.conf
30
- postgresql/rhel/pg_ident.conf
31
- postgresql/rhel/postgresql.conf
32
- postgresql/ubuntu/environment
33
- postgresql/ubuntu/pg_ctl.conf
34
- postgresql/ubuntu/pg_hba.conf
35
- postgresql/ubuntu/pg_ident.conf
36
- postgresql/ubuntu/postgresql.conf
37
- postgresql/ubuntu/start.conf
38
- test/test_syncwrap.rb
39
- usr/local/bin/jgem
40
- usr/local/etc/qpidd.conf
41
- var/iyyov/jobs.rb
24
+ lib/syncwrap/formatter.rb
25
+ lib/syncwrap/host.rb
26
+ lib/syncwrap/main.rb
27
+ lib/syncwrap/path_util.rb
28
+ lib/syncwrap/rsync.rb
29
+ lib/syncwrap/ruby_support.rb
30
+ lib/syncwrap/shell.rb
31
+ lib/syncwrap/components/commercial_jdk.rb
32
+ lib/syncwrap/components/cruby_vm.rb
33
+ lib/syncwrap/components/etc_hosts.rb
34
+ lib/syncwrap/components/geminabox.rb
35
+ lib/syncwrap/components/hashdot.rb
36
+ lib/syncwrap/components/iyyov.rb
37
+ lib/syncwrap/components/iyyov_daemon.rb
38
+ lib/syncwrap/components/jruby_vm.rb
39
+ lib/syncwrap/components/mdraid.rb
40
+ lib/syncwrap/components/network.rb
41
+ lib/syncwrap/components/open_jdk.rb
42
+ lib/syncwrap/components/postgresql.rb
43
+ lib/syncwrap/components/qpid.rb
44
+ lib/syncwrap/components/rhel.rb
45
+ lib/syncwrap/components/run_user.rb
46
+ lib/syncwrap/components/ubuntu.rb
47
+ lib/syncwrap/components/users.rb
48
+ sync/etc/gemrc
49
+ sync/etc/hosts.erb
50
+ sync/etc/corosync/corosync.conf
51
+ sync/etc/corosync/uidgid.d/qpid
52
+ sync/etc/init.d/iyyov.erb
53
+ sync/etc/init.d/qpidd
54
+ sync/etc/sysconfig/pgsql/postgresql.erb
55
+ sync/etc/sysctl.d/61-postgresql-shm.conf
56
+ sync/jruby/bin/jgem
57
+ sync/postgresql/rhel/pg_hba.conf
58
+ sync/postgresql/rhel/pg_ident.conf
59
+ sync/postgresql/rhel/postgresql.conf
60
+ sync/postgresql/ubuntu/environment
61
+ sync/postgresql/ubuntu/pg_ctl.conf
62
+ sync/postgresql/ubuntu/pg_hba.conf
63
+ sync/postgresql/ubuntu/pg_ident.conf
64
+ sync/postgresql/ubuntu/postgresql.conf
65
+ sync/postgresql/ubuntu/start.conf
66
+ sync/src/hashdot/Makefile.erb
67
+ sync/src/hashdot/profiles/default.hdp.erb
68
+ sync/src/hashdot/profiles/jruby-common.hdp
69
+ sync/src/hashdot/profiles/jruby-shortlived.hdp
70
+ sync/src/hashdot/profiles/jruby.hdp.erb
71
+ sync/src/hashdot/profiles/shortlived.hdp
72
+ sync/usr/local/etc/qpidd.conf
73
+ sync/var/iyyov/jobs.rb.erb
74
+ sync/var/iyyov/default/config.rb
75
+ sync/var/iyyov/default/daemon.rb.erb
76
+ test/muddled_sync.rb
77
+ test/setup.rb
78
+ test/test_components.rb
79
+ test/test_context.rb
80
+ test/test_context_rput.rb
81
+ test/test_rsync.rb
82
+ test/test_shell.rb
83
+ test/test_space.rb
84
+ test/test_space_main.rb
85
+ test/zfile
86
+ test/sync/d1/bar
87
+ test/sync/d1/foo.erb
88
+ test/sync/d3/d2/bar
89
+ test/sync/d3/d2/foo.erb
data/README.rdoc CHANGED
@@ -1,85 +1,133 @@
1
1
  = SyncWrap
2
2
 
3
3
  * http://github.com/dekellum/syncwrap
4
+ * {<img src="https://travis-ci.org/dekellum/syncwrap.png" />}[https://travis-ci.org/dekellum/syncwrap]
4
5
 
5
6
  == Description
6
7
 
7
- A generalized and modular set of provisioning and deployment routines.
8
- The Rake-centric Vlad and not-actually-Rake Capistrano both suffer
9
- from lack of objects, e.g. the ability to customize and mix-in
10
- behavior. SyncWrap offers an Object/Module system that can be used
11
- with either.
8
+ A rather direct provisioning and deployment system in ruby, bash over
9
+ ssh, and rsync. SyncWrap is a refreshingly straightforward, DSL-free
10
+ non-framework with no central server or repository requirements. The
11
+ "magic", if any, lies in the elegant component model, the shell
12
+ command queue, and a few powerful methods like rput (augmented rsync).
12
13
 
13
14
  == Features
14
15
 
15
- * Multi-line shell support in SyncWrap::Common#run,
16
- SyncWrap::Common#sudo for more natural script embedding
16
+ * Default Thread-per-host parallel operation, with synchronized
17
+ block/live console output for debugging.
17
18
 
18
- * SyncWrap::Common::rput offers some useful rsync magic, like setting
19
- the owner of placed remote files
19
+ * Multi-line shell support (often via here-document), command queue,
20
+ and composition support in SyncWrap::Component#sh for more natural
21
+ script embedding. You'll know you are provisioning with bash, in
22
+ all its syntactic glory.
20
23
 
21
- * Platform differences are factored out into platform-specific modules
24
+ * SyncWrap::Component#rput wraps rsync, with support for multiple
25
+ source roots, transparent ERB templates, and target file
26
+ owner/permissions control. Returns the file change status allowing
27
+ reactive scripting (i.e. restart daemon since config has changed.)
22
28
 
23
- * SyncWrap::RemoteTask rake-remote_task adapter (see synopsis below)
29
+ * Linux distro differences are factored out into distro-specific
30
+ components with utility methods exposed in host context.
24
31
 
25
- * Gem install utilities. e.g. SyncWrap::JRuby#jruby_check_gem,
26
- SyncWrap::JRuby#jruby_install_gem
32
+ * SyncWrap::AmazonEC2 provider with host profiles: create and
33
+ provision hosts in a single step.
27
34
 
28
- == Provisions
35
+ * Independent of (but easily integrated into) rake
29
36
 
30
- Currently the following provisions are provided:
37
+ * Depends only on ruby 1.9+ stdlib Open3 for interaction with bash,
38
+ ssh and rsync. Actually, really works on jruby 1.6.8 (--1.9 mode)
39
+ and 1.7+
31
40
 
32
- * SyncWrap::AWS for EC2 instances, mdraid over EBS volumes, and
33
- Route53 DNS updates.
41
+ == Synopsis
34
42
 
35
- * SyncWrap::PostgreSQL
43
+ Simplest example. Place the following in a sync.rb file:
36
44
 
37
- * Complete SyncWrap::Java, SyncWrap::Hashdot, SyncWrap::JRuby stack
45
+ class Greeter < SyncWrap::Component
46
+ def install
47
+ say_it
48
+ end
38
49
 
39
- * SyncWrap::Iyyov job scheduler and process monitor
50
+ def say_it
51
+ sh <<-SH
52
+ echo "Hello from #{host.name}"
53
+ SH
54
+ end
55
+ end
40
56
 
41
- * SyncWrap::UserRun for setup of a run user for deployed daemons, jobs
42
- and var directories.
57
+ host 'localhost', Greeter.new
43
58
 
44
- == Synopsis
59
+ Try it via the command line:
45
60
 
46
- For example, in your Rakefile with the SyncWrap::RemoteTask adapter:
61
+ gem install syncwrap
62
+ syncwrap --help
63
+ syncwrap -f ./sync.rb --list # -f default; list
64
+ syncwrap # Run it
65
+ syncwrap -v # Run it with full verbose output
66
+ syncwrap -v Greeter.say_it # Without Greeter#install default
47
67
 
48
- class SyncWrapper
68
+ Output from syncwrap -v (minus the terminal color):
49
69
 
50
- # Include these support modules for the tasks below, or include
51
- # your own.
70
+ == localhost #<Module:0x00000001e95678>::Greeter#install: enqueue
71
+ <-- sh localhost (-v coalesce live)
72
+ echo "Hello from localhost"
73
+ Hello from localhost
74
+ --> Exit 0 (success)
52
75
 
53
- include SyncWrap::Java
54
- include SyncWrap::Hashdot
55
- include SyncWrap::JRuby
56
- include SyncWrap::Ubuntu
76
+ See more elaborate examples, including ec2 provider support, in the
77
+ examples directory and LAYOUT.
57
78
 
58
- include SyncWrap::RemoteTask
79
+ == Components
59
80
 
60
- def initialize
61
- super
62
- self.common_prefix = '/usr/local'
63
- end
81
+ Components implementing SyncWrap::Distro, to expose common utility
82
+ methods like dist_install:
64
83
 
65
- def define_tasks
66
- desc "Combined Java, Hashdot, JRuby Deployment"
67
- remote_task :jruby_deploy do
68
- java_install
69
- hashdot_install
70
- jruby_install
71
- end
72
- end
84
+ * SyncWrap::RHEL (also supports CentOS, Amazon Linux)
85
+ * SyncWrap::Ubuntu
73
86
 
74
- # Override any of the support methods as needed.
87
+ Components implementing \#install:
75
88
 
76
- end
89
+ * SyncWrap::MDRaid - Software raid, lvm volumes, filesystems, mounts
90
+
91
+ * SyncWrap::Network and SyncWrap::EtcHosts - hostname, static names,
92
+ resolver config
93
+
94
+ * SyncWrap::Users - developer accounts, home directory files (incl. ssh
95
+ keys), sudoers access
96
+
97
+ * SyncWrap::RunUser - a user for running deployed daemons, jobs, in
98
+ var directories.
99
+
100
+ * SyncWrap::PostgreSQL
101
+
102
+ * SyncWrap::OpenJDK or SyncWrap::CommercialJDK
103
+
104
+ * SyncWrap::JRubyVM and/or SyncWrap::CRubyVM (MRI, from source)
105
+
106
+ * SyncWrap::Iyyov - job scheduler and process monitor with
107
+ utilities for SyncWrap::IyyovDaemon deployment.
108
+
109
+ * SyncWrap::Geminabox - private gem server
110
+
111
+ * SyncWrap::Qpid - AMQP broker
112
+
113
+ === Component wish list
114
+
115
+ The above only represents my more recent project needs. Pull requests
116
+ to add, for example, the following would be well received:
117
+
118
+ * Bundler install, for example for Sinatra apps
119
+ * Bluepill
120
+ * Rails (extra credit: without git fetch or per-host asset compile)
121
+ * Nginx
122
+ * Mongo
123
+ * Redis
77
124
 
78
- SyncWrapper.new.define_tasks
125
+ \SyncWrap makes it reasonable to implement any of the above in the
126
+ privacy of your own office.
79
127
 
80
128
  == License
81
129
 
82
- Copyright (c) 2011-2013 David Kellum
130
+ Copyright (c) 2011-2014 David Kellum
83
131
 
84
132
  Licensed under the Apache License, Version 2.0 (the "License"); you
85
133
  may not use this file except in compliance with the License. You
data/Rakefile CHANGED
@@ -6,68 +6,3 @@ require 'bundler/setup'
6
6
  require 'rjack-tarpit'
7
7
 
8
8
  RJack::TarPit.new( 'syncwrap' ).define_tasks
9
-
10
- require 'syncwrap/java'
11
- require 'syncwrap/hashdot'
12
- require 'syncwrap/jruby'
13
- require 'syncwrap/iyyov'
14
- require 'syncwrap/rhel'
15
- require 'syncwrap/aws'
16
- require 'syncwrap/postgresql'
17
- require 'syncwrap/remote_task'
18
- require 'syncwrap/geminabox'
19
-
20
- class SyncWrapper
21
- include SyncWrap::Java
22
- include SyncWrap::Hashdot
23
- include SyncWrap::JRuby
24
- include SyncWrap::Iyyov
25
- include SyncWrap::RHEL
26
- include SyncWrap::AWS
27
- include SyncWrap::PostgreSQL
28
- include SyncWrap::Geminabox
29
-
30
- include SyncWrap::RemoteTask
31
-
32
- def initialize
33
- super
34
-
35
- # SETUP: Install user@server instance goes here
36
- set :domain, "localhost"
37
-
38
- end
39
-
40
- def define_tasks
41
-
42
- desc "Combined Java, Hashdot, JRuby Deployment"
43
- remote_task :jruby_deploy do
44
- java_install
45
- hashdot_install
46
- jruby_install
47
- end
48
-
49
- desc "Deploy Iyyov Deamon"
50
- remote_task :iyyov_deploy do
51
- user_run_dir_setup
52
- iyyov_install
53
- end
54
-
55
- desc "Deploy Geminabox Daemon"
56
- remote_task :geminabox_deploy do
57
- iyyov_install_jobs do
58
- geminabox_install
59
- end
60
- end
61
-
62
- desc "Deploy PostgreSQL"
63
- remote_task :pg_deploy do
64
- pg_install
65
- pg_configure
66
- pg_start
67
- end
68
-
69
- end
70
-
71
- end
72
-
73
- SyncWrapper.new.define_tasks
data/bin/syncwrap ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+
4
+ #--
5
+ # Copyright (c) 2011-2014 David Kellum
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
8
+ # may not use this file except in compliance with the License. You
9
+ # may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16
+ # implied. See the License for the specific language governing
17
+ # permissions and limitations under the License.
18
+ #++
19
+
20
+ $LOAD_PATH.unshift File.expand_path( "../../lib", __FILE__ )
21
+
22
+ require 'rubygems'
23
+
24
+ require 'syncwrap'
25
+ require 'syncwrap/cli'
26
+
27
+ SyncWrap::CLI.new.run( ARGV )
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ == Examples
4
+
5
+ The examples/ directory contains several independent sync-file
6
+ examples. Normally you would just have one named the default "sync.rb"
7
+ Use the syncwrap command -f <file> option to load each.
8
+
9
+ There is also an example Rakefile demonstrating basic rake integration.
10
+
11
+ The sub-directories private/ and sync/ are standard named and shared
12
+ by multiple examples.
13
+
14
+ == Common Project Layout
15
+
16
+ Here is what a complete end-user project setup might look like:
17
+
18
+ deploy/
19
+ ├── lib/
20
+ │ └── my_component.rb
21
+ ├── .gitignore
22
+ ├── private/
23
+ │ ├── aws.json
24
+ │ └── sec.pem
25
+ ├── sync.rb
26
+ └── sync/
27
+ ├── home
28
+ │ └── bob
29
+ │ └── .ssh
30
+ │ └── authorized_keys
31
+ └── my/
32
+ └── config.rb.erb
33
+
34
+ sync.rb:: The aforementioned default named sync-file, containing
35
+ roles, components, hosts, and possibly profiles.
36
+
37
+ sync/:: The default named sync root containing a tree of static files
38
+ and templates for pushing to hosts. See the rput.rb example
39
+ for usage. The local sync root can contain overrides to the
40
+ syncwrap gem provided files/directories as well as new
41
+ files. Home directories and in particular
42
+ .ssh/authorized_keys is commonly used with the
43
+ SyncWrap::Users component.
44
+
45
+ lib/:: Place project-specific components here. Once these are
46
+ non-trivial its nicer to `require_relative` them into the
47
+ sync.rb. Its best to namespace these in your own module.
48
+
49
+ private/:: This directory is for sensitive files like credentials that
50
+ shouldn't be checked in. The files shown are for a typical
51
+ project using the SyncWrap::AmazonEC2 provider. See the
52
+ ec2.rb example. Similarly you can use a sync/private/ for
53
+ sensitive files/templates that will be deployed, and
54
+ include this as the first sync_root in your sync.rb You'll
55
+ have to externally arrange for sharing these files with
56
+ other users. Assuming you will check this into a git repo
57
+ (either its own, or for example, in a deploy/ directory of
58
+ a larger project repo), its a good idea to add a .gitignore
59
+ file containing the following at minimum:
60
+
61
+ private/
62
+
63
+ ...which ignores and avoids check-in by mistake of any so
64
+ named sub-directory and its contents.
65
+
66
+ Without the private/ directories and sync.rb file, and adjusting lib/
67
+ accordingly, you could also package this as a gem. This makes it easy
68
+ to reuse components and files/templates across projects. Include a
69
+ bundler Gemfile in each deploy directory for precise version control
70
+ of all gems involved, including syncwrap.
data/examples/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # -*- ruby -*-
2
+
3
+ # Stupid simple Rakefile integration example.
4
+ # See SyncWrap::Space#execute for additional customization options
5
+
6
+ require 'rubygems'
7
+ require 'bundler/setup'
8
+ require 'syncwrap'
9
+
10
+ desc "Execute default components on all hosts in SyncWrap hello.rb"
11
+ task :deploy do
12
+ sp = SyncWrap::Space.new
13
+ sp.load_sync_file_relative 'hello.rb'
14
+ sp.default_options[:verbose] = true
15
+ sp.execute
16
+ end
data/examples/ec2.rb ADDED
@@ -0,0 +1,44 @@
1
+ # Demonstrates provisioning a PostgreSQL instance on Amazon EC2.
2
+ #
3
+ # This includes a custom 4 EBS-volume software RAID-1+0 for the
4
+ # database storage.
5
+ #
6
+ # With API key-pair and pem (see SETUP below) create a host and
7
+ # provision it via:
8
+ #
9
+ # syncwrap -C postgres:pg-1 -v
10
+ #
11
+ # The host (name 'pg-1') definition will be automaticly added to the
12
+ # end of this file.
13
+
14
+ include SyncWrap
15
+
16
+ # SETUP: edit the sample file for your API key-pair obtained via AWS console
17
+ space.use_provider( AmazonEC2, aws_config: 'private/aws.json' )
18
+
19
+ profile( :default, # The "default" profile
20
+ image_id: "ami-ccf297fc", # Amazon Linux 2013.09.2 EBS 64 us-west-2
21
+ region: 'us-west-2', # Oregon; or change region and ami.
22
+ user_data: :ec2_user_sudo, # Sudoer ec2-user \w no-tty required
23
+ key_name: 'sec', # SETUP: Create this key in AWS console,
24
+ # or rename to an existing key.
25
+ # Same ssh_user_pem file below:
26
+ roles: [ :amazon_linux ] )
27
+
28
+ profile( :postgres, # Inherits properties from :default
29
+ instance_type: 'm1.small',
30
+ ebs_volumes: 4,
31
+ ebs_volume_options: { size: 2 }, #gb
32
+ roles: [ :postgres ] )
33
+
34
+ role( :amazon_linux,
35
+ Users.new( ssh_user: 'ec2-user',
36
+ ssh_user_pem: 'private/sec.pem' ), # SETUP
37
+ RHEL.new,
38
+ Network.new )
39
+
40
+ role( :postgres,
41
+ MDRaid.new( raw_devices: 4, lvm_volumes: [ [1.0, '/pg'] ] ),
42
+ PostgreSQL.new( pg_data_dir: '/pg/data' ) )
43
+
44
+ # Generated Hosts:
data/examples/hello.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ class Greeter < SyncWrap::Component
3
+ def install
4
+ say_it
5
+ end
6
+
7
+ def say_it
8
+ sh <<-SH
9
+ echo "Hello from #{host.name}"
10
+ SH
11
+ end
12
+ end
13
+
14
+ host 'localhost', Greeter.new
@@ -0,0 +1,27 @@
1
+
2
+ class GreetSupport < SyncWrap::Component
3
+
4
+ def install
5
+ # provision "echo" support, if that were needed.
6
+ end
7
+
8
+ def say( msg )
9
+ sh "echo '#{msg}'"
10
+ end
11
+
12
+ end
13
+
14
+ class Greeter < SyncWrap::Component
15
+
16
+ def install
17
+ say "Hello from #{host.name}"
18
+ end
19
+
20
+ end
21
+
22
+ host 'localhost', GreetSupport.new, Greeter.new
23
+
24
+ # When executing in the context of localhost, this Greeter has access
25
+ # to the public instance methods of this GreetSupport. The reverse is
26
+ # not true: this GreetSupport instance does not get any Greeter
27
+ # methods.
data/examples/jruby.rb ADDED
@@ -0,0 +1,11 @@
1
+ include SyncWrap
2
+
3
+ role( :all,
4
+ Users.new )
5
+
6
+ role( :jruby,
7
+ OpenJDK.new,
8
+ JRubyVM.new( jruby_version: '1.7.10' ),
9
+ Hashdot.new )
10
+
11
+ host( 'centos-1', RHEL.new, :jruby, internal_ip: '192.168.122.4' )
@@ -0,0 +1,4 @@
1
+ /* SETUP: Replace with the real pem file */
2
+ { "access_key_id": "AKiiiiiiiiiiiiiiiiii",
3
+ "secret_access_key": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
4
+ }
data/examples/rput.rb ADDED
@@ -0,0 +1,24 @@
1
+ # Important: Make this examples/sync directory first in
2
+ # sync_paths. This is not done by default, to make sure its explicit.
3
+ #
4
+ # The second path is the SyncWrap gem's own sync directory. The first
5
+ # path can effectively override any file that would otherwise be found
6
+ # in the second. This includes being able to override a static file
7
+ # with a template, or the other way around. This is what we mean by
8
+ # "transparent."
9
+ space.prepend_sync_path
10
+
11
+ class Writer < SyncWrap::Component
12
+ attr_accessor :message
13
+
14
+ def install
15
+ rput( "tmp/sample" ) # implied destination --> /tmp/sample
16
+ end
17
+ end
18
+
19
+ host 'localhost', Writer.new( message: "parameterized" )
20
+
21
+ # Try changing the message property above and running repeatedly in
22
+ # --verbose mode, to see how rsync uses checksums to detect
23
+ # changes. The cryptic looking output lines are actually returned as
24
+ # an array of changes from the rput call.
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3Nzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx== bob@dot.net
@@ -0,0 +1,3 @@
1
+ This could have been a simple file (i.e. 'sync/tmp/sample' ) but
2
+ instead its a <%= message %> ERB template with access to Writer
3
+ instance methods (including attributes).