forger 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.gitmodules +0 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +147 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +136 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +249 -0
- data/Rakefile +6 -0
- data/docs/example/.env +2 -0
- data/docs/example/.env.development +2 -0
- data/docs/example/.env.production +3 -0
- data/docs/example/app/scripts/hello.sh +3 -0
- data/docs/example/app/user-data/bootstrap.sh +35 -0
- data/docs/example/config/development.yml +8 -0
- data/docs/example/profiles/default.yml +11 -0
- data/docs/example/profiles/spot.yml +20 -0
- data/exe/forger +14 -0
- data/forger.gemspec +38 -0
- data/lib/forger.rb +29 -0
- data/lib/forger/ami.rb +10 -0
- data/lib/forger/aws_service.rb +7 -0
- data/lib/forger/base.rb +42 -0
- data/lib/forger/clean.rb +13 -0
- data/lib/forger/cleaner.rb +5 -0
- data/lib/forger/cleaner/ami.rb +45 -0
- data/lib/forger/cli.rb +67 -0
- data/lib/forger/command.rb +67 -0
- data/lib/forger/completer.rb +161 -0
- data/lib/forger/completer/script.rb +6 -0
- data/lib/forger/completer/script.sh +10 -0
- data/lib/forger/config.rb +20 -0
- data/lib/forger/core.rb +51 -0
- data/lib/forger/create.rb +155 -0
- data/lib/forger/create/error_messages.rb +58 -0
- data/lib/forger/create/params.rb +106 -0
- data/lib/forger/dotenv.rb +30 -0
- data/lib/forger/help.rb +9 -0
- data/lib/forger/help/ami.md +13 -0
- data/lib/forger/help/clean/ami.md +22 -0
- data/lib/forger/help/compile.md +5 -0
- data/lib/forger/help/completion.md +22 -0
- data/lib/forger/help/completion_script.md +3 -0
- data/lib/forger/help/create.md +7 -0
- data/lib/forger/help/upload.md +10 -0
- data/lib/forger/help/wait/ami.md +12 -0
- data/lib/forger/hook.rb +33 -0
- data/lib/forger/profile.rb +64 -0
- data/lib/forger/script.rb +46 -0
- data/lib/forger/script/compile.rb +40 -0
- data/lib/forger/script/compress.rb +62 -0
- data/lib/forger/script/templates/ami_creation.sh +12 -0
- data/lib/forger/script/templates/auto_terminate.sh +11 -0
- data/lib/forger/script/templates/auto_terminate_after_timeout.sh +5 -0
- data/lib/forger/script/templates/cloudwatch.sh +3 -0
- data/lib/forger/script/templates/extract_aws_ec2_scripts.sh +48 -0
- data/lib/forger/script/upload.rb +99 -0
- data/lib/forger/scripts/auto_terminate.sh +14 -0
- data/lib/forger/scripts/auto_terminate/after_timeout.sh +18 -0
- data/lib/forger/scripts/auto_terminate/functions.sh +130 -0
- data/lib/forger/scripts/auto_terminate/functions/amazonlinux2.sh +10 -0
- data/lib/forger/scripts/auto_terminate/functions/ubuntu.sh +11 -0
- data/lib/forger/scripts/auto_terminate/setup.sh +31 -0
- data/lib/forger/scripts/cloudwatch.sh +24 -0
- data/lib/forger/scripts/cloudwatch/configure.sh +84 -0
- data/lib/forger/scripts/cloudwatch/install.sh +3 -0
- data/lib/forger/scripts/cloudwatch/install/amazonlinux2.sh +4 -0
- data/lib/forger/scripts/cloudwatch/install/ubuntu.sh +23 -0
- data/lib/forger/scripts/cloudwatch/service.sh +3 -0
- data/lib/forger/scripts/cloudwatch/service/amazonlinux2.sh +11 -0
- data/lib/forger/scripts/cloudwatch/service/ubuntu.sh +8 -0
- data/lib/forger/scripts/shared/functions.sh +78 -0
- data/lib/forger/setting.rb +52 -0
- data/lib/forger/template.rb +13 -0
- data/lib/forger/template/context.rb +32 -0
- data/lib/forger/template/helper.rb +17 -0
- data/lib/forger/template/helper/ami_helper.rb +33 -0
- data/lib/forger/template/helper/core_helper.rb +127 -0
- data/lib/forger/template/helper/partial_helper.rb +71 -0
- data/lib/forger/template/helper/script_helper.rb +53 -0
- data/lib/forger/template/helper/ssh_key_helper.rb +21 -0
- data/lib/forger/version.rb +3 -0
- data/lib/forger/wait.rb +12 -0
- data/lib/forger/waiter.rb +5 -0
- data/lib/forger/waiter/ami.rb +61 -0
- data/spec/fixtures/demo_project/config/settings.yml +22 -0
- data/spec/fixtures/demo_project/config/test.yml +9 -0
- data/spec/fixtures/demo_project/profiles/default.yml +33 -0
- data/spec/lib/cli_spec.rb +41 -0
- data/spec/lib/params_spec.rb +71 -0
- data/spec/spec_helper.rb +33 -0
- metadata +354 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b3aa8428858adf323d614a2ad2d417ef111ecba07ed47f921ded9971b687e32
|
4
|
+
data.tar.gz: 954cade32be1581361774f9ef33d2aac9a6b4cc37006b7a60fb28eddf2f3fde8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26d8d1882ce393975e3b0721eacaec3c36e6abfeba8b72093260872b1d56ab158c967669d8991b7d7030938f7bd2e1b9906b607d7257ba9b3e5faa110f0e561e
|
7
|
+
data.tar.gz: 5cf53ac7391f7ae681b0f8951e3b7b923e11e05e29f65437ea7769db3c858b149f915a295f013a9a84f26916d1514e6633734c7a177fd962b3d052c0cb1e99ad
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
File without changes
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
|
+
|
6
|
+
## [1.5.0]
|
7
|
+
- rename to forger
|
8
|
+
|
9
|
+
## [1.4.9]
|
10
|
+
- fix /var/log/auto-terminate.log puts
|
11
|
+
|
12
|
+
## [1.4.8]
|
13
|
+
- show auto-terminate log also in AWS_EC2_CW mode
|
14
|
+
|
15
|
+
## [1.4.7]
|
16
|
+
- add AWS_EC2_CW to show cw tail command
|
17
|
+
|
18
|
+
## [1.4.6]
|
19
|
+
- enable awslogs on reboot
|
20
|
+
- improve message when auto-terminate gets called from a previous ami
|
21
|
+
|
22
|
+
## [1.4.5]
|
23
|
+
- fix cloudwatch python install for ubuntu
|
24
|
+
|
25
|
+
## [1.4.4]
|
26
|
+
- add AWS_EC2_REGION env to set the region for the cloudwatch log displayed url
|
27
|
+
|
28
|
+
## [1.4.3]
|
29
|
+
- fix get_region when aws-ec2 called from an ec2 instance
|
30
|
+
|
31
|
+
## [1.4.2]
|
32
|
+
- fix cloudwatch for ubuntu
|
33
|
+
|
34
|
+
## [1.4.1]
|
35
|
+
- fix cloudwatch support check and add add_to_clipboard url
|
36
|
+
- fix copy_to_clipboard
|
37
|
+
- remove normalize_os debugging call
|
38
|
+
|
39
|
+
## [1.4.0]
|
40
|
+
- Merge pull request #8 from tongueroo/cloudwatch
|
41
|
+
- cloudwatch support for amazonlinux2 and ubuntu
|
42
|
+
|
43
|
+
## [1.3.2]
|
44
|
+
- add noop mode for clean ami command
|
45
|
+
|
46
|
+
## [1.3.1]
|
47
|
+
- fix cleaning so it cleans out the oldest images
|
48
|
+
|
49
|
+
## [1.3.0]
|
50
|
+
- Merge pull request #7 from tongueroo/clean: aws-ec2 clean ami command
|
51
|
+
|
52
|
+
## [1.2.2]
|
53
|
+
- add render_me_pretty as gem instead of submodule
|
54
|
+
|
55
|
+
## [1.2.1]
|
56
|
+
- fix formatting after found ami with puts
|
57
|
+
|
58
|
+
## [1.2.0]
|
59
|
+
- Merge pull request #6 from tongueroo/wait: aws-ec2 wait ami command
|
60
|
+
- Fix dependencies: add aws-sdk-s3 dependency
|
61
|
+
- require render_me_pretty as vendor submodule for now
|
62
|
+
|
63
|
+
## [1.1.0]
|
64
|
+
- Merge pull request #5 from tongueroo/auto-terminate
|
65
|
+
- allow AWS_RDS_CODE_VERSION env variable
|
66
|
+
- restructure way scripts work for sanity
|
67
|
+
- bash scripts: ami_creation.sh and auto_terminate.sh
|
68
|
+
- support only amazonlinux2 and ubuntu
|
69
|
+
|
70
|
+
## [1.0.1]
|
71
|
+
- update ordering of the info displayed
|
72
|
+
|
73
|
+
## [1.0.0]
|
74
|
+
- Merge pull request #1 from tongueroo/cli-template-upgrade
|
75
|
+
- Merge pull request #2 from tongueroo/render_me_pretty
|
76
|
+
- Merge pull request #3 from tongueroo/s3-upload
|
77
|
+
- Merge pull request #4 from tongueroo/layout-support
|
78
|
+
- add --randomize option
|
79
|
+
- add extract_scripts and add_ssh_key helpers
|
80
|
+
- conventionally use name of server as profile if profile exists
|
81
|
+
- introduce settings.yml
|
82
|
+
- latest_ami: exit if image cannot be found
|
83
|
+
|
84
|
+
## [0.9.0]
|
85
|
+
- much improved error messaging
|
86
|
+
- rename docs folder
|
87
|
+
- update readme
|
88
|
+
|
89
|
+
## [0.8.4]
|
90
|
+
- add doc/example
|
91
|
+
- rename to commands to compile and upload
|
92
|
+
- rename to core_helper, only require specfic activesupport dependencies
|
93
|
+
- generate user-data in tmp/user-data.txt instead
|
94
|
+
|
95
|
+
## [0.8.3]
|
96
|
+
- change compile_keep to compile_clean option instead
|
97
|
+
|
98
|
+
## [0.8.2]
|
99
|
+
- add compile_keep option
|
100
|
+
|
101
|
+
## [0.8.1]
|
102
|
+
- reorganize template helpers into core and update readme
|
103
|
+
|
104
|
+
## [0.8.0]
|
105
|
+
- aws-ec2 upload_scripts command
|
106
|
+
- rename aws-ec2 compile to aws-ec2 compile_scripts
|
107
|
+
|
108
|
+
## [0.7.0]
|
109
|
+
- Rid of name to profile convention, check profile exists and report to user
|
110
|
+
if it does not exist. This is a more expected interface.
|
111
|
+
|
112
|
+
## [0.6.0]
|
113
|
+
- add scripts_s3_bucket config option
|
114
|
+
- halt script if hooks fail
|
115
|
+
|
116
|
+
## [0.5.2]
|
117
|
+
- remove byebug debugging
|
118
|
+
|
119
|
+
## [0.5.1]
|
120
|
+
- show a friendly user message if not an aws-ec2 project
|
121
|
+
|
122
|
+
## [0.5.0]
|
123
|
+
- compile_scripts compiles both app/user-data and app/scripts
|
124
|
+
|
125
|
+
## [0.4.0]
|
126
|
+
- aws-ec2 ami command
|
127
|
+
- create: add --source-ami options
|
128
|
+
- compile_scripts command
|
129
|
+
- custom helper support
|
130
|
+
- dotenv support
|
131
|
+
- hook support
|
132
|
+
- latest_ami helper
|
133
|
+
- partial support
|
134
|
+
- starter specs: spec for ami
|
135
|
+
- remove aws-ec2 spot command
|
136
|
+
- remove aws-ec2 userdata command, sanity rspec passing
|
137
|
+
|
138
|
+
## [0.3.0]
|
139
|
+
- Do not merge profile to default profile. This was pretty confusing usage.
|
140
|
+
- Add --ami option which result in automatically creating an ami at the end of
|
141
|
+
the user-data script.
|
142
|
+
|
143
|
+
## [0.2.0]
|
144
|
+
- Add config files support. example: config/development.yml.
|
145
|
+
|
146
|
+
## [0.1.0]
|
147
|
+
- Initial release.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
forger (1.4.9)
|
5
|
+
activesupport
|
6
|
+
aws-sdk-ec2
|
7
|
+
aws-sdk-s3
|
8
|
+
colorize
|
9
|
+
dotenv
|
10
|
+
filesize
|
11
|
+
hashie
|
12
|
+
render_me_pretty
|
13
|
+
thor
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: https://rubygems.org/
|
17
|
+
specs:
|
18
|
+
activesupport (5.2.0)
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
+
i18n (>= 0.7, < 2)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
tzinfo (~> 1.1)
|
23
|
+
aws-partitions (1.80.0)
|
24
|
+
aws-sdk-core (3.19.0)
|
25
|
+
aws-partitions (~> 1.0)
|
26
|
+
aws-sigv4 (~> 1.0)
|
27
|
+
jmespath (~> 1.0)
|
28
|
+
aws-sdk-ec2 (1.29.0)
|
29
|
+
aws-sdk-core (~> 3)
|
30
|
+
aws-sigv4 (~> 1.0)
|
31
|
+
aws-sdk-kms (1.5.0)
|
32
|
+
aws-sdk-core (~> 3)
|
33
|
+
aws-sigv4 (~> 1.0)
|
34
|
+
aws-sdk-s3 (1.9.0)
|
35
|
+
aws-sdk-core (~> 3)
|
36
|
+
aws-sdk-kms (~> 1)
|
37
|
+
aws-sigv4 (~> 1.0)
|
38
|
+
aws-sigv4 (1.0.2)
|
39
|
+
byebug (10.0.1)
|
40
|
+
codeclimate-test-reporter (1.0.8)
|
41
|
+
simplecov (<= 0.13)
|
42
|
+
coderay (1.1.2)
|
43
|
+
colorize (0.8.1)
|
44
|
+
concurrent-ruby (1.0.5)
|
45
|
+
diff-lcs (1.3)
|
46
|
+
docile (1.1.5)
|
47
|
+
dotenv (2.2.1)
|
48
|
+
ffi (1.9.23)
|
49
|
+
filesize (0.1.1)
|
50
|
+
formatador (0.2.5)
|
51
|
+
guard (2.14.2)
|
52
|
+
formatador (>= 0.2.4)
|
53
|
+
listen (>= 2.7, < 4.0)
|
54
|
+
lumberjack (>= 1.0.12, < 2.0)
|
55
|
+
nenv (~> 0.1)
|
56
|
+
notiffany (~> 0.0)
|
57
|
+
pry (>= 0.9.12)
|
58
|
+
shellany (~> 0.0)
|
59
|
+
thor (>= 0.18.1)
|
60
|
+
guard-bundler (2.1.0)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
guard (~> 2.2)
|
63
|
+
guard-compat (~> 1.1)
|
64
|
+
guard-compat (1.2.1)
|
65
|
+
guard-rspec (4.7.3)
|
66
|
+
guard (~> 2.1)
|
67
|
+
guard-compat (~> 1.1)
|
68
|
+
rspec (>= 2.99.0, < 4.0)
|
69
|
+
hashie (3.5.7)
|
70
|
+
i18n (1.0.1)
|
71
|
+
concurrent-ruby (~> 1.0)
|
72
|
+
jmespath (1.4.0)
|
73
|
+
json (2.1.0)
|
74
|
+
listen (3.1.5)
|
75
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
76
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
77
|
+
ruby_dep (~> 1.2)
|
78
|
+
lumberjack (1.0.12)
|
79
|
+
method_source (0.9.0)
|
80
|
+
minitest (5.11.3)
|
81
|
+
nenv (0.3.0)
|
82
|
+
notiffany (0.1.1)
|
83
|
+
nenv (~> 0.1)
|
84
|
+
shellany (~> 0.0)
|
85
|
+
pry (0.11.3)
|
86
|
+
coderay (~> 1.1.0)
|
87
|
+
method_source (~> 0.9.0)
|
88
|
+
rake (12.3.1)
|
89
|
+
rb-fsevent (0.10.3)
|
90
|
+
rb-inotify (0.9.10)
|
91
|
+
ffi (>= 0.5.0, < 2)
|
92
|
+
render_me_pretty (0.8.1)
|
93
|
+
activesupport
|
94
|
+
colorize
|
95
|
+
tilt
|
96
|
+
rspec (3.7.0)
|
97
|
+
rspec-core (~> 3.7.0)
|
98
|
+
rspec-expectations (~> 3.7.0)
|
99
|
+
rspec-mocks (~> 3.7.0)
|
100
|
+
rspec-core (3.7.1)
|
101
|
+
rspec-support (~> 3.7.0)
|
102
|
+
rspec-expectations (3.7.0)
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
+
rspec-support (~> 3.7.0)
|
105
|
+
rspec-mocks (3.7.0)
|
106
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
+
rspec-support (~> 3.7.0)
|
108
|
+
rspec-support (3.7.1)
|
109
|
+
ruby_dep (1.5.0)
|
110
|
+
shellany (0.0.1)
|
111
|
+
simplecov (0.13.0)
|
112
|
+
docile (~> 1.1.0)
|
113
|
+
json (>= 1.8, < 3)
|
114
|
+
simplecov-html (~> 0.10.0)
|
115
|
+
simplecov-html (0.10.2)
|
116
|
+
thor (0.20.0)
|
117
|
+
thread_safe (0.3.6)
|
118
|
+
tilt (2.0.8)
|
119
|
+
tzinfo (1.2.5)
|
120
|
+
thread_safe (~> 0.1)
|
121
|
+
|
122
|
+
PLATFORMS
|
123
|
+
ruby
|
124
|
+
|
125
|
+
DEPENDENCIES
|
126
|
+
bundler
|
127
|
+
byebug
|
128
|
+
codeclimate-test-reporter
|
129
|
+
forger!
|
130
|
+
guard
|
131
|
+
guard-bundler
|
132
|
+
guard-rspec
|
133
|
+
rake
|
134
|
+
|
135
|
+
BUNDLED WITH
|
136
|
+
1.16.1
|
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
guard "bundler", cmd: "bundle" do
|
2
|
+
watch("Gemfile")
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
7
|
+
require "guard/rspec/dsl"
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 Tung Nguyen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
# Forger
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/tongueroo/forger.svg?style=svg)](https://circleci.com/gh/tongueroo/forger)
|
4
|
+
|
5
|
+
Tool to create AWS ec2 instances consistently with pre-configured settings. The pre-configured settings are stored in the profiles folder of the current project directory.
|
6
|
+
Example:
|
7
|
+
|
8
|
+
* profiles/default.yml: Default settings. Used when no profile is specified.
|
9
|
+
* profiles/myserver.yml: myserver profile. Used when `--profile myserver` is specified.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```sh
|
14
|
+
forger create NAME --profile PROFILE
|
15
|
+
forger create myserver --profile myserver
|
16
|
+
```
|
17
|
+
|
18
|
+
In a nutshell, the profile parameters are passed to the ruby aws-sdk [AWS::EC2::Client#run_instances](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2/Client.html#run_instances-instance_method) method. This allows you to specify any parameter you wish that is available in the aws-sdk. To check out what a profile looks like check out [example default](docs/example/profiles/default.yml)
|
19
|
+
|
20
|
+
## Noop mode
|
21
|
+
|
22
|
+
You can do a test run with the `--noop` flag. This will print out what settings will be used to launch the instance. This is one good way to inspect the generated user-data script.
|
23
|
+
|
24
|
+
```sh
|
25
|
+
forger create myserver --profile myserver --noop
|
26
|
+
cat tmp/user-data.txt # to view generated user-data script
|
27
|
+
```
|
28
|
+
|
29
|
+
## Conventional Profile Name
|
30
|
+
|
31
|
+
If there is a profile name that matches the ec2 specified instance name, you can omit the `--profile` flag. Example
|
32
|
+
|
33
|
+
```sh
|
34
|
+
forger create webserver --profile webserver
|
35
|
+
forger create webserver # same as above
|
36
|
+
```
|
37
|
+
|
38
|
+
It is useful to add a random string to the end of your server name, but not use it for the `--profile` flag. Example:
|
39
|
+
|
40
|
+
```
|
41
|
+
forger create myserver-abc --profile myserver
|
42
|
+
forger create myserver-123 --profile myserver
|
43
|
+
```
|
44
|
+
|
45
|
+
You can use the `--randomize` option to do this automatically:
|
46
|
+
|
47
|
+
```
|
48
|
+
forger create myserver --randomize
|
49
|
+
```
|
50
|
+
|
51
|
+
## Project Structure
|
52
|
+
|
53
|
+
Directory | Description
|
54
|
+
------------- | -------------
|
55
|
+
app/helpers | Custom helpers methods. Define them as modules and their methods are made available whenever ERB is available: `profiles`, `app/scripts`, `app/user-data` files, etc. For example, you would define a `module FooHelper` in `app/helpers/foo_helper.rb`.
|
56
|
+
app/partials | Your partials that can to be included in other scripts. This is used in conjunction with the `partial` helper method. With great power comes great responsibility. It is recommended to use partials sparely to keep scripts more straightforward.
|
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
|
+
app/user-data | Your user-data scripts that are used to bootstrap EC2 instance.
|
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.
|
61
|
+
profiles | Your profile files. These files mainly contain parameters that are passed to the aws-sdk run_instances API method.
|
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
|
+
|
64
|
+
## Helpers
|
65
|
+
|
66
|
+
You can use ERB in the profile files. Some useful helper methods are documented here:
|
67
|
+
|
68
|
+
Helper | Description
|
69
|
+
------------- | -------------
|
70
|
+
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.
|
71
|
+
config | Access to the variables set in config/[AWS\_EC2\_ENV].yml. Examples are `config/development.yml` and `config/production.yml`.
|
72
|
+
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`.
|
73
|
+
search_ami | Returns a collection of AMI image objects based on a search pattern. The query searches on the AMI name.
|
74
|
+
extract_scripts | Use this in your bash script to extract the `app/scripts` files that get uploaded to s3.
|
75
|
+
|
76
|
+
For a full list of all the template helpers check out: [lib/forger/template/helper](lib/forger/template/helper).
|
77
|
+
|
78
|
+
You can also define custom helpers in the `app/helpers` folder as ruby modules with the naming convention `*_helper.rb`. For example, you would define a `module FooHelper` in `app/helpers/foo_helper.rb`. Custom helpers are first-class citizens and have access to the same variables, methods, and scope as built-in helpers.
|
79
|
+
|
80
|
+
## User-Data
|
81
|
+
|
82
|
+
You can provide a user-data script to customize the server upon launch. The user-data scripts are located under the `app/user-data` folder. Example:
|
83
|
+
|
84
|
+
* app/user-data/myserver.yml
|
85
|
+
|
86
|
+
The user-data script is generated on the machine that is running the forger command. If this is your local macosx machine, then the context of your local macosx machine is available. To see the generated user-data script, you can run the create command in `--noop` mode and then inspect the generated script. Example:
|
87
|
+
|
88
|
+
```sh
|
89
|
+
forger create myserver --noop
|
90
|
+
cat tmp/user-data.txt
|
91
|
+
```
|
92
|
+
|
93
|
+
Another way to view the generated user-data scripts is the `forger compile` command. It generates the files in the `tmp` folder. Example:
|
94
|
+
|
95
|
+
```
|
96
|
+
forger compile # generates files in tmp folder
|
97
|
+
```
|
98
|
+
|
99
|
+
To use the user-data script when creating an EC2 instance, use the `user_data` helper method in the profile file. Here's a grep of an example profile that uses the helper to show you want it looks like. Be sure to surround the ERB call with quotes because the user-data script context is base64 encoded.
|
100
|
+
|
101
|
+
```
|
102
|
+
$ grep user_data profiles/default.yml
|
103
|
+
user_data: "<%= user_data("bootstrap") %>"
|
104
|
+
```
|
105
|
+
|
106
|
+
### User-Data Layouts
|
107
|
+
|
108
|
+
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`:
|
109
|
+
|
110
|
+
```bash
|
111
|
+
#!/bin/bash
|
112
|
+
# do some setup
|
113
|
+
<%= yield %>
|
114
|
+
# finish work
|
115
|
+
```
|
116
|
+
|
117
|
+
And `app/user-data/box.sh`:
|
118
|
+
|
119
|
+
```
|
120
|
+
yum install -y vim
|
121
|
+
```
|
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.
|
142
|
+
|
143
|
+
### Config
|
144
|
+
|
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`:
|
146
|
+
|
147
|
+
```yaml
|
148
|
+
---
|
149
|
+
vpc_id: vpc-123
|
150
|
+
subnets:
|
151
|
+
- subnet-123
|
152
|
+
- subnet-456
|
153
|
+
- subnet-789
|
154
|
+
security_group_ids:
|
155
|
+
- sg-123
|
156
|
+
```
|
157
|
+
|
158
|
+
The variables are accessed via the `config` helper method. Here's a filtered example where it shows the relevant part of a profile: `profiles/default.yml`:
|
159
|
+
|
160
|
+
```yaml
|
161
|
+
image_id: ami-4fffc834 # Amazon Lambda AMI
|
162
|
+
instance_type: t2.medium
|
163
|
+
security_group_ids: <%= config["security_group_ids"] %>
|
164
|
+
subnet_id: <%= config["subnets"].shuffle %>
|
165
|
+
...
|
166
|
+
```
|
167
|
+
|
168
|
+
### Settings
|
169
|
+
|
170
|
+
A `config/settings.yml` file controls the internal behavior of forger. It is different from config files which are meant for user defined varibles. Settings variables are for internal use. Example:
|
171
|
+
|
172
|
+
```yaml
|
173
|
+
development:
|
174
|
+
# By setting s3_folder, forger will automatically tarball and upload your scripts
|
175
|
+
# to set. You then can then use the extract_scripts helper method to download
|
176
|
+
# the scripts onto the server.
|
177
|
+
s3_folder: boltops-infra-stag/ec2
|
178
|
+
# compile_clean: true # uncomment to clean at the end of a compile
|
179
|
+
# extract_scripts:
|
180
|
+
# to: "/opt"
|
181
|
+
# as: "ec2-user"
|
182
|
+
|
183
|
+
production:
|
184
|
+
```
|
185
|
+
|
186
|
+
### Hooks
|
187
|
+
|
188
|
+
There is only one hook: `before_run_instances`. You can configure this with `config/hooks.yml`: Example:
|
189
|
+
|
190
|
+
```
|
191
|
+
---
|
192
|
+
before_run_instances: /path/to/my/script.sh
|
193
|
+
```
|
194
|
+
|
195
|
+
This will run `/path/to/my/script.sh` as a shelled out command before the `run_instances` call.
|
196
|
+
|
197
|
+
## Dotenv File Support
|
198
|
+
|
199
|
+
You can set and configure environment variables in `.env*` files. Examples of this are in the [example](docs/example) project.
|
200
|
+
|
201
|
+
## AMI Creation
|
202
|
+
|
203
|
+
To create AMIs you can use the `forger ami` command. This command launches an EC2 instance with the specified profile and creates an AMI after the user-data script successfully completes. It does this by appending an AMI creation script at the end of the user-data script. It is recommended to use the `set -e` option in your user-data script so that any error halts the script and the AMI does not get created.
|
204
|
+
|
205
|
+
After the AMI is successfully created, the instance will also terminate itself automatically so you do not have to worry about cleanup. This is also done with an appended script. For more help run `forger ami help`.
|
206
|
+
|
207
|
+
For the instance to image and terminate itself, the EC2 IAM role for the instance requires IAM permissions for:
|
208
|
+
|
209
|
+
* aws ec2 create-image
|
210
|
+
* aws ec2 cancel-spot-instance-requests # in case a spot instance was used
|
211
|
+
* aws ec2 terminate-instances
|
212
|
+
|
213
|
+
## Spot Instance Support
|
214
|
+
|
215
|
+
Spot instance is natively supported by the AWS `run_instances` command by adding the `instance_market_options` to the parameters in the profile file. The available spot market options are available here:
|
216
|
+
|
217
|
+
* [https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_LaunchTemplateSpotMarketOptionsRequest.html](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_LaunchTemplateSpotMarketOptionsRequest.html)
|
218
|
+
* [https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2/Types/SpotMarketOptions.html](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2/Types/SpotMarketOptions.html)
|
219
|
+
|
220
|
+
An example of a spot instance profile is provided in [example/profiles/spot.yml](docs/example/profiles/spot.yml).
|
221
|
+
|
222
|
+
## More Help
|
223
|
+
|
224
|
+
```sh
|
225
|
+
forger create help
|
226
|
+
forger ami help
|
227
|
+
forger compile help
|
228
|
+
forger help # general help
|
229
|
+
```
|
230
|
+
|
231
|
+
Examples are in the [example](docs/example) folder. You will have to update settings like your subnet and security group ids.
|
232
|
+
|
233
|
+
## Installation
|
234
|
+
|
235
|
+
```sh
|
236
|
+
gem install forger
|
237
|
+
```
|
238
|
+
|
239
|
+
### Dependencies
|
240
|
+
|
241
|
+
This tool mainly uses the ruby aws-sdk. Though it does use the aws cli to check your region: `aws configure get region`. It also the uses `aws s3 sync` to perform the scripts upload. So it is dependent on the the `aws cli`.
|
242
|
+
|
243
|
+
## Contributing
|
244
|
+
|
245
|
+
1. Fork it
|
246
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
247
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
248
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
249
|
+
5. Create new Pull Request
|