forger 2.0.5 → 3.0.0

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -0
  3. data/CHANGELOG.md +12 -0
  4. data/Gemfile.lock +40 -29
  5. data/README.md +6 -37
  6. data/docs/example/config/variables/development.rb +2 -0
  7. data/docs/example/profiles/default.yml +2 -2
  8. data/docs/extract-scripts.md +40 -0
  9. data/docs/layouts.md +35 -0
  10. data/docs/profiles.md +79 -0
  11. data/docs/variables.md +53 -0
  12. data/forger.gemspec +6 -3
  13. data/lib/forger.rb +4 -23
  14. data/lib/forger/autoloader.rb +21 -0
  15. data/lib/forger/aws_services.rb +22 -0
  16. data/lib/forger/clean.rb +0 -2
  17. data/lib/forger/cleaner.rb +0 -1
  18. data/lib/forger/cleaner/ami.rb +1 -1
  19. data/lib/forger/cli.rb +10 -6
  20. data/lib/forger/completer.rb +0 -2
  21. data/lib/forger/core.rb +28 -12
  22. data/lib/forger/create.rb +2 -23
  23. data/lib/forger/create/info.rb +10 -4
  24. data/lib/forger/create/waiter.rb +1 -1
  25. data/lib/forger/destroy.rb +1 -1
  26. data/lib/forger/help/upload.md +1 -13
  27. data/lib/forger/network.rb +2 -2
  28. data/lib/forger/new.rb +5 -6
  29. data/lib/forger/profile.rb +15 -3
  30. data/lib/forger/s3.rb +23 -0
  31. data/lib/forger/s3/bucket.rb +131 -0
  32. data/lib/forger/script.rb +0 -4
  33. data/lib/forger/script/upload.rb +12 -42
  34. data/lib/forger/scripts/cloudwatch.sh +2 -2
  35. data/lib/forger/scripts/shared/functions.sh +1 -1
  36. data/lib/forger/setting.rb +0 -32
  37. data/lib/forger/template.rb +0 -3
  38. data/lib/forger/template/context.rb +16 -1
  39. data/lib/forger/template/helper.rb +9 -9
  40. data/lib/forger/template/helper/ami_helper.rb +1 -1
  41. data/lib/forger/template/helper/core_helper.rb +7 -6
  42. data/lib/forger/template/helper/script_helper.rb +3 -9
  43. data/lib/forger/version.rb +1 -1
  44. data/lib/forger/wait.rb +0 -2
  45. data/lib/forger/waiter.rb +0 -1
  46. data/lib/forger/waiter/ami.rb +1 -1
  47. data/lib/templates/default/app/user_data/bootstrap.sh.tt +6 -9
  48. data/lib/templates/default/app/user_data/layouts/default.sh.tt +1 -5
  49. data/lib/templates/default/config/settings.yml.tt +1 -11
  50. data/lib/templates/default/config/{development.yml.tt → variables/development.yml.tt} +0 -0
  51. data/spec/fixtures/demo_project/app/user_data/bootstrap.sh +2 -2
  52. data/spec/fixtures/demo_project/config/settings.yml +2 -4
  53. data/spec/fixtures/demo_project/config/variables/test.rb +4 -0
  54. data/spec/fixtures/demo_project/profiles/default.yml +2 -2
  55. metadata +59 -13
  56. data/docs/example/config/development.yml +0 -7
  57. data/lib/forger/aws_service.rb +0 -7
  58. data/lib/forger/config.rb +0 -25
  59. data/spec/fixtures/demo_project/config/test.yml +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24b35480802991ec9af7a567180f74723adabcf858c5b4ddcc6fc14a3944d7f7
4
- data.tar.gz: 046b74aae0f9b3d7cdeefbcaabd6409f0485cb2974c111667e6e03b26f2e473c
3
+ metadata.gz: c6a2c42b3903e698ada5e5ea866c96132f5de9013ab48e6a3ebab3164ef376a2
4
+ data.tar.gz: 8aee63e946e05d816eb6978d9ce3b504a50f8ae413287d181d2cf05717020078
5
5
  SHA512:
6
- metadata.gz: fb5996ebc2e3059ff16f6ffb4487be82c2348495167479c834de6f33550b282995a717ecfa67ebd739b1773b61e6c231e0744c3b3546fe6c54ddcd9959773f19
7
- data.tar.gz: da660ea8453c5905d74507a19a34e9243610d943e60fcacc2f3abcc341141926abf5c3dabdbe9ebc7b0eaae0cc5a8d952bc86e4d0b44c01a32b4026110c244f4
6
+ metadata.gz: 3c8acac50ce6b424cb2dfe29069cb92b774903b8ff6d7eb07ab043a98c82ad916d8f610841f9ad1ecd18b39829903d259221f588b726bc8d80d867a9e81f80f0
7
+ data.tar.gz: 90bfbe3f61a0f05a0ac893b0250678204b25c0be844ef300f2c2d0be3df849512beac1708729fe857c4b7382310922d8e4d3c7730c73f52e201d370949a55efa
@@ -32,6 +32,7 @@ jobs:
32
32
  - run:
33
33
  name: install dependencies
34
34
  command: |
35
+ sed -i '/BUNDLED WITH/Q' Gemfile.lock # hack to fix bundler issue: allow different versions of bundler to work
35
36
  bundle install --jobs=4 --retry=3 --path vendor/bundle
36
37
 
37
38
  # - save_cache:
@@ -3,6 +3,18 @@
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
+ ## [3.0.0]
7
+ * there are some breaking changes with this release
8
+ * automatically created a forger managed s3 bucket when extract_scripts usage detected
9
+ * `config/variables` support instead of `config/FORGER_ENV.yml` files
10
+ * variables definitions are Ruby instead of YAML
11
+ * removed config helper. use instance variables directly.
12
+ * introduced base.yml profile concept
13
+ * fix os_name and cloudwatch logging for amzn2
14
+ * cleanup: remove vars helper
15
+ * use zeitwerk for autoloading
16
+ * change aws\_profiles option to aws\_profile
17
+
6
18
  ## [2.0.5]
7
19
  - add circle config: circleci 2.0
8
20
  - use rainbow gem for terminal colors
@@ -3,8 +3,10 @@ PATH
3
3
  specs:
4
4
  forger (2.0.5)
5
5
  activesupport
6
+ aws-sdk-cloudformation
6
7
  aws-sdk-ec2
7
8
  aws-sdk-s3
9
+ cfn-status
8
10
  dotenv
9
11
  filesize
10
12
  hashie
@@ -12,39 +14,47 @@ PATH
12
14
  rainbow
13
15
  render_me_pretty
14
16
  thor
17
+ zeitwerk
15
18
 
16
19
  GEM
17
20
  remote: https://rubygems.org/
18
21
  specs:
19
- activesupport (5.2.2)
22
+ activesupport (6.0.0)
20
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
24
  i18n (>= 0.7, < 2)
22
25
  minitest (~> 5.1)
23
26
  tzinfo (~> 1.1)
24
- aws-eventstream (1.0.1)
25
- aws-partitions (1.135.0)
26
- aws-sdk-core (3.46.0)
27
- aws-eventstream (~> 1.0)
27
+ zeitwerk (~> 2.1, >= 2.1.8)
28
+ aws-eventstream (1.0.3)
29
+ aws-partitions (1.207.0)
30
+ aws-sdk-cloudformation (1.25.0)
31
+ aws-sdk-core (~> 3, >= 3.61.1)
32
+ aws-sigv4 (~> 1.1)
33
+ aws-sdk-core (3.65.1)
34
+ aws-eventstream (~> 1.0, >= 1.0.2)
28
35
  aws-partitions (~> 1.0)
29
- aws-sigv4 (~> 1.0)
36
+ aws-sigv4 (~> 1.1)
30
37
  jmespath (~> 1.0)
31
- aws-sdk-ec2 (1.67.0)
32
- aws-sdk-core (~> 3, >= 3.39.0)
33
- aws-sigv4 (~> 1.0)
34
- aws-sdk-kms (1.13.0)
35
- aws-sdk-core (~> 3, >= 3.39.0)
36
- aws-sigv4 (~> 1.0)
37
- aws-sdk-s3 (1.30.1)
38
- aws-sdk-core (~> 3, >= 3.39.0)
38
+ aws-sdk-ec2 (1.106.0)
39
+ aws-sdk-core (~> 3, >= 3.61.1)
40
+ aws-sigv4 (~> 1.1)
41
+ aws-sdk-kms (1.24.0)
42
+ aws-sdk-core (~> 3, >= 3.61.1)
43
+ aws-sigv4 (~> 1.1)
44
+ aws-sdk-s3 (1.48.0)
45
+ aws-sdk-core (~> 3, >= 3.61.1)
39
46
  aws-sdk-kms (~> 1)
40
- aws-sigv4 (~> 1.0)
41
- aws-sigv4 (1.0.3)
42
- byebug (10.0.2)
47
+ aws-sigv4 (~> 1.1)
48
+ aws-sigv4 (1.1.0)
49
+ aws-eventstream (~> 1.0, >= 1.0.2)
50
+ byebug (11.0.1)
51
+ cfn-status (0.2.0)
52
+ aws-sdk-cloudformation
43
53
  coderay (1.1.2)
44
- concurrent-ruby (1.1.4)
54
+ concurrent-ruby (1.1.5)
45
55
  diff-lcs (1.3)
46
- dotenv (2.6.0)
47
- ffi (1.10.0)
56
+ dotenv (2.7.5)
57
+ ffi (1.11.1)
48
58
  filesize (0.2.0)
49
59
  formatador (0.2.5)
50
60
  guard (2.15.0)
@@ -66,7 +76,7 @@ GEM
66
76
  guard-compat (~> 1.1)
67
77
  rspec (>= 2.99.0, < 4.0)
68
78
  hashie (3.6.0)
69
- i18n (1.5.3)
79
+ i18n (1.6.0)
70
80
  concurrent-ruby (~> 1.0)
71
81
  jmespath (1.4.0)
72
82
  listen (3.1.5)
@@ -78,18 +88,18 @@ GEM
78
88
  method_source (0.9.2)
79
89
  minitest (5.11.3)
80
90
  nenv (0.3.0)
81
- notiffany (0.1.1)
91
+ notiffany (0.1.3)
82
92
  nenv (~> 0.1)
83
93
  shellany (~> 0.0)
84
94
  pry (0.12.2)
85
95
  coderay (~> 1.1.0)
86
96
  method_source (~> 0.9.0)
87
97
  rainbow (3.0.0)
88
- rake (12.3.2)
98
+ rake (12.3.3)
89
99
  rb-fsevent (0.10.3)
90
100
  rb-inotify (0.10.0)
91
101
  ffi (~> 1.0)
92
- render_me_pretty (0.8.2)
102
+ render_me_pretty (0.8.3)
93
103
  activesupport
94
104
  rainbow
95
105
  tilt
@@ -97,15 +107,15 @@ GEM
97
107
  rspec-core (~> 3.8.0)
98
108
  rspec-expectations (~> 3.8.0)
99
109
  rspec-mocks (~> 3.8.0)
100
- rspec-core (3.8.0)
110
+ rspec-core (3.8.2)
101
111
  rspec-support (~> 3.8.0)
102
- rspec-expectations (3.8.2)
112
+ rspec-expectations (3.8.4)
103
113
  diff-lcs (>= 1.2.0, < 2.0)
104
114
  rspec-support (~> 3.8.0)
105
- rspec-mocks (3.8.0)
115
+ rspec-mocks (3.8.1)
106
116
  diff-lcs (>= 1.2.0, < 2.0)
107
117
  rspec-support (~> 3.8.0)
108
- rspec-support (3.8.0)
118
+ rspec-support (3.8.2)
109
119
  ruby_dep (1.5.0)
110
120
  shellany (0.0.1)
111
121
  thor (0.20.3)
@@ -113,6 +123,7 @@ GEM
113
123
  tilt (2.0.9)
114
124
  tzinfo (1.2.5)
115
125
  thread_safe (~> 0.1)
126
+ zeitwerk (2.1.9)
116
127
 
117
128
  PLATFORMS
118
129
  ruby
@@ -127,4 +138,4 @@ DEPENDENCIES
127
138
  rake
128
139
 
129
140
  BUNDLED WITH
130
- 1.17.2
141
+ 2.0.2
data/README.md CHANGED
@@ -65,7 +65,7 @@ app/partials | Your partials that can to be included in other scripts. This is
65
65
  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.
66
66
  app/user_data | Your user-data scripts that are used to bootstrap EC2 instance.
67
67
  app/user_data/layouts | user-data scripts support layouts. You user-data layouts go in here.
68
- 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.
68
+ config/[FORGER_ENV].yml | The config file where you set configs that you want available in your templating logic. Examples are: `config/variables/development.rb` and `config/variables/production.rb`. You access the config variables with ERB `<%= @var %>`.
69
69
  profiles | Your profile files. These files mainly contain parameters that are passed to the aws-sdk run_instances API method.
70
70
  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.
71
71
 
@@ -76,7 +76,7 @@ You can use ERB in the profile files. Some useful helper methods are documented
76
76
  Helper | Description
77
77
  ------------- | -------------
78
78
  user_data | Allows you to embed a generated user_data script. More details on the user-data are provided in the user data section below.
79
- config | Access to the variables set in config/[AWS\_EC2\_ENV].yml. Examples are `config/development.yml` and `config/production.yml`.
79
+ config | Access to the variables set in config/[AWS\_EC2\_ENV].yml. Examples are `config/variables/development.rb` and `config/variables/production.rb`.
80
80
  latest_ami | Returns an AMI id by searching the AMI name pattern and sorting in reverse order. Example: `latest_ami("ruby-2.5.0_*")` would return the latest ruby AMIs are named with timestamps at the end like so: `ruby-2.5.0_2018-01-30-05-36-02` and `ruby-2.5.0_2018-01-29-05-36-02`.
81
81
  search_ami | Returns a collection of AMI image objects based on a search pattern. The query searches on the AMI name.
82
82
  extract_scripts | Use this in your bash script to extract the `app/scripts` files that get uploaded to s3.
@@ -107,42 +107,11 @@ To use the user-data script when creating an EC2 instance, use the `user_data` h
107
107
 
108
108
  ### User-Data Layouts
109
109
 
110
- User-data scripts support layouts. This is useful if you have common setup and finish code with your user-data scripts. Here's an example: `app/user_data/layouts/default.sh`:
111
-
112
- ```bash
113
- #!/bin/bash
114
- # do some setup
115
- <%= yield %>
116
- # finish work
117
- ```
118
-
119
- And `app/user_data/box.sh`:
120
-
121
- yum install -y vim
122
-
123
- The resulting generated user-data script will be:
124
-
125
- ```bash
126
- #!/bin/bash
127
- # do some setup
128
- yum install -y vim
129
- # finish work
130
- ```
131
-
132
- You can specify the layout to use when you call the `user_data` helper method in your profile. Example: `profiles/box.yml`:
133
-
134
- ```yaml
135
- ---
136
- ...
137
- user_data: <%= user_data("box.sh", layout: "mylayout" ) %>
138
- ...
139
- ```
140
-
141
- If there's a `layouts/default.sh`, then it will automatically be used without having to specify the layout option. You can disable this behavior by passing in `layout: false` or by deleting the `layouts/default.sh` file.
110
+ Refer to [docs/layouts.md](docs/layouts.md)
142
111
 
143
112
  ### Config
144
113
 
145
- You can set variables in a config file and they are available when ERB is available: profiles, user-data, scripts, etc. Example `config/development.yml`:
114
+ You can set variables in a config file and they are available when ERB is available: profiles, user-data, scripts, etc. Example `config/variables/development.rb`:
146
115
 
147
116
  ```yaml
148
117
  ---
@@ -159,8 +128,8 @@ The variables are accessed via the `config` helper method. Here's a filtered exa
159
128
  ```yaml
160
129
  image_id: ami-4fffc834 # Amazon Lambda AMI
161
130
  instance_type: t2.medium
162
- security_group_ids: <%= config["security_group_ids"] %>
163
- subnet_id: <%= config["subnets"].shuffle %>
131
+ security_group_ids: <%= @security_group_ids %>
132
+ subnet_id: <%= @subnets.shuffle %>
164
133
  ...
165
134
  ```
166
135
 
@@ -0,0 +1,2 @@
1
+ @subnets = %w[subnet-111 subnet-222 subnet-333]
2
+ @security_group_ids = %w[sg-111]
@@ -4,8 +4,8 @@ instance_type: t2.medium
4
4
  key_name: default
5
5
  max_count: 1
6
6
  min_count: 1
7
- security_group_ids: <%= config["security_group_ids"] %>
8
- subnet_id: <%= config["subnets"].shuffle.first %>
7
+ security_group_ids: <%= @security_group_ids %>
8
+ subnet_id: <%= @subnets.shuffle.first %>
9
9
  user_data: "<%= user_data("bootstrap") %>"
10
10
  iam_instance_profile:
11
11
  name: IAMProfileName
@@ -0,0 +1,40 @@
1
+ # Extract Scripts
2
+
3
+ ## Overview
4
+
5
+ Forger supports uploading files to s3 and making them available to your the launched EC2 instances.
6
+
7
+ ## How it works
8
+
9
+ 1. Add your scripts to the `app/scripts` folder.
10
+ 2. In your user data script you called the helper method: `extract_scripts`
11
+
12
+ The `extract_scripts` in the user_data script can look something like this:
13
+
14
+ app/user_data/bootstrap.sh:
15
+
16
+ #!/bin/bash
17
+
18
+ <%= extract_scripts(to: "/opt") %>
19
+
20
+ The generates `extract_scripts` helper, generates a snippet of bash that looks something like this:
21
+
22
+ mkdir -p /opt
23
+ aws s3 cp s3://forger-bucket-EXAMPLE/development/scripts/scripts-md5.tgz /opt/
24
+ (
25
+ cd /opt
26
+ rm -rf /opt/scripts
27
+ tar zxf /opt/scripts-md5.tgz
28
+ chmod -R a+x /opt/scripts
29
+ chown -R ec2-user:ec2-user /opt/scripts
30
+ )
31
+
32
+ It essentially extracts the scripts from the `app/scripts` to `/opt/scripts`.
33
+
34
+ ## ERB Support
35
+
36
+ You can use ERB in the `app/scripts` files. So you can add dynamic logic based on ENV variables.
37
+
38
+ ## S3 Bucket
39
+
40
+ Forger will automatically create the s3 bucket as needed. The s3 bucket is defined in the `forger` CloudFormation stack.
@@ -0,0 +1,35 @@
1
+ # User Data Layouts
2
+
3
+ User-data scripts support layouts. This is useful if you have common setup and finish code with your user-data scripts. Here's an example: `app/user_data/layouts/default.sh`:
4
+
5
+ ```bash
6
+ #!/bin/bash
7
+ # do some setup
8
+ <%= yield %>
9
+ # finish work
10
+ ```
11
+
12
+ And `app/user_data/box.sh`:
13
+
14
+ yum install -y vim
15
+
16
+ The resulting generated user-data script will be:
17
+
18
+ ```bash
19
+ #!/bin/bash
20
+ # do some setup
21
+ yum install -y vim
22
+ # finish work
23
+ ```
24
+
25
+ You can specify the layout to use when you call the `user_data` helper method in your profile. Example: `profiles/box.yml`:
26
+
27
+ ```yaml
28
+ ---
29
+ ...
30
+ user_data: <%= user_data("box.sh", layout: "mylayout" ) %>
31
+ ...
32
+ ```
33
+
34
+ If there's a `layouts/default.sh`, then it will automatically be used without having to specify the layout option. You can disable this behavior by passing in `layout: false` or by deleting the `layouts/default.sh` file.
35
+
@@ -0,0 +1,79 @@
1
+ # Profiles
2
+
3
+ ## Overview
4
+
5
+ The `profiles` files are YAML files that set the parameters passed to the `ec2.run_instances` API call. Example:
6
+
7
+ `profiles/box.yml`:
8
+
9
+ ```yaml
10
+ ---
11
+ image_id: ami-97785bed
12
+ instance_type: t2.medium
13
+ key_name: default
14
+ max_count: 1
15
+ min_count: 1
16
+ security_group_ids: <%= @security_group_ids %>
17
+ subnet_id: <%= @subnets.shuffle.first %>
18
+ user_data: "<%= user_data("bootstrap") %>"
19
+ iam_instance_profile:
20
+ name: IAMProfileName
21
+ ```
22
+
23
+ The forger call to create the ec2 instance would be:
24
+
25
+ forger create box
26
+
27
+ ## Base Profile
28
+
29
+ If you have multiple profiles with a common base, you can create a `profiles/base.yml` file which will have the shared settings. Example structure:
30
+
31
+ profiles
32
+ ├── base.yml
33
+ ├── box.yml
34
+ └── test.yml
35
+
36
+ The `base.yml` gets merged with `box.yml`.
37
+ The `base.yml` also gets merged with `test.yml`.
38
+
39
+ ### Examples
40
+
41
+ profiles/base.yml:
42
+
43
+ ```yaml
44
+ ---
45
+ instance_type: t2.medium
46
+ key_name: default
47
+ max_count: 1
48
+ min_count: 1
49
+ security_group_ids: <%= @security_group_ids %>
50
+ subnet_id: <%= @subnets.shuffle.first %>
51
+ iam_instance_profile:
52
+ name: IAMProfileName
53
+ ```
54
+
55
+ profiles/box.yml:
56
+
57
+ ```yaml
58
+ ---
59
+ image_id: ami-1111111
60
+ user_data: "<%= user_data("box") %>"
61
+ ```
62
+
63
+ profiles/test.yml:
64
+
65
+ ```yaml
66
+ ---
67
+ image_id: ami-2222222
68
+ user_data: "<%= user_data("test") %>"
69
+ ```
70
+
71
+ ## Profile Conventions
72
+
73
+ By convention the profile file will be same as the name to you pass to the the `forger create NAME`. So
74
+
75
+ forger create box
76
+
77
+ Automatically matches to the `profiles/box.yml`. If you need to override the convention you can use the `--profile` option. Example:
78
+
79
+ forger create box-2 --profile box
@@ -0,0 +1,53 @@
1
+ # Variables
2
+
3
+ ## Overview
4
+
5
+ You can create variables that are accessible in the `app/scripts` and `profiles` files. You define the variables in the `config/variables/FORGER_ENV.rb` files.
6
+
7
+ ## Structure
8
+
9
+ config
10
+ └── variables
11
+ ├── base.rb
12
+ ├── development.rb
13
+ └── production.rb
14
+
15
+ ## Variable Definitions
16
+
17
+ Examples of variables definitions:
18
+
19
+ config/variables/base.rb:
20
+
21
+ ```ruby
22
+ @keypair = "my-keypair-1"
23
+ ```
24
+
25
+ config/variables/development.rb:
26
+
27
+ ```ruby
28
+ ---
29
+ instance_type: t2.medium
30
+ key_name: default
31
+ max_count: 1
32
+ min_count: 1
33
+ security_group_ids: <%= @security_group_ids %>
34
+ subnet_id: <%= @subnets.shuffle.first %>
35
+ iam_instance_profile:
36
+ name: IAMProfileName
37
+ ```
38
+
39
+ ## Variables Layering
40
+
41
+ The variable files are layered together. The base.rb variable file always get evaulated. Then environment specific variables get evaluated according to the `FORGER_ENV` value. For example, `FORGER_ENV=development` results in `config/variables/development.rb` getting used.
42
+
43
+ ## Accessing Variables
44
+
45
+ You access the variables files with ERB. Example:
46
+
47
+ profiles/server.yml:
48
+
49
+ ```yaml
50
+ ---
51
+ security_group_ids: <%= @security_group_ids %>
52
+ subnet_id: <%= @subnets.shuffle.first %>
53
+ ```