aws_stack_builder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +20 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +107 -0
  10. data/Rakefile +2 -0
  11. data/aws_stack_builder.gemspec +29 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/aws_stack_builder.rb +5 -0
  15. data/lib/aws_stack_builder/version.rb +3 -0
  16. data/lib/generators/aws_stack_builder/USAGE +25 -0
  17. data/lib/generators/aws_stack_builder/aws_stack_builder_generator.rb +47 -0
  18. data/lib/generators/aws_stack_builder/templates/aws/doc/README.md +69 -0
  19. data/lib/generators/aws_stack_builder/templates/aws/doc/app-cf-designer.png +0 -0
  20. data/lib/generators/aws_stack_builder/templates/aws/geradores/ami-userdata.sh.template +54 -0
  21. data/lib/generators/aws_stack_builder/templates/aws/geradores/build_templates.sh.template +6 -0
  22. data/lib/generators/aws_stack_builder/templates/aws/geradores/cf-base-instance.py.template +96 -0
  23. data/lib/generators/aws_stack_builder/templates/aws/geradores/cf-stack-generator.py.template +456 -0
  24. data/lib/generators/aws_stack_builder/templates/aws/scripts/app_deploy.sh.template +32 -0
  25. data/lib/generators/aws_stack_builder/templates/aws/scripts/app_pack.sh +36 -0
  26. data/lib/generators/aws_stack_builder/templates/aws/scripts/app_stop_instances_by_role.sh.template +35 -0
  27. data/lib/generators/aws_stack_builder/templates/aws/scripts/app_update.sh.template +77 -0
  28. data/lib/generators/aws_stack_builder/templates/aws/scripts/run_delayed_job.sh +25 -0
  29. metadata +102 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59de65fad1bf2ce53878fdde5c6c85124bc41f2496278227bb21a339e3cefdf0
4
+ data.tar.gz: 0c0875eddd152d1d2ef7c33f38c0384fd6ef3fe96c24a50dd27975f9f928f214
5
+ SHA512:
6
+ metadata.gz: f3522d648822ed372a3c873f2be89258ec09e44677659c4b3554a131dad5527f1de8f7f8c5f5601dbad08190163e92610d987f717933da5205a75d89c7c2ba49
7
+ data.tar.gz: 93c822b28ad42b5be4bb50f9c5d86aa3fe58f38fdb6e09b14b97174c99e3e15fa0df2203abe20e7236786336e304b3a50bc28e158e2605f9eb5e8990b7bc08a6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
@@ -0,0 +1 @@
1
+ aws-stack-builder
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jose.lopes.santos.neto@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in aws_stack_builder.gemspec
6
+ gemspec
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aws_stack_builder (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ aws_stack_builder!
16
+ bundler (~> 1.16)
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Neto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,107 @@
1
+ # AwsStackBuilder
2
+
3
+ Essa gem ira criar os arquivos necessários para criar e atualizar o stack
4
+ de seu aplicativo na AWS
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'aws_stack_builder'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install aws_stack_builder
21
+
22
+ ## Usage
23
+
24
+ # Instalação de Produção ou Homologação
25
+
26
+ Para instalar o aplicativo, temos 2 arquivos do Cloud Formation:
27
+
28
+ - O primeiro para montar a maquina base onde os aplicativos irão rodar, que a partir desse EC2
29
+ iremos gerar a AMI base para as maquinas de homologação e produção
30
+
31
+ - O segundo é para montar o STACK completo do aplicativo, que usa como
32
+ parametro o ID da AMI gerada pelo primeiro CF
33
+
34
+
35
+ - Entre no Cloud Formation: https://console.aws.amazon.com/cloudformation
36
+ - Clique em Create Stack e informe o CF da AMI e execute
37
+ - Como output teremos o id da maquinda criada
38
+ - Entre no EC2 e a partir dessa maquina crie uma AMI.
39
+ - Anote o AMI dessa AMI e altere o default do CF do Stack para esse novo ID
40
+
41
+
42
+ Durante a criacao da maquina, o log é criado esta no /tmp/user_data.log
43
+
44
+ tail -f /tmp/user_data.log
45
+
46
+
47
+
48
+ - Entre no Cloud Formation novamente
49
+ - Clique em Create Stack e informe o agora o segundo CF do Stack e execute
50
+ - Como output teremos o DNS de entrada no stack completo do aplicativo
51
+ - Entre no Aplicativo e faça um ciclo completo de uso para validar a instalação
52
+
53
+
54
+
55
+
56
+ # Cloud Formation (CF)
57
+
58
+ Para criar os arquivos do CF usamos as seguintes ferramentas:
59
+
60
+ ### Throposhpere
61
+ https://github.com/cloudtools/troposphere
62
+
63
+ ### CF Designer:
64
+ https://console.aws.amazon.com/cloudformation/designer/home?region=us-east-1
65
+
66
+ Primeiro instale o troposphere na sua maquina
67
+
68
+ https://github.com/cloudtools/troposphere
69
+ $ pip install troposphere
70
+
71
+
72
+ Para gerar o cloud formation, execute o arquivo aws_stack.py com o python
73
+
74
+ python aws_stack.py
75
+
76
+ Responda as perguntas e no final um novo arquivo .json será criado
77
+
78
+ Voce pode abrir o Json gerado para visualizar a arquiterura do aplicativo:
79
+
80
+ WEB
81
+ WORKERS:
82
+ calc_testv (ASJM)
83
+ general (ASJM)
84
+ deploy (ASJM)
85
+ builder
86
+ SUNSPOT
87
+ RDS*
88
+ S3*
89
+
90
+
91
+ ## Development
92
+
93
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
94
+
95
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_stack_builder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
104
+
105
+ ## Code of Conduct
106
+
107
+ Everyone interacting in the AwsStackBuilder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/aws_stack_builder/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "aws_stack_builder/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aws_stack_builder"
8
+ spec.version = AwsStackBuilder::VERSION
9
+ spec.authors = ["Neto"]
10
+ spec.email = ["jose.lopes.santos.neto@gmail.com"]
11
+
12
+ spec.summary = "Gem to create the cloud formation files do create the ROR app stack on AWS"
13
+ spec.description = "Gem to create the cloud formation files do create the ROR app stack on AWS"
14
+ spec.homepage = "http://www.mcfox.com.br"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aws_stack_builder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "aws_stack_builder/version"
2
+
3
+ module AwsStackBuilder
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module AwsStackBuilder
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ Description:
2
+ This generator builds the files required to create a complete Stack for this application on AWS
3
+ with Load Balance, Route 53, Web Servers, Delayed Jobs Worker, Security Groups ....
4
+
5
+ rails generate aws_stack_builder [app_name] [role1 [role2...]]
6
+
7
+ Example:
8
+
9
+ rails g aws_stack_builder your_amazing_app role1 role2 role3
10
+
11
+ This will create:
12
+
13
+ aws/doc/README.md
14
+ aws/doc/app-cf-designer.png
15
+
16
+ aws/scripts/app_pack.sh
17
+ aws/scripts/run_delayed_job.sh
18
+ aws/scripts/app_stop_instances.sh
19
+ aws/scripts/app_deploy.sh
20
+ aws/scripts/app_update.sh
21
+
22
+ aws/geradores/ami-userdata.sh
23
+ aws/geradores/cf-base-instance.py
24
+ aws/geradores/cf-stack-generator.py
25
+ aws/geradores/build_templates.sh
@@ -0,0 +1,47 @@
1
+ class AwsStackBuilderGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :app_name, :type => :string
4
+ argument :roles, :type => :array
5
+
6
+ def create_aws_folder
7
+ @app_name = app_name
8
+ @roles = roles
9
+ puts "Gerando na pasta aws todos os arquivos necessários"
10
+ puts "para criarmos o stack na AWS para o app #{app_name}"
11
+ puts "com os roles #{roles.join(', ')}."
12
+ puts "Consute o arquivo aws/doc/README.md para instruções."
13
+
14
+ copy_standard_files
15
+ create_custom_files
16
+
17
+ # transformo os arquivos em executáveis
18
+ File.chmod(0755,"aws/geradores/build_templates.sh")
19
+ File.chmod(0755,"aws/scripts/app_deploy.sh")
20
+ File.chmod(0755,"aws/scripts/app_pack.sh")
21
+ File.chmod(0755,"aws/scripts/app_stop_instances.sh")
22
+ File.chmod(0755,"aws/scripts/app_update.sh")
23
+ File.chmod(0755,"aws/scripts/run_delayed_job.sh")
24
+ puts "Arquivos gerados."
25
+
26
+ end
27
+
28
+ private
29
+
30
+ def copy_standard_files
31
+ directory "aws/doc", "aws/doc"
32
+ copy_file "aws/scripts/app_pack.sh"
33
+ copy_file "aws/scripts/run_delayed_job.sh"
34
+ end
35
+
36
+ def create_custom_files
37
+ # aqui geramos os arquivos com os roles baseados nos workers informados
38
+ template "aws/geradores/ami-userdata.sh.template", "aws/geradores/ami-userdata.sh"
39
+ template "aws/geradores/build_templates.sh.template", "aws/geradores/build_templates.sh"
40
+ template "aws/scripts/app_deploy.sh.template", "aws/scripts/app_deploy.sh"
41
+ template "aws/scripts/app_stop_instances_by_role.sh.template", "aws/scripts/app_stop_instances.sh"
42
+ template "aws/scripts/app_update.sh.template", "aws/scripts/app_update.sh"
43
+ template "aws/geradores/cf-stack-generator.py.template", "aws/geradores/cf-stack-generator.py"
44
+ template "aws/geradores/cf-base-instance.py.template", "aws/geradores/cf-base-instance.py"
45
+ end
46
+
47
+ end
@@ -0,0 +1,69 @@
1
+ # Instalação de Produção ou Homologação
2
+
3
+ Para instalar o aplicativo, temos 2 arquivos do Cloud Formation:
4
+
5
+ - O primeiro para montar a maquina base onde os aplicativos irão rodar, que a partir desse EC2
6
+ iremos gerar a AMI base para as maquinas de homologação e produção
7
+
8
+ - O segundo é para montar o STACK completo do aplicativo, que usa como
9
+ parametro o ID da AMI gerada pelo primeiro CF
10
+
11
+
12
+ - Entre no Cloud Formation: https://console.aws.amazon.com/cloudformation
13
+ - Clique em Create Stack e informe o CF da AMI e execute
14
+ - Como output teremos o id da maquinda criada
15
+ - Entre no EC2 e a partir dessa maquina crie uma AMI.
16
+ - Anote o AMI dessa AMI e altere o default do CF do Stack para esse novo ID
17
+
18
+
19
+ Durante a criacao da maquina, o log é criado esta no /tmp/user_data.log
20
+
21
+ tail -f /tmp/user_data.log
22
+
23
+
24
+
25
+ - Entre no Cloud Formation novamente
26
+ - Clique em Create Stack e informe o agora o segundo CF do Stack e execute
27
+ - Como output teremos o DNS de entrada no stack completo do aplicativo
28
+ - Entre no Aplicativo e faça um ciclo completo de uso para validar a instalação
29
+
30
+
31
+
32
+
33
+ # Cloud Formation (CF)
34
+
35
+ Para criar os arquivos do CF usamos as seguintes ferramentas:
36
+
37
+ ### Throposhpere
38
+ https://github.com/cloudtools/troposphere
39
+
40
+ ### CF Designer:
41
+ https://console.aws.amazon.com/cloudformation/designer/home?region=us-east-1
42
+
43
+ Primeiro instale o troposphere na sua maquina
44
+
45
+ https://github.com/cloudtools/troposphere
46
+ $ pip install troposphere
47
+
48
+
49
+ Para gerar o cloud formation, execute o arquivo aws_stack.py com o python
50
+
51
+ python aws_stack.py
52
+
53
+ Responda as perguntas e no final um novo arquivo .json será criado
54
+
55
+ Voce pode abrir o Json gerado para visualizar a arquiterura do aplicativo:
56
+
57
+ WEB
58
+ WORKERS:
59
+ calc_testv (ASJM)
60
+ general (ASJM)
61
+ deploy (ASJM)
62
+ builder
63
+ SUNSPOT
64
+ RDS*
65
+ S3*
66
+
67
+
68
+ ![stack](app-cf-designer.png)
69
+