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,32 @@
1
+ #!/bin/bash
2
+
3
+ USAGE="Uso: app_deploy.sh <RAILS_ENV>"
4
+
5
+ SCRIPT_DIR=$(dirname "$0")
6
+ cd $SCRIPT_DIR
7
+
8
+ RAILS_ENV=$1
9
+
10
+ if [ -z $RAILS_ENV ]; then
11
+ echo "Argumento RAILS_ENV é obrigatório."
12
+ echo $USAGE
13
+ exit
14
+ fi
15
+
16
+ if [ $RAILS_ENV != 'staging' ] && [ $RAILS_ENV != 'production' ]; then
17
+ echo "Valores permitidos para o argumento RAILS_ENV são: staging, production."
18
+ echo $USAGE
19
+ exit
20
+ fi
21
+
22
+ echo "Preparing application for deployment..."
23
+ app_pack.sh $RAILS_ENV
24
+ echo "Done."
25
+
26
+ echo "Rebooting AWS instances to deploy new version."
27
+ app_stop_instances_by_role.sh $RAILS_ENV web
28
+ <%- @roles.each do |role| %>
29
+ app_stop_instances_by_role.sh $RAILS_ENV <%= role %>
30
+ <% end %>
31
+ echo "Done."
32
+
@@ -0,0 +1,36 @@
1
+ #!/bin/bash
2
+
3
+ SCRIPT_DIR=$(dirname "$0")
4
+ cd $SCRIPT_DIR/../..
5
+
6
+ mkdir -p dist
7
+ RAILS_ENV=$1
8
+ APP_NAME=taxrules
9
+
10
+ # get current branch
11
+ BRANCH=`git branch | grep "*" | awk '{print $2}'`
12
+
13
+ # if RAILS_ENV was not set on the call, define it based on the current branch
14
+ if [ -z "$RAILS_ENV" ]; then
15
+ if [ $BRANCH = 'master' ]; then
16
+ RAILS_ENV="production"
17
+ else
18
+ RAILS_ENV="staging"
19
+ fi
20
+ fi
21
+
22
+ # define the filename
23
+ if [ $RAILS_ENV = 'staging' ]; then
24
+ FILENAME=source-hml.zip
25
+ else
26
+ FILENAME=source.zip
27
+ fi
28
+
29
+ echo Packing branch $BRANCH to $FILENAME
30
+ git archive -o dist/$FILENAME $BRANCH
31
+ git show $BRANCH:aws/scripts/app_update.sh > dist/app_update.sh
32
+
33
+ s3cmd sync dist/app_update.sh s3://taxweb-deploy/$APP_NAME/app_update.sh
34
+ s3cmd sync dist/$FILENAME s3://taxweb-deploy/$APP_NAME/$FILENAME
35
+ s3cmd setacl s3://taxweb-deploy/$APP_NAME/$FILENAME --acl-public
36
+ s3cmd setacl s3://taxweb-deploy/$APP_NAME/app_update.sh --acl-public
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ USAGE="Uso: app_stop_instances_by_role.sh <RAILS_ENV> <ROLE>"
4
+
5
+ RAILS_ENV=$1
6
+ ROLE=$2
7
+
8
+ if [ -z $RAILS_ENV ] || [ -z $ROLE ]; then
9
+ echo "Argumentos RAILS_ENV e ROLE são obrigatórios."
10
+ echo $USAGE
11
+ exit
12
+ fi
13
+
14
+ if [ $RAILS_ENV != 'staging' ] && [ $RAILS_ENV != 'production' ]; then
15
+ echo "Valores permitidos para o argumento RAILS_ENV são: staging, production."
16
+ echo $USAGE
17
+ exit
18
+ fi
19
+
20
+ if [ $RAILS_ENV = 'production' ]; then
21
+ REGION="us-east-1"
22
+ else
23
+ REGION="us-west-2"
24
+ fi
25
+
26
+ # get instance ids
27
+ instance_ids=$(aws ec2 describe-instances --region $REGION --output text --filter "Name=tag:Name,Values=<%= @app_name %>*" "Name=tag:Env,Values=$RAILS_ENV" "Name=tag:Role,Values=$ROLE" "Name=instance-state-name,Values=running" | grep INSTANCES | awk '{if ($18 == "ebs") print $9}')
28
+
29
+ # stop instances
30
+ if [ -n "$instance_ids" ]
31
+ then
32
+ aws ec2 stop-instances --region $REGION --instance-ids $instance_ids
33
+ else
34
+ echo "Nenhuma instância do ROLE '$ROLE' encontrada no ambiente '$RAILS_ENV'."
35
+ fi
@@ -0,0 +1,77 @@
1
+ #!/bin/bash --login
2
+
3
+ app_path="/home/deploy/app/current"
4
+ shared_path="/home/deploy/app/shared"
5
+
6
+ # Log output of this script to file in /tmp
7
+ set -x
8
+ exec > /tmp/app_update.log 2>&1
9
+
10
+ RAILS_ENV=$1
11
+ ROLE=$2
12
+ BUCKET_NAME=$3
13
+
14
+ if [ -z $RAILS_ENV ]; then
15
+ echo Environment must be informed
16
+ exit 1
17
+ fi
18
+
19
+ if [ -z ROLE ]; then
20
+ echo Role must be informed
21
+ exit 1
22
+ fi
23
+
24
+ if [ $RAILS_ENV = 'production' ]; then
25
+ FILENAME=source.zip
26
+ else
27
+ FILENAME=source-hml.zip
28
+ fi
29
+
30
+ if [ -z $ROLE ]; then
31
+ ROLE="web"
32
+ fi
33
+
34
+
35
+ echo Updating Role: $ROLE
36
+
37
+ echo Deleting old files
38
+ rm -rf ./*
39
+ rm -rf ./.*
40
+ echo done.
41
+
42
+ echo Downloading source code from S3 : $FILENAME
43
+ wget http://taxweb-deploy.s3.amazonaws.com/$BUCKET_NAME/$FILENAME -O $FILENAME >/dev/null 2>&1
44
+ echo done.
45
+
46
+ echo Extracting source code
47
+
48
+ unzip -o -q $FILENAME
49
+ echo done.
50
+
51
+ echo Installing new gems...
52
+ cd /tmp
53
+ cd $app_path
54
+ bundle config git.allow_insecure true && bundle install --without development test
55
+ echo done.
56
+
57
+ export RAILS_ENV=$RAILS_ENV
58
+
59
+ if [ $ROLE = "web" ]; then
60
+ echo Compiling Assets...
61
+ rake assets:precompile
62
+ echo Restarting Passenger
63
+ sudo touch tmp/restart.txt
64
+ fi
65
+
66
+ <%- @roles.each do |role| %>
67
+ if [ $ROLE = "<%= role %>" ]; then
68
+ cd $app_path && mkdir -p log
69
+ echo Restarting Workers <%= role %>...
70
+ chmod 755 $app_path/aws/scripts/run_delayed_job.sh
71
+ $app_path/aws/scripts/run_delayed_job.sh stop $ROLE
72
+ pkill -9 -f delayed
73
+ $app_path/aws/scripts/run_delayed_job.sh start $ROLE
74
+ fi
75
+ <% end %>
76
+
77
+ echo done Role: $ROLE
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+
3
+ app_path="/home/deploy/app/current"
4
+ ACTION=$1
5
+ ROLE=$2
6
+
7
+ mkdir -p $app_path/log
8
+
9
+ case $ACTION in
10
+ start)
11
+ echo -n "Starting delayed_job: "
12
+ sudo su - deploy -c "cd $app_path && ./bin/delayed_job --pool=$ROLE:2 start >> $app_path/log/delayed_job.log";
13
+ echo "done."
14
+ ;;
15
+ stop)
16
+ echo -n "Stopping delayed_job: "
17
+ sudo su - deploy -c "cd $app_path && ./bin/delayed_job stop >> $app_path/log/delayed_job.log";
18
+ echo "done."
19
+ ;;
20
+ *)
21
+ echo "Usage: $N {start|stop}" >&2
22
+ exit 1
23
+ ;;
24
+ esac
25
+ exit 0
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_stack_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Neto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Gem to create the cloud formation files do create the ROR app stack on
42
+ AWS
43
+ email:
44
+ - jose.lopes.santos.neto@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".idea/inspectionProfiles/Project_Default.xml"
51
+ - ".idea/vcs.xml"
52
+ - ".ruby-gemset"
53
+ - ".ruby-version"
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - aws_stack_builder.gemspec
61
+ - bin/console
62
+ - bin/setup
63
+ - lib/aws_stack_builder.rb
64
+ - lib/aws_stack_builder/version.rb
65
+ - lib/generators/aws_stack_builder/USAGE
66
+ - lib/generators/aws_stack_builder/aws_stack_builder_generator.rb
67
+ - lib/generators/aws_stack_builder/templates/aws/doc/README.md
68
+ - lib/generators/aws_stack_builder/templates/aws/doc/app-cf-designer.png
69
+ - lib/generators/aws_stack_builder/templates/aws/geradores/ami-userdata.sh.template
70
+ - lib/generators/aws_stack_builder/templates/aws/geradores/build_templates.sh.template
71
+ - lib/generators/aws_stack_builder/templates/aws/geradores/cf-base-instance.py.template
72
+ - lib/generators/aws_stack_builder/templates/aws/geradores/cf-stack-generator.py.template
73
+ - lib/generators/aws_stack_builder/templates/aws/scripts/app_deploy.sh.template
74
+ - lib/generators/aws_stack_builder/templates/aws/scripts/app_pack.sh
75
+ - lib/generators/aws_stack_builder/templates/aws/scripts/app_stop_instances_by_role.sh.template
76
+ - lib/generators/aws_stack_builder/templates/aws/scripts/app_update.sh.template
77
+ - lib/generators/aws_stack_builder/templates/aws/scripts/run_delayed_job.sh
78
+ homepage: http://www.mcfox.com.br
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Gem to create the cloud formation files do create the ROR app stack on AWS
102
+ test_files: []