krates-plugin-digitalocean 0.3.8

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
+ SHA256:
3
+ metadata.gz: e4e9e3a39babaaf4a7ef6a86b182e834cbe7653b4a8298d340d4067e9a47f3df
4
+ data.tar.gz: 29001f2fa141878d8812c3dd0875dc09362fd22dc13827f453776088f733e6ee
5
+ SHA512:
6
+ metadata.gz: 8781d96177b0cb2199309d8181349932f7b7d6e946183c4991cfb57f9b8dd0f45088b3a4d4eebba1c8fc8e0adadb0279855f9c84823ef6b338acb19b9560d0de
7
+ data.tar.gz: 77dfb4a7c336c68e3910ff328c73755ae0eb7610b3d08f75b1fa29adaac3dad04996ec1609d3f32f07bedb6cbaf26c8fa9bcf4d2b905237ed76126d2d9b24d11
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.gitmodules ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kontena-plugin-aws.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rspec'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,214 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Pavel Tsurbeleu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+
25
+ Apache License
26
+ Version 2.0, January 2004
27
+ http://www.apache.org/licenses/
28
+
29
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
30
+
31
+ 1. Definitions.
32
+
33
+ "License" shall mean the terms and conditions for use, reproduction,
34
+ and distribution as defined by Sections 1 through 9 of this document.
35
+
36
+ "Licensor" shall mean the copyright owner or entity authorized by
37
+ the copyright owner that is granting the License.
38
+
39
+ "Legal Entity" shall mean the union of the acting entity and all
40
+ other entities that control, are controlled by, or are under common
41
+ control with that entity. For the purposes of this definition,
42
+ "control" means (i) the power, direct or indirect, to cause the
43
+ direction or management of such entity, whether by contract or
44
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
45
+ outstanding shares, or (iii) beneficial ownership of such entity.
46
+
47
+ "You" (or "Your") shall mean an individual or Legal Entity
48
+ exercising permissions granted by this License.
49
+
50
+ "Source" form shall mean the preferred form for making modifications,
51
+ including but not limited to software source code, documentation
52
+ source, and configuration files.
53
+
54
+ "Object" form shall mean any form resulting from mechanical
55
+ transformation or translation of a Source form, including but
56
+ not limited to compiled object code, generated documentation,
57
+ and conversions to other media types.
58
+
59
+ "Work" shall mean the work of authorship, whether in Source or
60
+ Object form, made available under the License, as indicated by a
61
+ copyright notice that is included in or attached to the work
62
+ (an example is provided in the Appendix below).
63
+
64
+ "Derivative Works" shall mean any work, whether in Source or Object
65
+ form, that is based on (or derived from) the Work and for which the
66
+ editorial revisions, annotations, elaborations, or other modifications
67
+ represent, as a whole, an original work of authorship. For the purposes
68
+ of this License, Derivative Works shall not include works that remain
69
+ separable from, or merely link (or bind by name) to the interfaces of,
70
+ the Work and Derivative Works thereof.
71
+
72
+ "Contribution" shall mean any work of authorship, including
73
+ the original version of the Work and any modifications or additions
74
+ to that Work or Derivative Works thereof, that is intentionally
75
+ submitted to Licensor for inclusion in the Work by the copyright owner
76
+ or by an individual or Legal Entity authorized to submit on behalf of
77
+ the copyright owner. For the purposes of this definition, "submitted"
78
+ means any form of electronic, verbal, or written communication sent
79
+ to the Licensor or its representatives, including but not limited to
80
+ communication on electronic mailing lists, source code control systems,
81
+ and issue tracking systems that are managed by, or on behalf of, the
82
+ Licensor for the purpose of discussing and improving the Work, but
83
+ excluding communication that is conspicuously marked or otherwise
84
+ designated in writing by the copyright owner as "Not a Contribution."
85
+
86
+ "Contributor" shall mean Licensor and any individual or Legal Entity
87
+ on behalf of whom a Contribution has been received by Licensor and
88
+ subsequently incorporated within the Work.
89
+
90
+ 2. Grant of Copyright License. Subject to the terms and conditions of
91
+ this License, each Contributor hereby grants to You a perpetual,
92
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
93
+ copyright license to reproduce, prepare Derivative Works of,
94
+ publicly display, publicly perform, sublicense, and distribute the
95
+ Work and such Derivative Works in Source or Object form.
96
+
97
+ 3. Grant of Patent License. Subject to the terms and conditions of
98
+ this License, each Contributor hereby grants to You a perpetual,
99
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
100
+ (except as stated in this section) patent license to make, have made,
101
+ use, offer to sell, sell, import, and otherwise transfer the Work,
102
+ where such license applies only to those patent claims licensable
103
+ by such Contributor that are necessarily infringed by their
104
+ Contribution(s) alone or by combination of their Contribution(s)
105
+ with the Work to which such Contribution(s) was submitted. If You
106
+ institute patent litigation against any entity (including a
107
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
108
+ or a Contribution incorporated within the Work constitutes direct
109
+ or contributory patent infringement, then any patent licenses
110
+ granted to You under this License for that Work shall terminate
111
+ as of the date such litigation is filed.
112
+
113
+ 4. Redistribution. You may reproduce and distribute copies of the
114
+ Work or Derivative Works thereof in any medium, with or without
115
+ modifications, and in Source or Object form, provided that You
116
+ meet the following conditions:
117
+
118
+ (a) You must give any other recipients of the Work or
119
+ Derivative Works a copy of this License; and
120
+
121
+ (b) You must cause any modified files to carry prominent notices
122
+ stating that You changed the files; and
123
+
124
+ (c) You must retain, in the Source form of any Derivative Works
125
+ that You distribute, all copyright, patent, trademark, and
126
+ attribution notices from the Source form of the Work,
127
+ excluding those notices that do not pertain to any part of
128
+ the Derivative Works; and
129
+
130
+ (d) If the Work includes a "NOTICE" text file as part of its
131
+ distribution, then any Derivative Works that You distribute must
132
+ include a readable copy of the attribution notices contained
133
+ within such NOTICE file, excluding those notices that do not
134
+ pertain to any part of the Derivative Works, in at least one
135
+ of the following places: within a NOTICE text file distributed
136
+ as part of the Derivative Works; within the Source form or
137
+ documentation, if provided along with the Derivative Works; or,
138
+ within a display generated by the Derivative Works, if and
139
+ wherever such third-party notices normally appear. The contents
140
+ of the NOTICE file are for informational purposes only and
141
+ do not modify the License. You may add Your own attribution
142
+ notices within Derivative Works that You distribute, alongside
143
+ or as an addendum to the NOTICE text from the Work, provided
144
+ that such additional attribution notices cannot be construed
145
+ as modifying the License.
146
+
147
+ You may add Your own copyright statement to Your modifications and
148
+ may provide additional or different license terms and conditions
149
+ for use, reproduction, or distribution of Your modifications, or
150
+ for any such Derivative Works as a whole, provided Your use,
151
+ reproduction, and distribution of the Work otherwise complies with
152
+ the conditions stated in this License.
153
+
154
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
155
+ any Contribution intentionally submitted for inclusion in the Work
156
+ by You to the Licensor shall be under the terms and conditions of
157
+ this License, without any additional terms or conditions.
158
+ Notwithstanding the above, nothing herein shall supersede or modify
159
+ the terms of any separate license agreement you may have executed
160
+ with Licensor regarding such Contributions.
161
+
162
+ 6. Trademarks. This License does not grant permission to use the trade
163
+ names, trademarks, service marks, or product names of the Licensor,
164
+ except as required for reasonable and customary use in describing the
165
+ origin of the Work and reproducing the content of the NOTICE file.
166
+
167
+ 7. Disclaimer of Warranty. Unless required by applicable law or
168
+ agreed to in writing, Licensor provides the Work (and each
169
+ Contributor provides its Contributions) on an "AS IS" BASIS,
170
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
171
+ implied, including, without limitation, any warranties or conditions
172
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
173
+ PARTICULAR PURPOSE. You are solely responsible for determining the
174
+ appropriateness of using or redistributing the Work and assume any
175
+ risks associated with Your exercise of permissions under this License.
176
+
177
+ 8. Limitation of Liability. In no event and under no legal theory,
178
+ whether in tort (including negligence), contract, or otherwise,
179
+ unless required by applicable law (such as deliberate and grossly
180
+ negligent acts) or agreed to in writing, shall any Contributor be
181
+ liable to You for damages, including any direct, indirect, special,
182
+ incidental, or consequential damages of any character arising as a
183
+ result of this License or out of the use or inability to use the
184
+ Work (including but not limited to damages for loss of goodwill,
185
+ work stoppage, computer failure or malfunction, or any and all
186
+ other commercial damages or losses), even if such Contributor
187
+ has been advised of the possibility of such damages.
188
+
189
+ 9. Accepting Warranty or Additional Liability. While redistributing
190
+ the Work or Derivative Works thereof, You may choose to offer,
191
+ and charge a fee for, acceptance of support, warranty, indemnity,
192
+ or other liability obligations and/or rights consistent with this
193
+ License. However, in accepting such obligations, You may act only
194
+ on Your own behalf and on Your sole responsibility, not on behalf
195
+ of any other Contributor, and only if You agree to indemnify,
196
+ defend, and hold each Contributor harmless for any liability
197
+ incurred by, or claims asserted against, such Contributor by reason
198
+ of your accepting any such warranty or additional liability.
199
+
200
+ END OF TERMS AND CONDITIONS
201
+
202
+ Copyright 2015 Kontena, Inc.
203
+
204
+ Licensed under the Apache License, Version 2.0 (the "License");
205
+ you may not use this file except in compliance with the License.
206
+ You may obtain a copy of the License at
207
+
208
+ http://www.apache.org/licenses/LICENSE-2.0
209
+
210
+ Unless required by applicable law or agreed to in writing, software
211
+ distributed under the License is distributed on an "AS IS" BASIS,
212
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
213
+ See the License for the specific language governing permissions and
214
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Krates DigitalOcean Plugin
2
+
3
+ This plugin provides support for DigitalOcean provisioning to Kontena CLI.
4
+
5
+
6
+ ## Contributing
7
+
8
+ 1. Fork it ( https://bitbucket.org/staticpagesio/staticpagesio-plugin-digitalocean )
9
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
10
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
11
+ 4. Push to the branch (`git push origin my-new-feature`)
12
+ 5. Create a new Pull Request
13
+
14
+ ## License
15
+
16
+ Krates is licensed under the MIT License. See [LICENSE](LICENSE.txt) for full license text.
17
+
18
+ Kontena is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE.txt) for full license text.
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kontena/plugin/digital_ocean'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "krates-plugin-digitalocean"
8
+ spec.version = Kontena::Plugin::DigitalOcean::VERSION
9
+ spec.authors = ["Pavel Tsurbeleu"]
10
+ spec.email = ["staticpagesio@gmail.com"]
11
+
12
+ spec.summary = "Krates DigitalOcean plugin"
13
+ spec.description = "Krates DigitalOcean plugin"
14
+ spec.homepage = "https://krates.appsters.io"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ # NOTE: Exclude files not relevant to the plugin
21
+ spec.files -= %w[ Dockerfile Makefile docker-compose.yml docker-compose.dev.yml Jenkinsfile .dockerignore ]
22
+
23
+ spec.add_runtime_dependency 'kontena-cli', '1.5.2'
24
+ spec.add_runtime_dependency 'droplet_kit', '~> 2.2'
25
+ spec.add_runtime_dependency 'activesupport', '~> 4.0'
26
+ spec.add_runtime_dependency 'pastel', '0.7.2'
27
+ spec.add_development_dependency "bundler", "~> 1.11"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
@@ -0,0 +1,86 @@
1
+ #cloud-config
2
+ write_files:
3
+ - path: /etc/kontena-agent.env
4
+ permissions: 0600
5
+ owner: root
6
+ content: |
7
+ KONTENA_URI=<%= master_uri %>
8
+ KONTENA_TOKEN=<%= grid_token %>
9
+ KONTENA_PEER_INTERFACE=eth1
10
+ KONTENA_VERSION=<%= version %>
11
+ - path: /etc/systemd/system/docker.service.d/50-kontena.conf
12
+ content: |
13
+ [Service]
14
+ Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/16" --bip="172.17.43.1/16" -s overlay2'
15
+ Environment='DOCKER_CGROUPS=--exec-opt native.cgroupdriver=cgroupfs'
16
+ - path: /etc/sysctl.d/99-inotify.conf
17
+ owner: root
18
+ permissions: 0644
19
+ content: |
20
+ fs.inotify.max_user_instances = 8192
21
+ - path: /etc/resolv.conf
22
+ permissions: 0644
23
+ owner: root
24
+ content: |
25
+ nameserver 172.17.43.1
26
+ nameserver 8.8.8.8
27
+ nameserver 8.8.4.4
28
+ coreos:
29
+ units:
30
+ - name: etcd2.service
31
+ command: start
32
+ enable: true
33
+ content: |
34
+ [Unit]
35
+ Description=Kontena etcd 2.0
36
+ After=docker.service
37
+ After=kontena-agent.service
38
+ Requires=docker.service
39
+ [Service]
40
+ Restart=always
41
+ RestartSec=5
42
+ ExecStart=/usr/bin/docker logs --tail=10 -f kontena-etcd
43
+ - name: 50-docker.network
44
+ mask: true
45
+ - name: 50-docker-veth.network
46
+ mask: true
47
+ - name: zz-default.network
48
+ runtime: false
49
+ content: |
50
+ # default should only match real network interfaces
51
+ [Match]
52
+ Name=eth*
53
+
54
+ [Network]
55
+ DHCP=yes
56
+
57
+ [DHCP]
58
+ UseMTU=true
59
+ UseDomains=true
60
+ - name: kontena-agent.service
61
+ command: start
62
+ enable: true
63
+ content: |
64
+ [Unit]
65
+ Description=kontena-agent
66
+ After=network-online.target
67
+ After=docker.service
68
+ Description=Kontena Agent
69
+ Documentation=http://www.kontena.io/
70
+ Requires=network-online.target
71
+ Requires=docker.service
72
+
73
+ [Service]
74
+ Restart=always
75
+ RestartSec=5
76
+ EnvironmentFile=/etc/kontena-agent.env
77
+ ExecStartPre=-/usr/bin/docker stop kontena-agent
78
+ ExecStartPre=-/usr/bin/docker rm kontena-agent
79
+ ExecStartPre=/usr/bin/docker pull kontena/agent:${KONTENA_VERSION}
80
+ ExecStart=/usr/bin/docker run --name kontena-agent \
81
+ --env-file /etc/kontena-agent.env \
82
+ -v=/var/run/docker.sock:/var/run/docker.sock \
83
+ -v=/etc/kontena-agent.env:/etc/kontena.env \
84
+ --net=host \
85
+ kontena/agent:${KONTENA_VERSION}
86
+ ExecStop=/usr/bin/docker stop kontena-agent
@@ -0,0 +1,126 @@
1
+ #cloud-config
2
+ write_files:
3
+ - path: /etc/kontena-server.env
4
+ permissions: 0600
5
+ owner: root
6
+ content: |
7
+ KONTENA_VERSION=<%= version %>
8
+ KONTENA_VAULT_KEY=<%= vault_secret %>
9
+ KONTENA_VAULT_IV=<%= vault_iv %>
10
+ <% if ssl_cert %>SSL_CERT="/etc/kontena-server.pem"
11
+
12
+ - path: /etc/kontena-server.pem
13
+ permissions: 0600
14
+ owner: root
15
+ content: | <% ssl_cert.split(/\n/).each do |row| %>
16
+ <%= row %><% end %><% end %>
17
+ - path: /opt/bin/kontena-haproxy.sh
18
+ permissions: 0755
19
+ owner: root
20
+ content: |
21
+ #!/bin/sh
22
+ if [ -n "$SSL_CERT" ]; then
23
+ SSL_CERT=$(awk 1 ORS='\\n' $SSL_CERT)
24
+ else
25
+ SSL_CERT="**None**"
26
+ fi
27
+ /usr/bin/docker run --name=kontena-server-haproxy \
28
+ --link kontena-server-api:kontena-server-api \
29
+ -e SSL_CERT="$SSL_CERT" \
30
+ -p 80:80 -p 443:443 kontena/haproxy:latest
31
+ coreos:
32
+ units:
33
+ <% unless mongodb_uri -%>
34
+ - name: kontena-server-mongo.service
35
+ command: start
36
+ enable: true
37
+ content: |
38
+ [Unit]
39
+ Description=kontena-server-mongo
40
+ After=network-online.target
41
+ After=docker.service
42
+ Description=Kontena Server MongoDB
43
+ Documentation=http://www.mongodb.org/
44
+ Requires=network-online.target
45
+ Requires=docker.service
46
+
47
+ [Service]
48
+ Restart=always
49
+ RestartSec=5
50
+ ExecStartPre=/usr/bin/docker pull mongo:3.0
51
+ ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
52
+ ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
53
+ ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
54
+ ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
55
+ --volumes-from=kontena-server-mongo-data \
56
+ mongo:3.0 mongod --smallfiles
57
+ ExecStop=/usr/bin/docker stop kontena-server-mongo
58
+ <% end -%>
59
+ - name: kontena-server-api.service
60
+ command: start
61
+ enable: true
62
+ content: |
63
+ [Unit]
64
+ Description=kontena-server-api
65
+ After=network-online.target
66
+ After=docker.service
67
+ After=kontena-server-mongo.service
68
+ Description=Kontena Master
69
+ Documentation=http://www.kontena.io/
70
+ Before=kontena-server-haproxy.service
71
+ Wants=kontena-server-haproxy.service
72
+ Requires=network-online.target
73
+ Requires=docker.service
74
+ <% unless mongodb_uri -%>
75
+ Requires=kontena-server-mongo.service
76
+ <% end %>
77
+
78
+ [Service]
79
+ Restart=always
80
+ RestartSec=5
81
+ EnvironmentFile=/etc/kontena-server.env
82
+ EnvironmentFile=-/etc/kontena-server.custom.env
83
+ ExecStartPre=-/usr/bin/docker stop kontena-server-api
84
+ ExecStartPre=-/usr/bin/docker rm kontena-server-api
85
+ ExecStartPre=-/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
86
+ ExecStart=/usr/bin/docker run --name kontena-server-api \
87
+ <% if mongodb_uri -%>
88
+ -e MONGODB_URI=<%= mongodb_uri %> \
89
+ <% else -%>
90
+ --link kontena-server-mongo:mongodb \
91
+ -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
92
+ <% end -%>
93
+ <% if server_name -%>
94
+ -e SERVER_NAME=<%= server_name %> \
95
+ <% end -%>
96
+ <% if initial_admin_code -%>
97
+ -e INITIAL_ADMIN_CODE=<%= initial_admin_code %> \
98
+ <% end -%>
99
+ -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
100
+ kontena/server:${KONTENA_VERSION}
101
+ ExecStop=/usr/bin/docker stop kontena-server-api
102
+
103
+ - name: kontena-server-haproxy.service
104
+ command: start
105
+ enable: true
106
+ content: |
107
+ [Unit]
108
+ Description=kontena-server-haproxy
109
+ After=network-online.target
110
+ After=docker.service
111
+ Description=Kontena Server HAProxy
112
+ Documentation=http://www.kontena.io/
113
+ Requires=network-online.target
114
+ Requires=docker.service
115
+ Requires=kontena-server-api.service
116
+
117
+ [Service]
118
+ Restart=always
119
+ RestartSec=5
120
+ EnvironmentFile=/etc/kontena-server.env
121
+ EnvironmentFile=-/etc/kontena-server.custom.env
122
+ ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
123
+ ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
124
+ ExecStartPre=-/usr/bin/docker pull kontena/haproxy:latest
125
+ ExecStart=/opt/bin/kontena-haproxy.sh
126
+ ExecStop=/usr/bin/docker stop kontena-server-haproxy
@@ -0,0 +1,30 @@
1
+ module Kontena
2
+ module Machine
3
+ module DigitalOcean
4
+ class MasterDestroyer
5
+ include Kontena::Cli::ShellSpinner
6
+
7
+ attr_reader :client, :api_client
8
+
9
+ # @param [String] token Digital Ocean token
10
+ def initialize(token)
11
+ @client = DropletKit::Client.new(access_token: token)
12
+ end
13
+
14
+ def run!(name)
15
+ droplet = client.droplets.all.find{|d| d.name == name}
16
+ if droplet
17
+ spinner "Terminating DigitalOcean droplet #{name.colorize(:cyan)} " do
18
+ result = client.droplets.delete(id: droplet.id)
19
+ if result.is_a?(String)
20
+ abort "Cannot delete droplet #{name.colorize(:cyan)} in DigitalOcean"
21
+ end
22
+ end
23
+ else
24
+ abort "Cannot find droplet #{name.colorize(:cyan)} in DigitalOcean"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,99 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+ require 'open3'
4
+
5
+ module Kontena
6
+ module Machine
7
+ module DigitalOcean
8
+ class MasterProvisioner
9
+ include RandomName
10
+ include Machine::CertHelper
11
+ include Kontena::Cli::ShellSpinner
12
+
13
+ attr_reader :client, :http_client
14
+
15
+ # @param [String] token Digital Ocean token
16
+ def initialize(token)
17
+ @client = DropletKit::Client.new(access_token: token)
18
+ end
19
+
20
+ def run!(opts)
21
+ if opts[:ssl_cert]
22
+ abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
23
+ ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
24
+ else
25
+ spinner "Generating self-signed SSL certificate" do
26
+ ssl_cert = generate_self_signed_cert
27
+ end
28
+ end
29
+
30
+ name = opts[:name]
31
+ userdata_vars = opts.merge(
32
+ ssl_cert: ssl_cert,
33
+ server_name: name
34
+ )
35
+
36
+ droplet = DropletKit::Droplet.new(
37
+ name: name,
38
+ region: opts[:region],
39
+ image: 'coreos-stable',
40
+ size: opts[:size],
41
+ private_networking: true,
42
+ user_data: user_data(userdata_vars),
43
+ ssh_keys: [opts[:ssh_key_id]],
44
+ tags: ['master']
45
+ )
46
+
47
+ spinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
48
+ droplet = client.droplets.create(droplet)
49
+ until droplet.status == 'active'
50
+ droplet = client.droplets.find(id: droplet.id)
51
+ sleep 1
52
+ end
53
+ end
54
+
55
+ master_url = "https://#{droplet.public_ip}"
56
+ Excon.defaults[:ssl_verify_peer] = false
57
+ @http_client = Excon.new("#{master_url}", {
58
+ :connect_timeout => 10,
59
+ :ssl_verify_peer => false
60
+ })
61
+
62
+ spinner "Waiting for #{droplet.name.colorize(:cyan)} to start" do
63
+ sleep 0.5 until master_running?
64
+ end
65
+
66
+ puts
67
+ puts "Kontena Master is now running at #{master_url}".colorize(:green)
68
+ puts
69
+
70
+ data = {
71
+ name: name.sub('kontena-master-', ''),
72
+ public_ip: droplet.public_ip,
73
+ code: opts[:initial_admin_code]
74
+ }
75
+ if respond_to?(:certificate_public_key) && !opts[:ssl_cert]
76
+ data[:ssl_certificate] = certificate_public_key(ssl_cert)
77
+ end
78
+
79
+ data
80
+ end
81
+
82
+ def user_data(vars)
83
+ cloudinit_template = File.join(__dir__ , '/cloudinit_master.yml')
84
+ erb(File.read(cloudinit_template), vars)
85
+ end
86
+
87
+ def master_running?
88
+ http_client.get(path: '/').status == 200
89
+ rescue
90
+ false
91
+ end
92
+
93
+ def erb(template, vars)
94
+ ERB.new(template, nil, '%<>-').result(OpenStruct.new(vars).instance_eval { binding })
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,39 @@
1
+ module Kontena
2
+ module Machine
3
+ module DigitalOcean
4
+ class NodeDestroyer
5
+ include RandomName
6
+ include Kontena::Cli::ShellSpinner
7
+
8
+ attr_reader :client, :api_client
9
+
10
+ # @param [Kontena::Client] api_client Kontena api client
11
+ # @param [String] token Digital Ocean token
12
+ def initialize(api_client, token)
13
+ @api_client = api_client
14
+ @client = DropletKit::Client.new(access_token: token)
15
+ end
16
+
17
+ def run!(grid, name)
18
+ droplet = client.droplets.all.find{|d| d.name == name}
19
+ if droplet
20
+ spinner "Terminating DigitalOcean droplet #{name.colorize(:cyan)} " do
21
+ result = client.droplets.delete(id: droplet.id)
22
+ if result.is_a?(String)
23
+ abort "Cannot delete droplet #{name.colorize(:cyan)} in DigitalOcean"
24
+ end
25
+ end
26
+ else
27
+ abort "Cannot find droplet #{name.colorize(:cyan)} in DigitalOcean"
28
+ end
29
+ node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
30
+ if node
31
+ spinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
32
+ api_client.delete("nodes/#{grid['id']}/#{name}")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end