ami_spec 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 791efe6c0784b76689e581dd3d4172d9069471c81e1f06cf6a3671b2edb2e5c3
4
+ data.tar.gz: bb3c40ff9295d4dafc97cbc7ec6e54b5514d29a13cd39a17647b1170ee6d7839
5
+ SHA512:
6
+ metadata.gz: c82b27a4a85ac7fbdc3bac38bf4736d8675167349ffb41bf97deaa9358ae54fa2dea58e286c5ead916058266b3cddb5aca6c0fa0e24c1f4b0e1a0d4e2052ac00
7
+ data.tar.gz: 857dfa433808063a4a64c8dba5cc2e493f3f064e3a94b69565f28eb49a7a4cedd5950f83e09ad5ec784174c291d0f0ddc016fcd1b9ed07b4135da10a67fb3395
data/README.md CHANGED
@@ -29,32 +29,34 @@ Run `bundle install`
29
29
  ```cli
30
30
  $ bundle exec ami_spec --help
31
31
  Options:
32
- -r, --role=<s> The role to test, this should map to a directory in the spec folder
33
- -a, --ami=<s> The ami ID to run tests against
34
- -o, --role-ami-file=<s> A file containing comma separated roles and amis. i.e.
35
- web_server,ami-id.
36
- -s, --specs=<s> The directory to find ServerSpecs
37
- -u, --subnet-id=<s> The subnet to start the instance in
38
- -k, --key-name=<s> The SSH key name to assign to instances
39
- -e, --key-file=<s> The SSH private key file associated to the key_name
40
- -h, --ssh-user=<s> The user to ssh to the instance as
41
- -w, --aws-region=<s> The AWS region, defaults to AWS_DEFAULT_REGION environment variable
42
- -i, --aws-instance-type=<s> The ec2 instance type, defaults to t2.micro (default: t2.micro)
43
- -c, --aws-security-groups=<s+> Security groups to associate to the launched instances. May be specified
44
- multiple times
45
- -p, --aws-public-ip Launch instances with a public IP
46
- -t, --ssh-retries=<i> The number of times we should try sshing to the ec2 instance before
47
- giving up. Defaults to 30 (default: 30)
48
- -d, --debug Don't terminate instances on exit
49
- -l, --help Show this message
50
- $ bundle exec ami_spec \
51
- --role web_server \
52
- --ami ami-12345678 \
53
- --subnet-id subnet-abcdefgh \
54
- --key-name ec2-key-pair \
55
- --key-file ~/.ssh/ec2-key-pair.pem \
56
- --ssh-user ubuntu \
57
- --specs ./my_project/spec
32
+ -r, --role=<s> The role to test, this should map to a directory in the spec
33
+ folder
34
+ -a, --ami=<s> The ami ID to run tests against
35
+ -o, --role-ami-file=<s> A file containing comma separated roles and amis. i.e.
36
+ web_server,ami-id.
37
+ -s, --specs=<s> The directory to find ServerSpecs
38
+ -u, --subnet-id=<s> The subnet to start the instance in
39
+ -k, --key-name=<s> The SSH key name to assign to instances
40
+ -e, --key-file=<s> The SSH private key file associated to the key_name
41
+ -h, --ssh-user=<s> The user to ssh to the instance as
42
+ -w, --aws-region=<s> The AWS region, defaults to AWS_DEFAULT_REGION environment
43
+ variable
44
+ -i, --aws-instance-type=<s> The ec2 instance type, defaults to t2.micro (default:
45
+ t2.micro)
46
+ -c, --aws-security-groups=<s+> Security groups to associate to the launched instances. May be
47
+ specified multiple times
48
+ -p, --aws-public-ip Launch instances with a public IP
49
+ -t, --ssh-retries=<i> The number of times we should try sshing to the ec2 instance
50
+ before giving up. Defaults to 30 (default: 30)
51
+ -g, --tags=<s> Additional tags to add to launched instances in the form of
52
+ comma separated key=value pairs. i.e. Name=AmiSpec (default: )
53
+ -d, --debug Don't terminate instances on exit
54
+ -f, --wait-for-rc Wait for oldschool SystemV scripts to run before conducting
55
+ tests. Currently only supports Ubuntu with upstart
56
+ -l, --user-data-file=<s> File path for aws ec2 user data
57
+ -m, --iam-instance-profile-arn=<s> IAM instance profile to use
58
+ --help Show this message
59
+
58
60
  ```
59
61
 
60
62
  AmiSpec will launch an EC2 instance from the given AMI (`--ami`), in a subnet (`--subnet-id`) with a key-pair (`--key-name`)
@@ -40,6 +40,8 @@ module AmiSpec
40
40
  # Additional tags to add to launched instances in the form of comma separated key=value pairs
41
41
  # debug::
42
42
  # Don't terminate the instances on exit
43
+ # buildkite::
44
+ # Output section separators for buildkite
43
45
  # == Returns:
44
46
  # Boolean - The result of all the server specs.
45
47
  def self.run(options)
@@ -100,7 +102,10 @@ module AmiSpec
100
102
  type: :int, default: 30
101
103
  opt :tags, "Additional tags to add to launched instances in the form of comma separated key=value pairs. i.e. Name=AmiSpec", type: :string, default: ""
102
104
  opt :debug, "Don't terminate instances on exit"
105
+ opt :buildkite, "Output section separators for buildkite"
103
106
  opt :wait_for_rc, "Wait for oldschool SystemV scripts to run before conducting tests. Currently only supports Ubuntu with upstart"
107
+ opt :user_data_file, "File path for aws ec2 user data", type: :string
108
+ opt :iam_instance_profile_arn, "IAM instance profile to use", type: :string
104
109
  end
105
110
 
106
111
  if options[:role] && options[:ami]
@@ -116,6 +121,14 @@ module AmiSpec
116
121
  fail "You must specify either role and ami or role_ami_file"
117
122
  end
118
123
 
124
+ unless File.exist? options[:key_file]
125
+ fail "Key file #{options[:key_file]} not found"
126
+ end
127
+
128
+ unless options[:user_data_file] and File.exist? options[:user_data_file]
129
+ fail "User Data file #{options[:user_data_file]} not found"
130
+ end
131
+
119
132
  options[:tags] = parse_tags(options[:tags])
120
133
 
121
134
  exit run(options)
@@ -1,5 +1,6 @@
1
1
  require 'aws-sdk'
2
2
  require 'forwardable'
3
+ require 'base64'
3
4
 
4
5
  module AmiSpec
5
6
  class AwsInstance
@@ -21,6 +22,8 @@ module AmiSpec
21
22
  @region = options.fetch(:aws_region)
22
23
  @security_group_ids = options.fetch(:aws_security_groups)
23
24
  @tags = ec2ify_tags(options.fetch(:tags))
25
+ @user_data_file = options.fetch(:user_data_file, nil)
26
+ @iam_instance_profile_arn = options.fetch(:iam_instance_profile_arn, nil)
24
27
  end
25
28
 
26
29
  def_delegators :@instance, :instance_id, :tags, :terminate, :private_ip_address, :public_ip_address
@@ -58,6 +61,14 @@ module AmiSpec
58
61
  }]
59
62
  }
60
63
 
64
+ params[:user_data] = Base64.encode64(File.read(@user_data_file)) unless @user_data_file.nil?
65
+
66
+ unless @iam_instance_profile_arn.nil?
67
+ params[:iam_instance_profile] = {
68
+ arn: @iam_instance_profile_arn
69
+ }
70
+ end
71
+
61
72
  unless @security_group_ids.nil?
62
73
  params[:network_interfaces][0][:groups] = @security_group_ids
63
74
  end
@@ -13,5 +13,7 @@ module AmiSpec
13
13
  property :aws_region
14
14
  property :aws_security_groups
15
15
  property :tags
16
+ property :user_data_file
17
+ property :iam_instance_profile_arn
16
18
  end
17
19
  end
@@ -15,10 +15,17 @@ module AmiSpec
15
15
  @spec = options.fetch(:specs)
16
16
  @user = options.fetch(:ssh_user)
17
17
  @key_file = options.fetch(:key_file)
18
+ @buildkite = options.fetch(:buildkite)
19
+ @user_data_file = options.fetch(:user_data_file)
20
+ @iam_instance_profile_arn = options.fetch(:user_data_file)
18
21
  end
19
22
 
20
23
  def run
21
- puts "Running tests for #{@role}"
24
+ if @buildkite
25
+ puts "--- Running tests for #{@role}"
26
+ else
27
+ puts "Running tests for #{@role}"
28
+ end
22
29
 
23
30
  $LOAD_PATH.unshift(@spec) unless $LOAD_PATH.include?(@spec)
24
31
  require File.join(@spec, 'spec_helper')
@@ -38,6 +45,7 @@ module AmiSpec
38
45
 
39
46
  Specinfra::Backend::Ssh.clear
40
47
 
48
+ puts "^^^ +++" if @buildkite && !result.zero?
41
49
  result.zero?
42
50
  end
43
51
  end
@@ -10,5 +10,8 @@ module AmiSpec
10
10
  property :key_file
11
11
  property :specs
12
12
  property :ssh_user
13
+ property :buildkite
14
+ property :user_data_file
15
+ property :iam_instance_profile_arn
13
16
  end
14
17
  end
@@ -1,3 +1,3 @@
1
1
  module AmiSpec
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'base64'
3
+ require 'tempfile'
2
4
 
3
5
  describe AmiSpec::AwsInstance do
4
6
  let(:role) { 'web_server' }
@@ -8,6 +10,9 @@ describe AmiSpec::AwsInstance do
8
10
  let(:new_ec2_double) { instance_double(Aws::EC2::Types::Instance) }
9
11
  let(:ec2_double) { instance_double(Aws::EC2::Instance) }
10
12
  let(:tags) { {} }
13
+ let(:iam_instance_profile_arn) { nil }
14
+ let(:user_data_file) { nil }
15
+
11
16
  subject(:aws_instance) do
12
17
  described_class.new(
13
18
  role: role,
@@ -18,7 +23,9 @@ describe AmiSpec::AwsInstance do
18
23
  aws_public_ip: false,
19
24
  aws_security_groups: sec_group_id,
20
25
  aws_region: region,
21
- tags: tags
26
+ tags: tags,
27
+ user_data_file: user_data_file,
28
+ iam_instance_profile_arn: iam_instance_profile_arn
22
29
  )
23
30
  end
24
31
 
@@ -91,6 +98,33 @@ describe AmiSpec::AwsInstance do
91
98
  end
92
99
  end
93
100
 
101
+ context 'with user_data' do
102
+ let(:user_data_file) {
103
+ file = Tempfile.new('user_data.txt')
104
+ file.write("my file\ncontent")
105
+ file.close
106
+ file.path
107
+ }
108
+
109
+ it 'does include user_data' do
110
+ expect(client_double).to receive(:run_instances).with(
111
+ hash_including(:user_data => Base64.encode64("my file\ncontent"))
112
+ )
113
+ start
114
+ end
115
+ end
116
+
117
+ context 'with iam_instance_profile_arn' do
118
+ let(:iam_instance_profile_arn) { "my_arn" }
119
+
120
+ it 'does include iam_instance_profile_arn' do
121
+ expect(client_double).to receive(:run_instances).with(
122
+ hash_including(:iam_instance_profile => { arn: 'my_arn'})
123
+ )
124
+ start
125
+ end
126
+ end
127
+
94
128
  it 'tags the instance with a role' do
95
129
  expect(ec2_double).to receive(:create_tags).with(
96
130
  hash_including(tags: [{ key: 'AmiSpec', value: role}])
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ami_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Patrick Robinson
@@ -10,118 +9,104 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2016-09-15 00:00:00.000000000 Z
12
+ date: 2018-06-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: aws-sdk
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - "~>"
21
19
  - !ruby/object:Gem::Version
22
20
  version: '2'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ~>
25
+ - - "~>"
29
26
  - !ruby/object:Gem::Version
30
27
  version: '2'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ">="
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - ">="
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: serverspec
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - ">="
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: specinfra
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - ">="
69
61
  - !ruby/object:Gem::Version
70
62
  version: '2.45'
71
63
  type: :runtime
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - ">="
77
68
  - !ruby/object:Gem::Version
78
69
  version: '2.45'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: trollop
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - ">="
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :runtime
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - ">="
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: hashie
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - ">="
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :runtime
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - ">="
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: net-ssh
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - <
102
+ - - "<"
117
103
  - !ruby/object:Gem::Version
118
104
  version: '3.0'
119
105
  type: :runtime
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - <
109
+ - - "<"
125
110
  - !ruby/object:Gem::Version
126
111
  version: '3.0'
127
112
  description: Acceptance testing your AMIs
@@ -131,9 +116,9 @@ executables:
131
116
  extensions: []
132
117
  extra_rdoc_files: []
133
118
  files:
134
- - .gitignore
135
- - .ruby-version
136
- - .travis.yml
119
+ - ".gitignore"
120
+ - ".ruby-version"
121
+ - ".travis.yml"
137
122
  - Gemfile
138
123
  - LICENSE.txt
139
124
  - README.md
@@ -154,31 +139,29 @@ files:
154
139
  - spec/wait_for_ssh_spec.rb
155
140
  homepage: https://github.com/envato/ami-spec
156
141
  licenses: []
142
+ metadata: {}
157
143
  post_install_message:
158
144
  rdoc_options: []
159
145
  require_paths:
160
146
  - lib
161
147
  required_ruby_version: !ruby/object:Gem::Requirement
162
- none: false
163
148
  requirements:
164
- - - ! '>='
149
+ - - ">="
165
150
  - !ruby/object:Gem::Version
166
151
  version: '0'
167
152
  required_rubygems_version: !ruby/object:Gem::Requirement
168
- none: false
169
153
  requirements:
170
- - - ! '>='
154
+ - - ">="
171
155
  - !ruby/object:Gem::Version
172
156
  version: '0'
173
157
  requirements: []
174
158
  rubyforge_project:
175
- rubygems_version: 1.8.23.2
159
+ rubygems_version: 2.7.6
176
160
  signing_key:
177
- specification_version: 3
161
+ specification_version: 4
178
162
  summary: Acceptance testing your AMIs
179
163
  test_files:
180
164
  - spec/ami_spec_spec.rb
181
165
  - spec/aws_instance_spec.rb
182
166
  - spec/spec_helper.rb
183
167
  - spec/wait_for_ssh_spec.rb
184
- has_rdoc: