cronicle 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/Vagrantfile +17 -22
- data/lib/cronicle/dsl/context/job.rb +17 -5
- data/lib/cronicle/version.rb +1 -1
- data/spec/cronicle_exec_spec.rb +39 -0
- data/spec/spec_helper.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a9b9808f5544209161321c06c465715a6f07dd
|
4
|
+
data.tar.gz: 3a63c1278482a6a6af9dc9e57c3a873ac81989ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f85ee6ee7e0e12e391282895c63400bf627ad6f7f8b30b541b2a56badcbdca2627d5d57408fb502e421246243154d174983da49877601a179257f96a69d1fc29
|
7
|
+
data.tar.gz: ffe7a07a5c8f8bbd1faa49e06495f4027ba59eb32229c9e92b0ef8546340a2eab330518e799abffb00f41bda340d599b56ba15f6751264f3c98ea1f22115f43c
|
data/README.md
CHANGED
@@ -88,6 +88,21 @@ puts "hello"
|
|
88
88
|
|
89
89
|
## Jobfile example
|
90
90
|
|
91
|
+
```ruby
|
92
|
+
on servers: :your_hostname do
|
93
|
+
job :my_job, user: "ec2-user", schedule: "* * * * *" do
|
94
|
+
puts "hello"
|
95
|
+
end
|
96
|
+
|
97
|
+
job :my_job2, user: "ec2-user", schedule: "* * * * *", content: <<-EOS
|
98
|
+
#!/bin/sh
|
99
|
+
echo hello
|
100
|
+
EOS
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
### User bundler
|
105
|
+
|
91
106
|
```ruby
|
92
107
|
on servers: :your_hostname do
|
93
108
|
job :my_job, user: "ec2-user", schedule: "* * * * *", bundle: 'ruby-mysql' do
|
@@ -97,11 +112,6 @@ on servers: :your_hostname do
|
|
97
112
|
p col1, col2
|
98
113
|
end
|
99
114
|
end
|
100
|
-
|
101
|
-
job :my_job2, user: "ec2-user", schedule: "* * * * *", content: <<-EOS
|
102
|
-
#!/bin/sh
|
103
|
-
echo hello
|
104
|
-
EOS
|
105
115
|
end
|
106
116
|
```
|
107
117
|
|
data/Vagrantfile
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
# vi: set ft=ruby :
|
3
3
|
VAGRANTFILE_API_VERSION = "2"
|
4
4
|
|
5
|
+
def set_aws_config(aws, override)
|
6
|
+
aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
|
7
|
+
aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
8
|
+
aws.keypair_name = ENV["EC2_KEYPAIR_NAME"]
|
9
|
+
aws.instance_type = "t1.micro"
|
10
|
+
aws.region = ENV["AWS_REGION"] || 'us-east-1'
|
11
|
+
aws.terminate_on_shutdown = true
|
12
|
+
|
13
|
+
override.ssh.private_key_path = ENV["EC2_PRIVATE_KEY_PATH"] || ENV["EC2_KEYPAIR_NAME"] + ".pem"
|
14
|
+
override.ssh.pty = true
|
15
|
+
override.vm.boot_timeout = 180
|
16
|
+
end
|
17
|
+
|
5
18
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
6
19
|
config.vm.box = "dummy"
|
7
20
|
config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
|
@@ -10,47 +23,29 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
10
23
|
|
11
24
|
config.vm.define :amazon_linux do |machine|
|
12
25
|
machine.vm.provider :aws do |aws, override|
|
13
|
-
aws
|
14
|
-
aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
15
|
-
aws.keypair_name = ENV["EC2_KEYPAIR_NAME"]
|
16
|
-
aws.instance_type = "m1.large"
|
17
|
-
aws.region = ENV["AWS_REGION"] || 'us-east-1'
|
18
|
-
aws.terminate_on_shutdown = true
|
19
|
-
aws.ami = ENV["AMAZON_LINUX_AMI"] || "ami-8e682ce6"
|
26
|
+
set_aws_config(aws, override)
|
20
27
|
|
28
|
+
aws.ami = ENV["AMAZON_LINUX_AMI"] || "ami-8e682ce6"
|
21
29
|
override.ssh.username = "ec2-user"
|
22
|
-
override.ssh.private_key_path = ENV["EC2_PRIVATE_KEY_PATH"] || ENV["EC2_KEYPAIR_NAME"] + ".pem"
|
23
|
-
override.ssh.pty = true
|
24
30
|
|
25
31
|
override.vm.provision "shell", inline: <<-SH
|
26
32
|
echo cronicle | passwd --stdin ec2-user
|
27
33
|
echo 'ec2-user ALL=(ALL) ALL' > /etc/sudoers.d/cloud-init
|
28
34
|
SH
|
29
|
-
|
30
|
-
override.vm.boot_timeout = 180
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
38
|
config.vm.define :ubuntu do |machine|
|
35
39
|
machine.vm.provider :aws do |aws, override|
|
36
|
-
aws
|
37
|
-
aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
38
|
-
aws.keypair_name = ENV["EC2_KEYPAIR_NAME"]
|
39
|
-
aws.instance_type = "m1.large"
|
40
|
-
aws.region = ENV["AWS_REGION"] || 'us-east-1'
|
41
|
-
aws.terminate_on_shutdown = true
|
42
|
-
aws.ami = ENV['UBUNTU_AMI'] || "ami-84562dec"
|
40
|
+
set_aws_config(aws, override)
|
43
41
|
|
42
|
+
aws.ami = ENV['UBUNTU_AMI'] || "ami-84562dec"
|
44
43
|
override.ssh.username = "ubuntu"
|
45
|
-
override.ssh.private_key_path = ENV["EC2_PRIVATE_KEY_PATH"] || ENV["EC2_KEYPAIR_NAME"] + ".pem"
|
46
|
-
override.ssh.pty = true
|
47
44
|
|
48
45
|
override.vm.provision "shell", inline: <<-SH
|
49
46
|
echo ubuntu:cronicle | chpasswd
|
50
47
|
echo 'ubuntu ALL=(ALL) ALL' > /etc/sudoers.d/90-cloud-init-users
|
51
48
|
SH
|
52
|
-
|
53
|
-
override.vm.boot_timeout = 180
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
@@ -30,7 +30,7 @@ class Cronicle::DSL::Context::Job
|
|
30
30
|
raise ArgumentError, "Job `#{name}`: :user is required"
|
31
31
|
end
|
32
32
|
|
33
|
-
opts.assert_valid_keys(:schedule, :user, :content, :bundle)
|
33
|
+
opts.assert_valid_keys(:schedule, :user, :content, :bundle, :locals, :header)
|
34
34
|
|
35
35
|
if opts[:content] and block
|
36
36
|
raise ArgumentError, 'Can not pass :content and block to `job` method'
|
@@ -38,6 +38,10 @@ class Cronicle::DSL::Context::Job
|
|
38
38
|
raise ArgumentError, "Job `#{name}`: :context or block is required"
|
39
39
|
end
|
40
40
|
|
41
|
+
unless opts[:locals].nil? or opts[:locals].kind_of?(Hash)
|
42
|
+
raise TypeError, "Job `#{name}`: :locals is wrong argument type (expected Hash)"
|
43
|
+
end
|
44
|
+
|
41
45
|
job_hash = @result[name][:job]
|
42
46
|
job_hash[:name] = name
|
43
47
|
job_hash[:user] = opts.fetch(:user).to_s
|
@@ -52,12 +56,20 @@ class Cronicle::DSL::Context::Job
|
|
52
56
|
source = block.to_raw_source(:strip_enclosure => true).each_line.to_a
|
53
57
|
source = source.shift + source.join.unindent
|
54
58
|
|
55
|
-
job_hash[:content] =
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
job_hash[:content] = "#!/usr/bin/env ruby\n"
|
60
|
+
|
61
|
+
opts.fetch(:locals, {}).each do |name, value|
|
62
|
+
job_hash[:content] << "#{name} = #{value.inspect}\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
job_hash[:content] << "#{source}\n"
|
59
66
|
else
|
60
67
|
job_hash[:content] = opts[:content].to_s.unindent
|
61
68
|
end
|
69
|
+
|
70
|
+
if opts[:header]
|
71
|
+
index = (job_hash[:content] =~ /^[^#]/) || 0
|
72
|
+
job_hash[:content].insert(index, "#{opts[:header]}\n")
|
73
|
+
end
|
62
74
|
end
|
63
75
|
end
|
data/lib/cronicle/version.rb
CHANGED
data/spec/cronicle_exec_spec.rb
CHANGED
@@ -210,4 +210,43 @@ describe 'Cronicle::Client#exec' do
|
|
210
210
|
EOS
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
context 'with locals/header' do
|
215
|
+
let(:jobfile) do
|
216
|
+
<<-RUBY.unindent
|
217
|
+
on servers: /amazon_linux/ do
|
218
|
+
job :foo, user: 'ec2-user', locals: {foo: 'BAR'} do
|
219
|
+
puts foo
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
on servers: /ubuntu/ do
|
224
|
+
job :foo, user: :ubuntu, header: 'FOO=100', content: <<-SH
|
225
|
+
#!/bin/sh
|
226
|
+
echo $FOO
|
227
|
+
SH
|
228
|
+
end
|
229
|
+
RUBY
|
230
|
+
end
|
231
|
+
|
232
|
+
before do
|
233
|
+
cronicle(:exec, :foo, logger: logger) { jobfile }
|
234
|
+
end
|
235
|
+
|
236
|
+
it do
|
237
|
+
expect(amzn_out).to eq <<-EOS.unindent
|
238
|
+
foo on amazon_linux/ec2-user> Execute job
|
239
|
+
foo on amazon_linux/ec2-user>\s
|
240
|
+
foo on amazon_linux/ec2-user> BAR
|
241
|
+
EOS
|
242
|
+
end
|
243
|
+
|
244
|
+
it do
|
245
|
+
expect(ubuntu_out).to eq <<-EOS.unindent
|
246
|
+
foo on ubuntu/ubuntu> Execute job
|
247
|
+
foo on ubuntu/ubuntu>\s
|
248
|
+
foo on ubuntu/ubuntu> 100
|
249
|
+
EOS
|
250
|
+
end
|
251
|
+
end
|
213
252
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -120,7 +120,7 @@ def cronicle(*args)
|
|
120
120
|
command = args.shift
|
121
121
|
options = args.last.kind_of?(Hash) ? args.pop : {}
|
122
122
|
|
123
|
-
tempfile(
|
123
|
+
tempfile(vagrant_ssh_config) do |ssh_config|
|
124
124
|
SSHKit::Backend::Netssh.configure do |ssh|
|
125
125
|
ssh.ssh_options = {:config => ssh_config.path}
|
126
126
|
end
|
@@ -134,6 +134,10 @@ def cronicle(*args)
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
def vagrant_ssh_config
|
138
|
+
@vagrant_ssh_config ||= `vagrant ssh-config`
|
139
|
+
end
|
140
|
+
|
137
141
|
def cronicle_client(options = {})
|
138
142
|
options = {
|
139
143
|
:sudo_password => 'cronicle'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronicle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sourcify
|