grocery_delivery 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.md +99 -17
- data/bin/grocery-delivery +259 -0
- data/lib/grocery_delivery/config.rb +32 -0
- data/lib/grocery_delivery/hooks.rb +34 -0
- data/lib/grocery_delivery/logging.rb +56 -0
- metadata +39 -35
- checksums.yaml +0 -7
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -1
- data/grocery_delivery.gemspec +0 -23
- data/lib/grocery_delivery/version.rb +0 -3
- data/lib/grocery_delivery.rb +0 -5
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,29 +1,111 @@
|
|
1
|
-
#
|
1
|
+
# Grocery Delivery
|
2
2
|
|
3
|
-
|
3
|
+
## Intro
|
4
|
+
Ohai!
|
4
5
|
|
5
|
-
|
6
|
+
Welcome to Grocery Delivery, software to keep cookbooks, roles, and databags in
|
7
|
+
sync between a VCS repo and a chef server. The idea is that if you have
|
8
|
+
multiple, distinct Chef server instances that should all be identical, they can
|
9
|
+
all run this script in cron. The script uses proper locking, so you should be
|
10
|
+
able to run it every minute.
|
6
11
|
|
7
|
-
|
12
|
+
However, there are several things to know:
|
13
|
+
* It assumes you don't leverage versions or environments.
|
14
|
+
* It assumes you want anything committed to HEAD to be uploaded immediately.
|
8
15
|
|
9
|
-
|
16
|
+
Grocery Delivery is pretty customizable. Many things can be tuned from a simple
|
17
|
+
config file, and it's pluggable so you can extend it as well.
|
10
18
|
|
11
|
-
|
19
|
+
## Prerequisites
|
12
20
|
|
13
|
-
|
21
|
+
Grocery Delivery is a particular way of managing your Chef infrastructure,
|
22
|
+
and it assumes you follow that model consistently. Here are the basic
|
23
|
+
principals:
|
14
24
|
|
15
|
-
|
25
|
+
* Checkins are live immediately (which implies code review before merge)
|
26
|
+
* Versions are meaningless (ideally, never change them)
|
27
|
+
* You want all your chef-servers in sync
|
28
|
+
* Everything you care about comes from version control.
|
16
29
|
|
17
|
-
|
30
|
+
We recommend using the whitelist_node_attrs
|
31
|
+
(https://github.com/opscode/whitelist-node-attrs) cookbook to prevent node
|
32
|
+
attributes being saved back to the server. Or in recent versions of Chef 11,
|
33
|
+
this feature is built-in:
|
18
34
|
|
19
|
-
|
35
|
+
http://docs.getchef.com/essentials_node_object.html#whitelist-attributes
|
20
36
|
|
21
|
-
|
37
|
+
## Dependencies
|
22
38
|
|
23
|
-
|
39
|
+
* Mixlib::Config
|
40
|
+
* BetweenMeals
|
24
41
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
## Config file
|
43
|
+
|
44
|
+
The default config file is `/etc/gd-config.rb` but you may use -c to specify
|
45
|
+
another. The config file works the same as client.rb does for Chef - there
|
46
|
+
are a series of keywords that take an arguement and anything else is just
|
47
|
+
standard Ruby.
|
48
|
+
|
49
|
+
All command-line options are available in the config file:
|
50
|
+
* dry_run (bool, default: false)
|
51
|
+
* debug (bool, default: false)
|
52
|
+
* timestamp (bool, default: false)
|
53
|
+
* config_file (string, default: `/etc/gd-config.rb`)
|
54
|
+
* lockfile (string, default: `/var/lock/subsys/grocery_delivery`)
|
55
|
+
* pidfile (string, default: `/var/run/grocery_delivery.pid`)
|
56
|
+
|
57
|
+
In addition the following are also available:
|
58
|
+
* master_path - The top-level path for Grocery Delivery's work. Most other
|
59
|
+
paths are relative to this. Default: `/var/chef/grocery_delivery_work`
|
60
|
+
* repo_url - The URL to clone/checkout if it doesn't exist. Default: `nil`
|
61
|
+
* reponame - The relative directory to check the repo out to, inside of
|
62
|
+
`master_path`. Default: `ops`
|
63
|
+
* cookbook_paths - An array of directories that contain cookbooks relative to
|
64
|
+
`reponame`. Default: `['chef/cookbooks']`
|
65
|
+
* role_path - A directory to find roles in relative to `reponame`. Default:
|
66
|
+
`['chef/roles']`
|
67
|
+
* databag_path - A directory to find databags in relative to `reponame`.
|
68
|
+
Default: `['chef/databags']`
|
69
|
+
* rev_checkpoint - Name of the file to store the last-uploaded revision,
|
70
|
+
relative to `reponame`. Default: `gd_revision`
|
71
|
+
* knife_config - Knife config to use for uploads. Default:
|
72
|
+
`/root/.chef/knife.rb`
|
73
|
+
* knife_bin - Path to knife. Default: `/opt/chef/bin/knife`
|
74
|
+
* vcs_type - Git or SVN? Default: `svn`
|
75
|
+
* vcs_path - Path to git or svn binary. If not given, just uses 'git' or 'svn'.
|
76
|
+
Default: `nil`
|
77
|
+
* plugin_path - Path to plugin file. Default: `/etc/gd-plugin.rb`
|
78
|
+
|
79
|
+
## Plugin
|
80
|
+
|
81
|
+
The plugin should be a ruby file which defines several class methods. It is
|
82
|
+
class_eval()d into a Hooks class.
|
83
|
+
|
84
|
+
The following functions can optionally be defined:
|
85
|
+
|
86
|
+
* self.preflight_checks(dryrun)
|
87
|
+
|
88
|
+
This code will run once we've read our config and loaded our plugins but before
|
89
|
+
*anything* else. We don't even have a lock yet. `Dryrun` is a bool which
|
90
|
+
indicates if we are in dryrun mode.
|
91
|
+
|
92
|
+
* self.prerun(dryrun)
|
93
|
+
|
94
|
+
This is run after we've gotten a lock, written a pidfile and initialized our
|
95
|
+
repo object (but not touched the repo yet)
|
96
|
+
|
97
|
+
* self.post_repo_up(dryrun)
|
98
|
+
|
99
|
+
This is code to run after we've updated the repo, but before we've done any work
|
100
|
+
to parse it.
|
101
|
+
|
102
|
+
* self.postrun(dryrun, success, msg)
|
103
|
+
|
104
|
+
After we've parsed the updates to the repo and uploaded/deleted the relevent
|
105
|
+
items from the local server. `Success` is a bool for whether we succeeded, and
|
106
|
+
`msg` is the status message - either the revision we sync'd or an error.
|
107
|
+
|
108
|
+
* self.atexit(dryrun, success, msg)
|
109
|
+
|
110
|
+
Same as postrun, but is registered as an atexit function so it happens even
|
111
|
+
if we crash.
|
@@ -0,0 +1,259 @@
|
|
1
|
+
#!/opt/chef/embedded/bin/ruby
|
2
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
3
|
+
|
4
|
+
require 'between_meals/util'
|
5
|
+
require 'between_meals/knife'
|
6
|
+
require 'between_meals/repo/svn'
|
7
|
+
require 'between_meals/repo/git'
|
8
|
+
require 'between_meals/changeset'
|
9
|
+
require 'grocery_delivery/config'
|
10
|
+
require 'grocery_delivery/logging'
|
11
|
+
require 'grocery_delivery/hooks'
|
12
|
+
require 'optparse'
|
13
|
+
require 'logger'
|
14
|
+
|
15
|
+
# rubocop:disable GlobalVars
|
16
|
+
$success = false
|
17
|
+
$status_msg = 'NO WORK DONE'
|
18
|
+
$lockfileh = nil
|
19
|
+
|
20
|
+
def action(msg)
|
21
|
+
if GroceryDelivery::Config.dry_run
|
22
|
+
GroceryDelivery::Log.warn("[DRYRUN] Would do: #{msg}")
|
23
|
+
else
|
24
|
+
GroceryDelivery::Log.warn(msg)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_lock
|
29
|
+
GroceryDelivery::Log.warn('Attempting to acquire lock')
|
30
|
+
$lockfileh = File.open(GroceryDelivery::Config.lockfile,
|
31
|
+
File::RDWR | File::CREAT, 0600)
|
32
|
+
$lockfileh.flock(File::LOCK_EX)
|
33
|
+
GroceryDelivery::Log.warn('Lock acquired')
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_pidfile
|
37
|
+
File.write(GroceryDelivery::Config.pidfile, Process.pid)
|
38
|
+
end
|
39
|
+
|
40
|
+
def checkpoint_path
|
41
|
+
File.join(GroceryDelivery::Config.master_path,
|
42
|
+
GroceryDelivery::Config.rev_checkpoint)
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_checkpoint(rev)
|
46
|
+
File.write(checkpoint_path, rev) unless GroceryDelivery::Config.dry_run
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_checkpoint
|
50
|
+
GroceryDelivery::Log.debug("Reading #{checkpoint_path}")
|
51
|
+
File.exists?(checkpoint_path) ? File.read(checkpoint_path).strip : nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def full_upload(knife)
|
55
|
+
GroceryDelivery::Log.warn('Uploading all cookbooks')
|
56
|
+
knife.cookbook_upload_all
|
57
|
+
GroceryDelivery::Log.warn('Uploading all roles')
|
58
|
+
knife.role_upload_all
|
59
|
+
GroceryDelivery::Log.warn('Uploading all databags')
|
60
|
+
knife.databag_upload_all
|
61
|
+
end
|
62
|
+
|
63
|
+
def partial_upload(knife, repo, checkpoint, local_head)
|
64
|
+
GroceryDelivery::Log.warn(
|
65
|
+
"Determing changes... from #{checkpoint} to #{local_head}"
|
66
|
+
)
|
67
|
+
|
68
|
+
begin
|
69
|
+
changeset = BetweenMeals::Changeset.new(
|
70
|
+
GroceryDelivery::Log,
|
71
|
+
repo,
|
72
|
+
checkpoint,
|
73
|
+
local_head,
|
74
|
+
{
|
75
|
+
:cookbook_dirs =>
|
76
|
+
GroceryDelivery::Config.cookbook_paths,
|
77
|
+
:role_dir =>
|
78
|
+
GroceryDelivery::Config.role_path,
|
79
|
+
:databag_dir =>
|
80
|
+
GroceryDelivery::Config.databag_path,
|
81
|
+
},
|
82
|
+
)
|
83
|
+
rescue BetweenMeals::Changeset::ReferenceError
|
84
|
+
GroceryDelivery::Log.error('Repo error, invalid revision, exiting')
|
85
|
+
exit(2)
|
86
|
+
end
|
87
|
+
|
88
|
+
deleted_cookbooks = changeset.cookbooks.select { |x| x.status == :deleted }
|
89
|
+
added_cookbooks = changeset.cookbooks.select { |x| x.status == :modified }
|
90
|
+
deleted_roles = changeset.roles.select { |x| x.status == :deleted }
|
91
|
+
added_roles = changeset.roles.select { |x| x.status == :modified }
|
92
|
+
deleted_databags = changeset.databags.select { |x| x.status == :deleted }
|
93
|
+
added_databags = changeset.databags.select { |x| x.status == :modified }
|
94
|
+
|
95
|
+
{
|
96
|
+
'Added cookbooks' => added_cookbooks,
|
97
|
+
'Deleted cookbooks' => deleted_cookbooks,
|
98
|
+
'Added roles' => added_roles,
|
99
|
+
'Deleted roles' => deleted_roles,
|
100
|
+
'Added databags' => added_databags,
|
101
|
+
'Deleted databags' => deleted_databags,
|
102
|
+
}.each do |msg, list|
|
103
|
+
if list
|
104
|
+
GroceryDelivery::Log.warn("#{msg}: #{list}")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
knife.cookbook_delete(deleted_cookbooks) if deleted_cookbooks
|
109
|
+
knife.cookbook_upload(added_cookbooks) if added_cookbooks
|
110
|
+
knife.role_delete(deleted_roles) if deleted_roles
|
111
|
+
knife.role_upload(added_roles) if added_roles
|
112
|
+
knife.databag_delete(deleted_databags) if deleted_databags
|
113
|
+
knife.databag_upload(added_databags) if added_databags
|
114
|
+
end
|
115
|
+
|
116
|
+
def upload_changed(repo, checkpoint)
|
117
|
+
local_head = repo.head_rev
|
118
|
+
base_dir = File.join(GroceryDelivery::Config.master_path,
|
119
|
+
GroceryDelivery::Config.reponame)
|
120
|
+
|
121
|
+
knife = BetweenMeals::Knife.new(
|
122
|
+
{
|
123
|
+
:logger => GroceryDelivery::Log,
|
124
|
+
:config => GroceryDelivery::Config.knife_config,
|
125
|
+
:bin => GroceryDelivery::Config.knife_bin,
|
126
|
+
:role_dir => File.join(base_dir, GroceryDelivery::Config.role_path),
|
127
|
+
:cookbook_dirs => GroceryDelivery::Config.cookbook_paths.map do |x|
|
128
|
+
File.join(base_dir, x)
|
129
|
+
end,
|
130
|
+
:databag_dir => File.join(base_dir, GroceryDelivery::Config.databag_path),
|
131
|
+
}
|
132
|
+
)
|
133
|
+
|
134
|
+
if checkpoint
|
135
|
+
partial_upload(knife, repo, checkpoint, local_head)
|
136
|
+
else
|
137
|
+
full_upload(knife)
|
138
|
+
end
|
139
|
+
return local_head
|
140
|
+
end
|
141
|
+
|
142
|
+
def setup_config
|
143
|
+
options = {}
|
144
|
+
OptionParser.new do |opts|
|
145
|
+
options[:config_file] = GroceryDelivery::Config.config_file
|
146
|
+
opts.on('-n', '--dry-run', 'Dryrun mode') do |s|
|
147
|
+
options[:dry_run] = s
|
148
|
+
end
|
149
|
+
opts.on('-v', '--verbosity', 'Verbosity level. Twice for debug.') do
|
150
|
+
# If -vv is supplied this block is executed twice
|
151
|
+
if options[:verbosity]
|
152
|
+
options[:verbosity] = ::Logger::DEBUG
|
153
|
+
else
|
154
|
+
options[:verbosity] = ::Logger::INFO
|
155
|
+
end
|
156
|
+
end
|
157
|
+
opts.on('-T', '--timestamp', 'Timestamp output') do |s|
|
158
|
+
options[:timestamp] = s
|
159
|
+
end
|
160
|
+
opts.on('-c', '--config-file FILE', 'config file') do |s|
|
161
|
+
unless File.exists?(File.expand_path(s))
|
162
|
+
GroceryDelivery::Log.error("Config file #{s} not found.")
|
163
|
+
exit(2)
|
164
|
+
end
|
165
|
+
options[:config_file] = s
|
166
|
+
end
|
167
|
+
opts.on('-l', '--lockfile FILE', 'lockfile') do |s|
|
168
|
+
options[:lockfile] = s
|
169
|
+
end
|
170
|
+
opts.on('-p', '--pidfile FILE', 'pidfile') do |s|
|
171
|
+
options[:pidfile] = s
|
172
|
+
end
|
173
|
+
end.parse!
|
174
|
+
if File.exists?(File.expand_path(options[:config_file]))
|
175
|
+
GroceryDelivery::Config.from_file(options[:config_file])
|
176
|
+
end
|
177
|
+
GroceryDelivery::Config.merge!(options)
|
178
|
+
GroceryDelivery::Log.verbosity = GroceryDelivery::Config.verbosity
|
179
|
+
if GroceryDelivery::Config.dry_run
|
180
|
+
GroceryDelivery::Log.warn('Dryrun mode activated, no changes will be made.')
|
181
|
+
end
|
182
|
+
GroceryDelivery::Hooks.get(GroceryDelivery::Config.plugin_path)
|
183
|
+
at_exit do
|
184
|
+
GroceryDelivery::Hooks.atexit(GroceryDelivery::Config.dry_run,
|
185
|
+
$success, $status_msg)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_repo
|
190
|
+
repo_path = File.join(GroceryDelivery::Config.master_path,
|
191
|
+
GroceryDelivery::Config.reponame)
|
192
|
+
r = BetweenMeals::Repo.get(GroceryDelivery::Config.vcs_type, repo_path,
|
193
|
+
GroceryDelivery::Log)
|
194
|
+
if GroceryDelivery::Config.vcs_path
|
195
|
+
r.bin = GroceryDelivery::Config.vcs_path
|
196
|
+
end
|
197
|
+
r
|
198
|
+
end
|
199
|
+
|
200
|
+
setup_config
|
201
|
+
|
202
|
+
GroceryDelivery::Hooks.preflight_checks(GroceryDelivery::Config.dry_run)
|
203
|
+
|
204
|
+
get_lock
|
205
|
+
write_pidfile
|
206
|
+
repo = get_repo
|
207
|
+
|
208
|
+
GroceryDelivery::Hooks.prerun(GroceryDelivery::Config.dry_run)
|
209
|
+
|
210
|
+
if repo.exists?
|
211
|
+
action('Updating repo')
|
212
|
+
repo.update unless GroceryDelivery::Config.dry_run
|
213
|
+
else
|
214
|
+
unless GroceryDelivery::Config.repo_url
|
215
|
+
GroceryDeliver::Log.error(
|
216
|
+
'No repo URL was specified, and no repo is checked out'
|
217
|
+
)
|
218
|
+
exit(1)
|
219
|
+
end
|
220
|
+
action('Cloning repo')
|
221
|
+
unless GroceryDelivery::Config.dry_run
|
222
|
+
repo.checkout(GroceryDelivery::Config.repo_url)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
GroceryDelivery::Hooks.post_repo_up(GroceryDelivery::Config.dry_run)
|
227
|
+
|
228
|
+
if GroceryDelivery::Config.dry_run && !repo.exists?
|
229
|
+
GroceryDelivery::Log.warn(
|
230
|
+
'In dryrun mode, with no repo, there\'s not much I can dryrun'
|
231
|
+
)
|
232
|
+
GroceryDelivery::Hooks.postrun(GroceryDelivery::Config.dry_run, true,
|
233
|
+
'dryrun mode')
|
234
|
+
exit
|
235
|
+
end
|
236
|
+
|
237
|
+
checkpoint = read_checkpoint
|
238
|
+
if repo.exists? && repo.head_rev == checkpoint
|
239
|
+
GroceryDelivery::Log.warn('Repo has not changed, nothing to do...')
|
240
|
+
$success = true
|
241
|
+
$status_msg = "Success at #{checkpoint}"
|
242
|
+
else
|
243
|
+
begin
|
244
|
+
ver = upload_changed(repo, checkpoint)
|
245
|
+
write_checkpoint(ver)
|
246
|
+
$success = true
|
247
|
+
$status_msg = "Success at #{ver}"
|
248
|
+
rescue => e
|
249
|
+
$status_msg = e.message
|
250
|
+
e.backtrace.each do |line|
|
251
|
+
GroceryDelivery::Log.error(line)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
GroceryDelivery::Log.warn($status_msg)
|
257
|
+
GroceryDelivery::Hooks.postrun(GroceryDelivery::Config.dry_run, $success,
|
258
|
+
$status_msg)
|
259
|
+
# rubocop:enable GlobalVars
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
2
|
+
|
3
|
+
require 'mixlib/config'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module GroceryDelivery
|
7
|
+
# Config file parser and config object
|
8
|
+
# Uses Mixlib::Config v1 syntax so it works in Chef10 omnibus...
|
9
|
+
# it's compatible with v2, so it should work in 11 too.
|
10
|
+
class Config
|
11
|
+
extend Mixlib::Config
|
12
|
+
|
13
|
+
dry_run false
|
14
|
+
verbosity Logger::WARN
|
15
|
+
timestamp false
|
16
|
+
config_file '/etc/gd-config.rb'
|
17
|
+
pidfile '/var/run/grocery_delivery.pid'
|
18
|
+
lockfile '/var/lock/subsys/grocery_delivery'
|
19
|
+
master_path '/var/chef/grocery_delivery_work'
|
20
|
+
repo_url nil
|
21
|
+
reponame 'ops'
|
22
|
+
cookbook_paths ['chef/cookbooks']
|
23
|
+
role_path 'chef/roles'
|
24
|
+
databag_path 'chef/databags'
|
25
|
+
rev_checkpoint 'gd_revision'
|
26
|
+
knife_config '/root/.chef/knife.rb'
|
27
|
+
knife_bin '/opt/chef/bin/knife'
|
28
|
+
vcs_type 'svn'
|
29
|
+
vcs_path nil
|
30
|
+
plugin_path '/etc/gd-plugin.rb'
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
2
|
+
|
3
|
+
module GroceryDelivery
|
4
|
+
# Hook class for GD
|
5
|
+
class Hooks
|
6
|
+
# This code will run once we've read our config and loaded our plugins
|
7
|
+
# but before *anything* else. We don't even have a lock yet.
|
8
|
+
def self.preflight_checks(_dryrun)
|
9
|
+
end
|
10
|
+
|
11
|
+
# This is run after we've gotten a lock, written a pidfile and initialized
|
12
|
+
# our repo object (but not touched the repo yet)
|
13
|
+
def self.prerun(_dryrun)
|
14
|
+
end
|
15
|
+
|
16
|
+
# This is code to run after we've updated the repo, but before we've done
|
17
|
+
# any work to parse it.
|
18
|
+
def self.post_repo_up(_dryrun)
|
19
|
+
end
|
20
|
+
|
21
|
+
# After we parse the updates to the repo and uploaded/deleted the relevent
|
22
|
+
# items from the local server.
|
23
|
+
def self.postrun(_dryrun, _success, _msg)
|
24
|
+
end
|
25
|
+
|
26
|
+
# exit hooks.
|
27
|
+
def self.atexit(_dryrun, _success, _msg)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(file)
|
31
|
+
class_eval(File.read(file), __FILE__, __LINE__) if File.exists?(file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
2
|
+
|
3
|
+
require 'syslog'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module GroceryDelivery
|
7
|
+
# Logging wrapper
|
8
|
+
# rubocop:disable ClassVars
|
9
|
+
module Log
|
10
|
+
@@init = false
|
11
|
+
@@level = Logger::WARN
|
12
|
+
|
13
|
+
def self.init
|
14
|
+
Syslog.open(File.basename($PROGRAM_NAME, '.rb'))
|
15
|
+
@@init = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.verbosity=(val)
|
19
|
+
@@level = val
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.logit(level, msg)
|
23
|
+
init unless @@init
|
24
|
+
# You can't do `Syslog.log(level, msg)` because if there is a
|
25
|
+
# `%` in `msg` then ruby will interpret it as a printf string and
|
26
|
+
# expect more arguments to log().
|
27
|
+
Syslog.log(level, '%s', msg)
|
28
|
+
puts msg if $stdout.tty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.debug(msg)
|
32
|
+
if @@level == Logger::DEBUG
|
33
|
+
msg.prepend('DEBUG: ')
|
34
|
+
logit(Syslog::LOG_DEBUG, msg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.info(msg)
|
39
|
+
if @@level == Logger::INFO
|
40
|
+
msg.prepend('INFO: ')
|
41
|
+
logit(Syslog::LOG_INFO, msg)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.warn(msg)
|
46
|
+
msg.prepend('WARN: ')
|
47
|
+
logit(Syslog::LOG_WARNING, msg)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.error(msg)
|
51
|
+
msg.prepend('ERROR: ')
|
52
|
+
logit(Syslog::LOG_ERR, msg)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
# rubocop:enable ClassVars
|
56
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grocery_delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
|
-
- Marcin Sawicki
|
8
8
|
- Phil Dibowitz
|
9
|
+
- Marcin Sawicki
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
+
name: mixlib-config
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
21
|
-
type: :
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
30
|
+
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
32
|
+
name: between_meals
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- - '>='
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
|
-
type: :
|
39
|
+
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- - '>='
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
|
-
description:
|
43
|
-
email:
|
44
|
-
|
45
|
-
-
|
46
|
-
executables: []
|
47
|
+
description: Utility for keeping Chef servers in sync with a repo
|
48
|
+
email:
|
49
|
+
executables:
|
50
|
+
- grocery-delivery
|
47
51
|
extensions: []
|
48
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README.md
|
54
|
+
- LICENSE
|
49
55
|
files:
|
50
|
-
- .gitignore
|
51
|
-
- Gemfile
|
52
|
-
- LICENSE.txt
|
53
56
|
- README.md
|
54
|
-
-
|
55
|
-
- grocery_delivery.
|
56
|
-
- lib/grocery_delivery.rb
|
57
|
-
- lib/grocery_delivery/
|
58
|
-
|
57
|
+
- LICENSE
|
58
|
+
- lib/grocery_delivery/hooks.rb
|
59
|
+
- lib/grocery_delivery/config.rb
|
60
|
+
- lib/grocery_delivery/logging.rb
|
61
|
+
- bin/grocery-delivery
|
62
|
+
homepage:
|
59
63
|
licenses:
|
60
|
-
-
|
61
|
-
metadata: {}
|
64
|
+
- Apache
|
62
65
|
post_install_message:
|
63
66
|
rdoc_options: []
|
64
67
|
require_paths:
|
65
68
|
- lib
|
66
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
67
71
|
requirements:
|
68
|
-
- - '>='
|
72
|
+
- - ! '>='
|
69
73
|
- !ruby/object:Gem::Version
|
70
74
|
version: '0'
|
71
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
72
77
|
requirements:
|
73
|
-
- - '>='
|
78
|
+
- - ! '>='
|
74
79
|
- !ruby/object:Gem::Version
|
75
80
|
version: '0'
|
76
81
|
requirements: []
|
77
82
|
rubyforge_project:
|
78
|
-
rubygems_version:
|
83
|
+
rubygems_version: 1.8.29
|
79
84
|
signing_key:
|
80
|
-
specification_version:
|
81
|
-
summary:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Grocery Delivery
|
82
87
|
test_files: []
|
83
|
-
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 7702abefa5d8056aaed6c9869c9592000634519a
|
4
|
-
data.tar.gz: cb9a07a882441556fc03956e6b216c01d64043d5
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 96940f8a75d4a3f2a5a5e522adac15be45ecc691644766b988add6e5c933ede7eebf2603fbb34096e365c7f75f6b5d5cde7f6cea475f42328dba7a9d7460567e
|
7
|
-
data.tar.gz: 8aa2514296d2c1c30c86176f11f1cc41f9674d3104c7c865bc49aa308b5c72b8cbd9875739703a52072232c51a9f24b7266715c049ad44977d4e9688bcbbed5f
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Marcin Sawicki
|
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/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/grocery_delivery.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'grocery_delivery/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "grocery_delivery"
|
8
|
-
spec.version = GroceryDelivery::VERSION
|
9
|
-
spec.authors = ["Marcin Sawicki", "Phil Dibowitz"]
|
10
|
-
spec.email = ["odcinek@gmail.com", "phil@ipom.com"]
|
11
|
-
spec.description = %q{Write a gem description}
|
12
|
-
spec.summary = %q{Write a gem summary}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
end
|