hetzner-docker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c3e0ec46f94c725547dc048481226fb01270705
4
+ data.tar.gz: dc04a903cef5a4448d196b5f7cff0cdbb8b99381
5
+ SHA512:
6
+ metadata.gz: 369349fa0e4c9517287cf4fd571fc2cb70f23e562462ad3a8fd0e2fe6f26d45b7bd8e612784b4007236880d16e5f79e00129efa5dcb7cca4631e716d06360328
7
+ data.tar.gz: 7bec17a4f1bddf46bed04a872c56526fcd60fad8293d832796c00166e72c3bb52cedc514ee7612a5d7594f87251f4486872d05b9bad262cfdc2e8b9176a0f6cd
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.lock
2
+ nodes/
3
+ .bundle/
4
+ .env.source
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /test/tmp/
13
+ /test/version_tmp/
14
+ /tmp/
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+
21
+ ## Documentation cache and generated files:
22
+ /.yardoc/
23
+ /_yardoc/
24
+ /doc/
25
+ /rdoc/
26
+
27
+ ## Environment normalisation:
28
+ /.bundle/
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
data/Berksfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://api.berkshelf.com"
2
+
3
+ cookbook 'docker', github: 'bflad/chef-docker'
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hetzner-docker', github: 'imelnik/hetzner-docker'
4
+ gem 'hetzner-api'
5
+ gem 'net-ssh'
6
+ gem 'net-scp'
7
+ gem 'knife-solo'
8
+ gem 'berkshelf', '~> 3.1.1'
9
+ gem 'slop'
data/LICENSE.txt ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Hetzner::Docker
2
+
3
+ Ultra simple deployment of Docker-enabled Hetzner servers.
4
+ Uses:
5
+ hetzner-api
6
+ Chef (knife-solo)
7
+ chef-docker cookbook
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'hetzner-docker'
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install hetzner-docker
23
+
24
+ ## Usage
25
+ You should have your ssh public key located at ~/.ssh/id_rsa.pub and get a copy of Berksfile at your current working directory.
26
+
27
+ ```
28
+ export HETZNER_USER="" && export HETZNER_PASSWORD=""
29
+
30
+ hetzner-docker bootstrap -i <server-ip> -d <server-domain>
31
+
32
+ ```
33
+
34
+
35
+ ## TODO
36
+
37
+ 1. Modular config for do-install-trusty.sh
38
+ 2. More options
39
+ 3. Verbose and non-verbose output
40
+ 4. Enable OpenVSwitch install
41
+
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/imelnik/hetzner-docker/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require "slop"
5
+ require "hetzner-docker"
6
+ DEFAULT_IDENTITY_FILE = '~/.ssh/id_rsa.pub'
7
+ opts = Slop.parse(help: true) do
8
+ description 'Usage: manage.rb [command] [options]'
9
+ on 'v','version', 'module version' do
10
+ puts HetznerDocker::VERSION
11
+ end
12
+
13
+ command 'rescue' do
14
+ description 'Enter Rescue mode'
15
+ on :i, :ip=, 'Server ip'
16
+ run do |options, args|
17
+ host = HetznerHost.new(options.to_hash)
18
+ host.rescuemode
19
+ end
20
+
21
+ end
22
+
23
+ command 'ubuntu' do
24
+ description 'Install Ubuntu 14.04 on server'
25
+ on :i, :ip=, 'Server ip'
26
+ on :H, :hostname=, 'Desired server hostname', argument: :optional
27
+ on :d, :domain=, 'Desired server domain', argument: :optional
28
+ on :u, :url=, 'ubuntu bootstrap script', argument: :optional
29
+
30
+ run do |options, args|
31
+ host = HetznerHost.new(options.to_hash)
32
+ host.rescuemode
33
+ host.install_ubuntu
34
+ end
35
+ end
36
+
37
+ command 'centos' do
38
+ description 'Install CentOS 7 minimal on server'
39
+ on :i, :ip=, 'Server ip'
40
+ on :H, :hostname=, 'Desired server hostname', argument: :optional
41
+ on :d, :domain=, 'Desired server domain', argument: :optional
42
+
43
+ run do |options, args|
44
+ host = HetznerHost.new(options.to_hash)
45
+ host.install_centos
46
+ end
47
+ end
48
+
49
+ command 'coreos' do
50
+ description 'Install CoreOS on server'
51
+ on :i, :ip=, 'Server ip'
52
+ on :H, :hostname=, 'Desired server hostname', argument: :optional
53
+ on :d, :domain=, 'Desired server domain', argument: :optional
54
+
55
+ run do |options, args|
56
+ host = HetznerHost.new(options.to_hash)
57
+ host.rescuemode
58
+ host.install_coreos
59
+ end
60
+ end
61
+
62
+
63
+ command 'chef' do
64
+ on :i, :ip=, 'Server ip'
65
+ on :bootstrap_version=, 'Chef version to install', argument: :optional
66
+ description 'Install Chef'
67
+ run do |options, args|
68
+ host = HetznerHost.new(options.to_hash)
69
+ host.bootstrap_chef
70
+ end
71
+ end
72
+
73
+ command 'cook' do
74
+ description 'Cook recipes'
75
+ on :i, :ip=, 'Server ip'
76
+ on :b, :cookbook= , 'Cook this recipe only', argument: :optional, default: "docker"
77
+ run do |options, args|
78
+ host = HetznerHost.new(options.to_hash)
79
+ host.run_chef
80
+ end
81
+ end
82
+
83
+ command 'bootstrap' do
84
+ description 'Do everything'
85
+ on :i, :ip=, 'Server ip'
86
+ on :H, :hostname=, 'Desired server hostname', argument: :optional
87
+ on :d, :domain=, 'Desired server domain', argument: :optional
88
+ on :b, :cookbook= , 'Cook this recipe only', argument: :optional, default: "docker"
89
+ on :bootstrap_version=, 'Chef version to install'
90
+ run do |options, args|
91
+ host = HetznerHost.new(options.to_hash)
92
+ host.rescuemode
93
+ host.install_ubuntu
94
+ host.bootstrap_chef
95
+ host.run_chef
96
+ end
97
+ end
98
+ end
99
+
100
+ #if ARGV.empty?
101
+ # puts opts.help
102
+ #end
data/cloud-config.yaml ADDED
@@ -0,0 +1,57 @@
1
+ #cloud-config
2
+
3
+ ssh_authorized_keys:
4
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpIgFxCmmSHISwTmSxrYbiBIbuo0CorhnLD9jZQdlFZ6DMdBykr6jcq3mzU7gk1mPSRTqqeuIMceb1OGDE35icg+d4/3dl0Qstq3j6kNP2zg60i5+OleSFdM4TnxrXkjjgCV7QDW/TYndrJiInB0quPNwPnafgHCJWBiHdv0gSm3jEWi2jGbFAL+pIKDoKAgQcTMcUve79gniadVWLc74mf8UcysivVWEwX8UjKZynVcI0tefFYQQeAr+r020oICLdoCDsm7fjDDeosbw6WjVSQgt0p0DZD0a8FUHCjUgQKl7oXC8AcQ+4DY780gOjnnWnHXodCDcOxAj36VqE5DOB melnik@melnik-work
5
+ users:
6
+ - name: melnik
7
+ coreos-ssh-import-github: imelnik
8
+ groups:
9
+ - sudo
10
+ - docker
11
+ - name: denz
12
+ coreos-ssh-import-github: dennybaa
13
+ groups:
14
+ - sudo
15
+ - docker
16
+ hostname: HOSTNAME
17
+ write_files:
18
+ - path: /root/prepare-drive
19
+ permissions: 0755
20
+ content: |
21
+ ##!/bin/bash
22
+ /usr/bin/test -f /var/data/active || /usr/sbin/wipefs -f /dev/sdb
23
+ /usr/bin/test -f /var/data/active || /usr/sbin/mkfs.btrfs -f /dev/sdb
24
+ /usr/bin/test -f /var/data/active || /usr/bin/mkdir -p /var/data
25
+ /usr/bin/touch /var/data/active
26
+ coreos:
27
+ etcd:
28
+ name: HOSTNAME
29
+ discovery: https://discovery.etcd.io/4cd6529256354a0d378888045767bf3b
30
+ addr: EXTIP:4001
31
+ peer-addr: EXTIP:7001
32
+ units:
33
+ - name: etcd.service
34
+ command: start
35
+ - name: fleet.service
36
+ command: start
37
+ - name: format-sdb.service
38
+ command: start
39
+ content: |
40
+ [Unit]
41
+ Description=Formats the sdb drive
42
+ [Service]
43
+ Type=oneshot
44
+ RemainAfterExit=yes
45
+ ExecStart=/bin/bash /root/prepare-drive
46
+ - name: var-data.mount
47
+ command: start
48
+ content: |
49
+ [Unit]
50
+ Description=Mount sdb to /var/data
51
+ Requires=format-sdb.service
52
+ After=format-sdb.service
53
+ Before=docker.service
54
+ [Mount]
55
+ What=/dev/sdb
56
+ Where=/var/data
57
+ Type=btrfs
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+ echo "Starting install"
3
+
4
+ TARGET_HOSTNAME=$1
5
+ TARGET_DOMAIN=$2
6
+
7
+
8
+ /sbin/wipefs -a /dev/sda
9
+ /sbin/wipefs -a /dev/sdb
10
+ export TERM=xterm
11
+
12
+ # Workarond for installimage using dialog for warnings
13
+ # Dialog sucks at autoistalls
14
+ rm /usr/bin/dialog
15
+ ln -s /bin/echo /usr/bin/dialog
16
+
17
+ cat >/autosetup <<EOF
18
+
19
+ DRIVE1 /dev/sda
20
+ DRIVE2 /dev/sdb
21
+ FORMATDRIVE2 0
22
+ SWRAID 0
23
+ SWRAIDLEVEL 1
24
+ BOOTLOADER grub
25
+ HOSTNAME ${TARGET_HOSTNAME}.${TARGET_DOMAIN}
26
+ PART swap swap 48G
27
+ PART /boot ext3 512M
28
+ PART / btrfs all
29
+ IMAGE /root/images/Ubuntu-1404-trusty-64-minimal.tar.gz
30
+ EOF
31
+
32
+ /root/.oldroot/nfs/install/installimage -a -c /autosetup
33
+
34
+ reboot
35
+ exit
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hetzner-docker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hetzner-docker'
8
+ spec.version = HetznerDocker::VERSION
9
+ spec.authors = ['Sergey Melnik']
10
+ spec.email = ['admin.sa@gmail.com']
11
+ spec.summary = 'Hetzner servers cli installation'
12
+ spec.description = 'Configures and installs docker to Hetzner server in\
13
+ default bootstrap mode, yet has some server management\
14
+ modes like rescue mode, CentOS and CoreOS installation'
15
+ spec.homepage = 'https://github.com/iMelnik/hetzner-docker'
16
+ spec.license = 'GPLv2'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_runtime_dependency 'hetzner-api', '~> 0'
25
+ spec.add_runtime_dependency 'net-ssh', '~> 0'
26
+ spec.add_runtime_dependency 'net-scp', '~> 0'
27
+ spec.add_runtime_dependency 'knife-solo', '~> 0'
28
+ spec.add_runtime_dependency 'berkshelf', '~> 3.1'
29
+ spec.add_runtime_dependency 'slop', '~> 0'
30
+ end
@@ -0,0 +1,37 @@
1
+ require 'hetzner-api'
2
+
3
+ class HetznerHost
4
+ def install_centos
5
+ puts "Installing CentOS!"
6
+ hetzner = Hetzner::API.new ENV['HETZNER_USER'], ENV['HETZNER_PASSWORD']
7
+ server = hetzner.server? @ip
8
+
9
+ if server.parsed_response.has_key?("server")
10
+ hostname = server.parsed_response["server"]["server_name"]
11
+ puts "Resetting #{hostname} at #{@ip}"
12
+ else
13
+ raise server.parsed_response["error"]["message"]
14
+ end
15
+
16
+ hetzner.disable_rescue! @ip
17
+ result = hetzner.boot_linux!(@ip,"CentOS 7.0 minimal", "64", "en" )
18
+
19
+ if result.parsed_response.has_key?("linux")
20
+ @password = result.parsed_response["linux"]["password"]
21
+ puts @password
22
+ hetzner.reset! @ip, 'sw'
23
+ wait_for_reboot
24
+ put_key
25
+ puts "Wait while CentOS is being installed"
26
+ wait_for_reboot
27
+ put_key
28
+ puts "CentOS installed"
29
+ else
30
+ raise result.parsed_response["error"]["message"]
31
+ end
32
+
33
+
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'chef'
2
+ require 'chef/knife'
3
+ require 'chef/knife/bootstrap'
4
+ require 'chef/knife/ssh'
5
+ require 'chef/knife/solo_prepare'
6
+ require 'knife-solo/bootstraps'
7
+ require 'knife-solo/ssh_command'
8
+ require 'knife-solo/node_config_command'
9
+ require 'knife-solo/ssh_connection'
10
+
11
+ class HetznerHost
12
+ def bootstrap_chef
13
+ kb = Chef::Knife::SoloPrepare.new
14
+ kb.config[:ssh_user] = @user
15
+ kb.name_args = [@ip]
16
+ Chef::Config[:knife][:bootstrap_version] = @bootstrap_version
17
+ kb.run
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'chef'
2
+ require 'chef/knife'
3
+ require 'chef/knife/ssh'
4
+ require 'chef/knife/solo_cook'
5
+
6
+ require 'berkshelf'
7
+ require 'erubis'
8
+ require 'pathname'
9
+
10
+ require 'knife-solo'
11
+ require 'knife-solo/ssh_command'
12
+ require 'knife-solo/berkshelf'
13
+ require 'knife-solo/node_config_command'
14
+ require 'knife-solo/ssh_connection'
15
+ require 'knife-solo/tools'
16
+
17
+ class HetznerHost
18
+ def run_chef
19
+ kb = Chef::Knife::SoloCook.new
20
+ kb.config[:ssh_user] = @user
21
+ kb.config[:override_runlist] = @cookbook
22
+ kb.config[:librarian] = false
23
+ kb.config[:host_key_verify] = false
24
+ kb.name_args = [@ip]
25
+ kb.run
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'net/ssh'
2
+ require 'net/scp'
3
+
4
+
5
+ class HetznerHost
6
+ def install_coreos
7
+ puts "Goint to install coreos at #{@ip}"
8
+ cloud_config=`cat cloud-config.yaml | sed s/EXTIP/#{@ip}/g | sed 's/HOSTNAME/#{hostname}/g'`
9
+ Net::SSH.start(@ip, @user) do |ssh|
10
+ #puts cloud_config
11
+ ssh.exec "cat >/run/cloud-config.yaml <<EOF #cloud-config\n#{cloud_config} \nEOF"
12
+ ssh.exec "wget --quiet https://raw.github.com/coreos/init/master/bin/coreos-install -O /root/coreos-install && /bin/bash /root/coreos-install -d /dev/sda -c /run/cloud-config.yaml && reboot"
13
+ end
14
+ clear_known_key
15
+ wait_for_reboot
16
+ puts "Fresh coreos installed at #{@ip}"
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ require 'hetzner-api'
2
+
3
+ class HetznerHost
4
+ def rescuemode
5
+ puts "to the rescue!"
6
+ hetzner = Hetzner::API.new ENV['HETZNER_USER'], ENV['HETZNER_PASSWORD']
7
+ server = hetzner.server? @ip
8
+
9
+ if server.parsed_response.has_key?("server")
10
+ hostname = server.parsed_response["server"]["server_name"]
11
+ puts "Resetting #{hostname} at #{@ip}"
12
+ else
13
+ raise server.parsed_response["error"]["message"]
14
+ end
15
+
16
+ hetzner.disable_rescue! @ip
17
+ result = hetzner.enable_rescue! @ip
18
+
19
+ if result.parsed_response.has_key?("rescue")
20
+ @password = result.parsed_response["rescue"]["password"]
21
+ puts @password
22
+ hetzner.reset! @ip, 'hw'
23
+ wait_for_reboot
24
+ put_key
25
+ else
26
+ raise result.parsed_response["error"]["message"]
27
+ end
28
+
29
+
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/ssh'
2
+ require 'net/scp'
3
+
4
+ class HetznerHost
5
+ def put_key
6
+ clear_known_key
7
+ identity_file = File.expand_path(DEFAULT_IDENTITY_FILE)
8
+ Net::SSH.start(@ip, @user, :password => @password) do |ssh|
9
+ ssh.exec "test -d ~/.ssh || mkdir ~/.ssh"
10
+ if @password
11
+ ssh.scp.upload! identity_file, "/root/.ssh/authorized_keys"
12
+ puts "ssh identity copied"
13
+ end
14
+ end
15
+ end
16
+
17
+ def clear_known_key
18
+ system("ssh-keygen -q -R #{@ip} >/dev/null")
19
+ end
20
+
21
+ def wait_for_reboot
22
+ while test_ssh
23
+ sleep 1
24
+ end
25
+ puts "Waiting for #{@ip}..." until test_ssh
26
+ end
27
+
28
+ def test_ssh(port = 22)
29
+ socket = TCPSocket.new(@ip, port)
30
+ IO.select([socket], nil, nil, 5)
31
+ rescue SocketError, Errno::ECONNREFUSED,
32
+ Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError
33
+ sleep 2
34
+ false
35
+ rescue Errno::EPERM, Errno::ETIMEDOUT
36
+ false
37
+ ensure
38
+ socket && socket.close
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'net/ssh'
2
+ require 'net/scp'
3
+
4
+
5
+ class HetznerHost
6
+ def install_ubuntu
7
+ puts "Goint to install ubuntu at #{@ip}"
8
+ Net::SSH.start(@ip, @user) do |ssh|
9
+ ssh.scp.upload! "do-install-trusty.sh", "/root/do-install-trusty.sh" do |ch, name, sent, total|
10
+ puts "#{name}: #{sent}/#{total}"
11
+ end
12
+ ssh.exec "/bin/bash /root/do-install-trusty.sh #{@hostname} #{@domain}"
13
+ end
14
+ clear_known_key
15
+ wait_for_reboot
16
+ put_key
17
+ puts "Fresh ubuntu installed at #{@ip}"
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module HetznerDocker
2
+ VERSION = "0.0.1"
3
+ def version
4
+ puts VERSION
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ require "hetzner-docker/version"
2
+ require "hetzner-docker/rescuemode"
3
+ require "hetzner-docker/ubuntu"
4
+ require "hetzner-docker/centos"
5
+ require "hetzner-docker/coreos"
6
+ require "hetzner-docker/chefbootstrap"
7
+ require "hetzner-docker/chefrun"
8
+ require "hetzner-docker/tools"
9
+
10
+ class HetznerHost
11
+ include HetznerDocker
12
+
13
+ def initialize(init)
14
+ init.each_pair do |key, val|
15
+ instance_variable_set('@' + key.to_s, val)
16
+ end
17
+ unless defined?(@user)
18
+ @user='root'
19
+ end
20
+ unless defined?(@hostname) and @hostname != nil
21
+ @hostname="docker#{SecureRandom.hex(3)+@ip.rpartition(".")[2]}"
22
+ end
23
+ unless defined?(@domain) and @domain != nil
24
+ @domain="twiket.com" # this is our default, sorry
25
+ end
26
+ unless defined?(@url) and @url != nil
27
+ @url="https://raw.githubusercontent.com/iMelnik/hetzner-docker/master/do-install-trusty.sh"
28
+ end
29
+
30
+ end
31
+ def user
32
+ @user
33
+ end
34
+ def hostname
35
+ @hostname
36
+ end
37
+
38
+ end
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=Ambari Server
3
+ After=docker.service
4
+
5
+ [Service]
6
+ TimeoutStartSec=0
7
+ ExecStartPre=/root/ambari.sh -i 192.168.90.10
8
+ ExecStart=/usr/bin/docker attach --no-stdin=true amb0
9
+ ExecStop=/usr/bin/docker stop amb0
10
+ Type=forking
11
+ PIDFile=/var/run/docker/amb0.pid
@@ -0,0 +1,15 @@
1
+ [Unit]
2
+ Description=Ambari Node
3
+ After=docker.service
4
+
5
+ [Service]
6
+ TimeoutStartSec=0
7
+ ExecStartPre=/root/ambari.sh -i 192.168.90.1%i %i 192.168.90.10
8
+ ExecStart=/usr/bin/docker attach amb%i
9
+ ExecStop=/usr/bin/docker stop amb%i
10
+ Type=forking
11
+ PIDFile=/var/run/docker/amb%i.pid
12
+ Restart=on-failure
13
+
14
+ [X-Fleet]
15
+ X-Conflicts=ambari-node@*.service
@@ -0,0 +1,9 @@
1
+ [Unit]
2
+ Description=nsenter binary
3
+ After=docker.service
4
+
5
+ [Service]
6
+ TimeoutStartSec=0
7
+ ExecStartPre=/usr/bin/docker pull jpetazzo/nsenter
8
+ ExecStart=/usr/bin/docker run --rm -v /usr/local/sbin:/target jpetazzo/nsenter
9
+ Type=oneshot
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hetzner-docker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Melnik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hetzner-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-scp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: knife-solo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: berkshelf
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: slop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |-
112
+ Configures and installs docker to Hetzner server in\
113
+ default bootstrap mode, yet has some server management\
114
+ modes like rescue mode, CentOS and CoreOS installation
115
+ email:
116
+ - admin.sa@gmail.com
117
+ executables:
118
+ - hetzner-docker
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - ".gitignore"
123
+ - Berksfile
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - bin/hetzner-docker
128
+ - cloud-config.yaml
129
+ - do-install-trusty.sh
130
+ - hetzner-docker.gemspec
131
+ - lib/hetzner-docker.rb
132
+ - lib/hetzner-docker/centos.rb
133
+ - lib/hetzner-docker/chefbootstrap.rb
134
+ - lib/hetzner-docker/chefrun.rb
135
+ - lib/hetzner-docker/coreos.rb
136
+ - lib/hetzner-docker/rescuemode.rb
137
+ - lib/hetzner-docker/tools.rb
138
+ - lib/hetzner-docker/ubuntu.rb
139
+ - lib/hetzner-docker/version.rb
140
+ - services/ambari-master.service
141
+ - services/ambari-node@.service
142
+ - services/nsenter.service
143
+ homepage: https://github.com/iMelnik/hetzner-docker
144
+ licenses:
145
+ - GPLv2
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.4.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Hetzner servers cli installation
167
+ test_files: []