forger 1.5.2 → 1.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b27c0f4d04ea641ac7dc7be07704f21b7b36cace82c20e3d50764badbccb390
4
- data.tar.gz: adfdfb01b9500b142ec34fd9c3623bcb29c2e8994d05f33402e49f434a2ed780
3
+ metadata.gz: 76857772ac7cbd2c550b7506d1a2521abd062fa81db597cb3bb7668f4748d4e8
4
+ data.tar.gz: 1629ca2594868f7613be0cedfa8d0365f7be0c2944d22d6beb91f3723eccaa9b
5
5
  SHA512:
6
- metadata.gz: fc3040ab22124d40436638e283bf47f8e8442d55c3f5e4c6c804801c7b2827dccdaea3f24141fc2d09255398cb992b07089068f453dd0c3707d9b7fd3fa2d0e9
7
- data.tar.gz: 0f758fc77521872611434426a99afeca52745ab1e881daeed9f727673f23145fb1072e8f882b6c295d37c3064f1c0ed1cf9c7e2a55609829da09aac578f9e304
6
+ metadata.gz: 607c651c3253855fbaec49322962a49108c0c9861d2e84cc61c2a6dc611d21c3bd39b35ab132206b1713762982d5801a893ccaa091a8ea80d176e664bdfa7836
7
+ data.tar.gz: b1a1b5922611f071985aecaab00b56c0b36dcf1368b220056439a403d389006bece6cc17351b79a449b5d12c225a4583a126b3709463bb3356715990669c2c10
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.5.3]
7
+ - Merge pull request #9 from tongueroo/erb-support-for-config-env-files
8
+ - ERB support for config env files
9
+ - rename AWS_EC2 to FORGER
10
+
6
11
  ## [1.5.2]
7
12
  - add back user-data.txt script to cloudwatch
8
13
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- forger (1.5.1)
4
+ forger (1.5.2)
5
5
  activesupport
6
6
  aws-sdk-ec2
7
7
  aws-sdk-s3
data/README.md CHANGED
@@ -57,7 +57,7 @@ app/partials | Your partials that can to be included in other scripts. This is
57
57
  app/scripts | Where you define common scripts that can be used to configure the server. These scripts can be automatically uploaded to an s3 bucket for later downloading in your user-data script by setting the `s3_folder` settings option.
58
58
  app/user-data | Your user-data scripts that are used to bootstrap EC2 instance.
59
59
  app/user-data/layouts | user-data scripts support layouts. You user-data layouts go in here.
60
- config/[AWS_EC2_ENV].yml | The config file where you set configs that you want available in your templating logic. Examples are: `config/development.yml` and `config/production.yml`. You access the config variables with the `<%= config["var"] %>` helper.
60
+ config/[FORGER_ENV].yml | The config file where you set configs that you want available in your templating logic. Examples are: `config/development.yml` and `config/production.yml`. You access the config variables with the `<%= config["var"] %>` helper.
61
61
  profiles | Your profile files. These files mainly contain parameters that are passed to the aws-sdk run_instances API method.
62
62
  tmp | Where the generated scripts get compiled to. You can manually invoke the compilation via `forger compile` to inspect what is generated. This is automatically done as part of the `forger` create command.
63
63
 
@@ -8,8 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Forger::VERSION
9
9
  spec.authors = ["Tung Nguyen"]
10
10
  spec.email = ["tongueroo@gmail.com"]
11
- spec.description = %q{Simple tool to create AWS ec2 instances consistently with pre-configured settings}
12
- spec.summary = %q{Simple tool to create AWS ec2 instances}
11
+ spec.summary = "Tool to create AWS ec2 instances"
13
12
  spec.homepage = "https://github.com/tongueroo/forger"
14
13
  spec.license = "MIT"
15
14
 
@@ -1,7 +1,10 @@
1
1
  require 'yaml'
2
+ require 'render_me_pretty'
2
3
 
3
4
  module Forger
4
5
  class Config < Base
6
+ include Forger::Template
7
+
5
8
  def initialize(options={})
6
9
  super
7
10
  @path = options[:path] || "#{Forger.root}/config/#{Forger.env}.yml"
@@ -10,7 +13,9 @@ module Forger
10
13
  @@data = nil
11
14
  def data
12
15
  return @@data if @@data
13
- @@data = YAML.load_file(@path)
16
+
17
+ text = RenderMePretty.result(@path, context: context)
18
+ @@data = YAML.load(text)
14
19
  rescue Errno::ENOENT => e
15
20
  puts e.message
16
21
  puts "The #{@path} does not exist. Please double check that it exists."
@@ -13,7 +13,7 @@ module Forger
13
13
  end
14
14
 
15
15
  def root
16
- path = ENV['AWS_EC2_ROOT'] || '.'
16
+ path = ENV['FORGER_ROOT'] || '.'
17
17
  Pathname.new(path)
18
18
  end
19
19
 
@@ -28,7 +28,7 @@ module Forger
28
28
  def env
29
29
  return @@env if @@env
30
30
  env = env_from_profile(ENV['AWS_PROFILE']) || 'development'
31
- env = ENV['AWS_EC2_ENV'] if ENV['AWS_EC2_ENV'] # highest precedence
31
+ env = ENV['FORGER_ENV'] if ENV['FORGER_ENV'] # highest precedence
32
32
  @@env = env
33
33
  end
34
34
 
@@ -90,22 +90,22 @@ module Forger
90
90
  def display_cloudwatch_info(instance_id)
91
91
  return unless @options[:cloudwatch]
92
92
 
93
- region = get_region
93
+ region = cloudwatch_log_region
94
94
  stream = "#{instance_id}/var/log/cloud-init-output.log"
95
95
  url = "https://#{region}.console.aws.amazon.com/cloudwatch/home?region=#{region}#logEventViewer:group=ec2;stream=#{stream}"
96
96
  cw_init_log = "cw tail -f ec2 #{stream}"
97
97
  puts "To view instance's cloudwatch logs visit:"
98
98
  puts " #{url}"
99
99
 
100
- puts " #{cw_init_log}" if ENV['AWS_EC2_CW']
101
- if ENV['AWS_EC2_CW'] && @options[:auto_terminate]
100
+ puts " #{cw_init_log}" if ENV['FORGER_CW']
101
+ if ENV['FORGER_CW'] && @options[:auto_terminate]
102
102
  cw_terminate_log = "cw tail -f ec2 #{instance_id}/var/log/auto-terminate.log"
103
103
  puts " #{cw_terminate_log}"
104
104
  end
105
105
 
106
106
  puts "Note: It takes a little time for the instance to launch and report logs."
107
107
 
108
- paste_command = ENV['AWS_EC2_CW'] ? cw_init_log : url
108
+ paste_command = ENV['FORGER_CW'] ? cw_init_log : url
109
109
  add_to_clipboard(paste_command)
110
110
  end
111
111
 
@@ -117,10 +117,15 @@ module Forger
117
117
  puts "Pro tip: The CloudWatch Console Link has been added to your copy-and-paste clipboard."
118
118
  end
119
119
 
120
- def get_region
121
- # Highest precedence: AWS_EC2_REGION env variable. Only really used here.
122
- if ENV['AWS_EC2_REGION']
123
- return ENV['AWS_EC2_REGION']
120
+ def cloudwatch_log_region
121
+ # Highest precedence: FORGER_REGION env variable. Only really used here.
122
+ # This is useful to be able to override when running tool in codebuild.
123
+ # Codebuild can be running in different region then the region which the
124
+ # instance is launched in.
125
+ # Getting the region from the the profile and metadata doesnt work in
126
+ # this case.
127
+ if ENV['FORGER_REGION']
128
+ return ENV['FORGER_REGION']
124
129
  end
125
130
 
126
131
  # Pretty high in precedence: AWS_PROFILE and ~/.aws/config and
@@ -24,7 +24,7 @@ class Forger::Dotenv
24
24
  end
25
25
 
26
26
  def root
27
- Forger.root || Pathname.new(ENV["AWS_EC2_ROOT"] || Dir.pwd)
27
+ Forger.root || Pathname.new(ENV["FORGER_ROOT"] || Dir.pwd)
28
28
  end
29
29
  end
30
30
  end
@@ -29,7 +29,8 @@ module Forger
29
29
  def create_ami
30
30
  # set variables for the template
31
31
  @ami_name = @options[:ami_name]
32
- @region = `aws configure get region`.strip rescue 'us-east-1'
32
+ @region = 'us-east-1' if ENV['TEST']
33
+ @region ||= `aws configure get region`.strip rescue 'us-east-1'
33
34
  load_template("ami_creation.sh")
34
35
  end
35
36
 
@@ -21,13 +21,13 @@ function extract_forger_scripts() {
21
21
 
22
22
  <%
23
23
  # Examples:
24
- # AWS_EC2_CODE=v1.0.0
25
- # AWS_EC2_CODE=master
26
- # AWS_EC2_CODE=branch-name
24
+ # FORGER_CODE=v1.0.0
25
+ # FORGER_CODE=master
26
+ # FORGER_CODE=branch-name
27
27
  #
28
28
  # https://github.com/tongueroo/forger/archive/v1.0.0.tar.gz
29
29
  # https://github.com/tongueroo/forger/archive/master.tar.gz
30
- code_version = ENV['AWS_EC2_CODE']
30
+ code_version = ENV['FORGER_CODE']
31
31
  code_version ||= "v#{Forger::VERSION}"
32
32
  %>
33
33
  url="https://github.com/tongueroo/forger/archive/<%= code_version %>.tar.gz"
@@ -18,10 +18,10 @@ module Forger::Template
18
18
  filename = path.sub(%r{.*/},'').sub('.rb','')
19
19
  module_name = filename.classify
20
20
 
21
- # Prepend a period so require works AWS_EC2_ROOT is set to a relative path
21
+ # Prepend a period so require works FORGER_ROOT is set to a relative path
22
22
  # without a period.
23
23
  #
24
- # Example: AWS_EC2_ROOT=tmp/project
24
+ # Example: FORGER_ROOT=tmp/project
25
25
  first_char = path[0..0]
26
26
  path = "./#{path}" unless %w[. /].include?(first_char)
27
27
  require path
@@ -58,8 +58,8 @@ module Forger::Template::Helper::CoreHelper
58
58
  end
59
59
 
60
60
  # provides access to config/* settings as variables
61
- # AWS_EC2_ENV=development => config/development.yml
62
- # AWS_EC2_ENV=production => config/production.yml
61
+ # FORGER_ENV=development => config/development.yml
62
+ # FORGER_ENV=production => config/production.yml
63
63
  def config
64
64
  Forger.config
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Forger
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.3"
3
3
  end
@@ -0,0 +1,2 @@
1
+ IAM_INSTANCE_PROFILE=test-iam-profile
2
+ TEST_KEY=test-key-value
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -exu
2
+
3
+ # test env variables from config/[ENV].yml file
4
+ # test_key: <%= config["test_key"] %>
@@ -5,3 +5,4 @@ subnets:
5
5
  security_group_ids:
6
6
  - sg-123 # test-single-instance
7
7
  s3_bucket: my-bucket # for the user-data shared scripts
8
+ test_key: <%= ENV['TEST_KEY'] %>
@@ -6,9 +6,9 @@ instance_type: t2.medium
6
6
  key_name: default
7
7
  max_count: 1
8
8
  min_count: 1
9
- user_data:
9
+ user_data: "<%= user_data("bootstrap.sh") %>"
10
10
  iam_instance_profile:
11
- name: DevLinux
11
+ name: <%= ENV['IAM_INSTANCE_PROFILE'] %>
12
12
  # public network settings
13
13
  security_group_ids: <%= config["security_group_ids"].inspect %>
14
14
  subnet_id: <%= config["subnets"].shuffle.first %>
@@ -9,6 +9,13 @@ describe Forger::CLI do
9
9
  expect(out).to include("Creating EC2 instance")
10
10
  end
11
11
 
12
+ it "ERB evaluates dotenv files" do
13
+ out = execute("exe/forger create server #{@args}")
14
+ user_data = IO.readlines("spec/fixtures/demo_project/tmp/user-data.txt")
15
+ found = !user_data.select { |l| l =~ /test_key: test-key-value/ }.empty?
16
+ expect(found).to be true
17
+ end
18
+
12
19
  it "ami" do
13
20
  out = execute("exe/forger ami myimage #{@args}")
14
21
  expect(out).to include("Creating EC2 instance")
@@ -1,6 +1,6 @@
1
1
  ENV["TEST"] = "1"
2
- ENV["AWS_EC2_ENV"] = "test"
3
- ENV["AWS_EC2_ROOT"] = "spec/fixtures/demo_project"
2
+ ENV["FORGER_ENV"] = "test"
3
+ ENV["FORGER_ROOT"] = "spec/fixtures/demo_project"
4
4
  # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
5
5
  ENV['HOME'] = "spec/fixtures/home"
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -220,8 +220,7 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
- description: Simple tool to create AWS ec2 instances consistently with pre-configured
224
- settings
223
+ description:
225
224
  email:
226
225
  - tongueroo@gmail.com
227
226
  executables:
@@ -315,6 +314,8 @@ files:
315
314
  - lib/forger/wait.rb
316
315
  - lib/forger/waiter.rb
317
316
  - lib/forger/waiter/ami.rb
317
+ - spec/fixtures/demo_project/.env.test
318
+ - spec/fixtures/demo_project/app/user-data/bootstrap.sh
318
319
  - spec/fixtures/demo_project/config/settings.yml
319
320
  - spec/fixtures/demo_project/config/test.yml
320
321
  - spec/fixtures/demo_project/profiles/default.yml
@@ -344,8 +345,10 @@ rubyforge_project:
344
345
  rubygems_version: 2.7.3
345
346
  signing_key:
346
347
  specification_version: 4
347
- summary: Simple tool to create AWS ec2 instances
348
+ summary: Tool to create AWS ec2 instances
348
349
  test_files:
350
+ - spec/fixtures/demo_project/.env.test
351
+ - spec/fixtures/demo_project/app/user-data/bootstrap.sh
349
352
  - spec/fixtures/demo_project/config/settings.yml
350
353
  - spec/fixtures/demo_project/config/test.yml
351
354
  - spec/fixtures/demo_project/profiles/default.yml