aws_deploy 0.2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/app/business/aws_deploy/tasks/generate_aws_deploy.rb +53 -0
  5. data/app/business/aws_deploy/tasks/generate_aws_send_rb.rb +49 -0
  6. data/app/business/aws_deploy/tasks/generate_git_version_tag_rb.rb +70 -0
  7. data/app/business/aws_deploy/tasks/generate_local_deploy_rb.rb +157 -0
  8. data/app/business/aws_deploy/tasks/generate_production_cron_check_updates.rb +134 -0
  9. data/app/business/aws_deploy/tasks/generate_production_deploy_sh.rb +146 -0
  10. data/app/business/aws_deploy/tasks/setup_yml.rb +89 -0
  11. data/app/business/deploy/deploy.rb +17 -0
  12. data/app/business/deploy/packing.rb +13 -0
  13. data/app/controllers/aws_deploy/aws_deploy_application_controller.rb +56 -0
  14. data/app/controllers/aws_deploy/index/version.rb +24 -0
  15. data/app/controllers/aws_deploy/index_controller.rb +70 -0
  16. data/app/views/aws_deploy/index/_config_file_not_found.html.erb +11 -0
  17. data/app/views/aws_deploy/index/index.html.erb +70 -0
  18. data/app/views/layouts/aws_deploy.html.erb +208 -0
  19. data/config/initializers/aws_deploy.rb +19 -0
  20. data/config/routes.rb +10 -0
  21. data/lib/aws_deploy/engine.rb +17 -0
  22. data/lib/aws_deploy/version.rb +3 -0
  23. data/lib/aws_deploy.rb +9 -0
  24. data/lib/tasks/aws_deploy_tasks.rake +47 -0
  25. data/test/aws_deploy_test.rb +7 -0
  26. data/test/dummy/README.rdoc +28 -0
  27. data/test/dummy/Rakefile +6 -0
  28. data/test/dummy/app/assets/javascripts/application.js +13 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +5 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/test/dummy/bin/bundle +3 -0
  34. data/test/dummy/bin/rails +4 -0
  35. data/test/dummy/bin/rake +4 -0
  36. data/test/dummy/config/application.rb +23 -0
  37. data/test/dummy/config/aws_deploy.yml +11 -0
  38. data/test/dummy/config/aws_deploy_.yml +23 -0
  39. data/test/dummy/config/boot.rb +5 -0
  40. data/test/dummy/config/database.yml +25 -0
  41. data/test/dummy/config/environment.rb +5 -0
  42. data/test/dummy/config/environments/development.rb +29 -0
  43. data/test/dummy/config/environments/production.rb +80 -0
  44. data/test/dummy/config/environments/test.rb +36 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  47. data/test/dummy/config/initializers/inflections.rb +16 -0
  48. data/test/dummy/config/initializers/mime_types.rb +5 -0
  49. data/test/dummy/config/initializers/secret_token.rb +12 -0
  50. data/test/dummy/config/initializers/session_store.rb +3 -0
  51. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/test/dummy/config/locales/en.yml +23 -0
  53. data/test/dummy/config/routes.rb +56 -0
  54. data/test/dummy/config.ru +4 -0
  55. data/test/dummy/db/development.sqlite3 +0 -0
  56. data/test/dummy/log/development.log +6379 -0
  57. data/test/dummy/log/local.log +0 -0
  58. data/test/dummy/public/404.html +58 -0
  59. data/test/dummy/public/422.html +58 -0
  60. data/test/dummy/public/500.html +57 -0
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/dummy/script/deploy.rb +116 -0
  63. data/test/dummy/script/lib/deploy/aws_send.rb +29 -0
  64. data/test/dummy/script/lib/deploy/git_version_tag.rb +48 -0
  65. data/test/dummy/script/production/cron_check_updates.rb +109 -0
  66. data/test/dummy/script/production/deploy.sh +127 -0
  67. data/test/test_helper.rb +15 -0
  68. metadata +180 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: beb5a252844c9639b20fe5175bf4b3b724e776a8
4
+ data.tar.gz: 554f47ff5a8b86381a541c36f315838551705baa
5
+ SHA512:
6
+ metadata.gz: 8684cd1bfb6c1c10d9c3fc7d476778e16c971ae12d81a03105c230194b43fa46cd8e45c309cbe4c0c5b6b762a69ff3444fa70d0a463034719987a7210f416e80
7
+ data.tar.gz: 4c39a7bf0fdf67e52014c4a52aab2dc52ea98f4faf714cdacd915983400a9638b880564ecd74260a5172c4024130001da7ae7f755599b67ce31f68ba14917db4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'AwsDeploy'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,53 @@
1
+ module AwsDeploy::Tasks::GenerateAwsDeploy
2
+
3
+ #
4
+ #
5
+ def generate_aws_deploy
6
+
7
+ content = "development:\n" +
8
+ " aws_bucket: \"#{@aws_deploy_bucket}\" \n" +
9
+ " aws_access_key_id: \"#{@aws_access_key_id}\" \n" +
10
+ " aws_secret_access_key: \"#{@aws_secret_access_key}\" \n" +
11
+ " file_pattern: \"#{@file_pattern}\" \n" +
12
+ "\n" +
13
+ "development_remote: \n" +
14
+ " aws_bucket: \"#{@aws_deploy_bucket}\"\n" +
15
+ " aws_access_key_id: \"#{@aws_access_key_id}\"\n" +
16
+ " aws_secret_access_key: \"#{@aws_secret_access_key}\"\n" +
17
+ " file_pattern: \"#{@file_pattern}\"\n"
18
+
19
+ File.delete("#{Rails.root}/config/aws_deploy.yml") if File.exists?("#{Rails.root}/config/aws_deploy.yml")
20
+
21
+ File.open("#{Rails.root}/config/aws_deploy.yml", "w") do |f|
22
+ f.write("#{content}")
23
+ end
24
+
25
+ "#{Rails.root}/config/aws_deploy.yml"
26
+ end
27
+
28
+
29
+ #
30
+ #
31
+ def collect_inputs__aws_deploy
32
+
33
+ print "What is the of your AWS BUCKET ? [directory/deploy] :"
34
+ @aws_deploy_bucket = STDIN.gets
35
+ @aws_deploy_bucket = (@aws_deploy_bucket.blank? ? "directory/deploy" : @aws_deploy_bucket)
36
+ puts "#{@aws_deploy_bucket.gsub!("\n","")} \n"
37
+
38
+ print "What is your AWS ACCESS KEY ID ? [my_key_id] :"
39
+ @aws_access_key_id = STDIN.gets || "my_key_id"
40
+ puts "#{@aws_access_key_id.gsub!("\n","")} \n"
41
+
42
+ print "What is your AWS SECRET ACCESS KEY ? [my_secret_key] :"
43
+ @aws_secret_access_key = STDIN.gets || "my_secret_key"
44
+ puts "#{@aws_secret_access_key.gsub!("\n","")} \n"
45
+
46
+ print "What is your FILE PATERN ? [my_file_before_zip_ext] :"
47
+ @file_pattern = STDIN.gets || "my_file_before_zip_ext"
48
+ puts "#{@file_pattern.gsub!("\n","")} \n"
49
+
50
+ end
51
+
52
+
53
+ end
@@ -0,0 +1,49 @@
1
+ module AwsDeploy::Tasks::GenerateAwsSendRb
2
+
3
+ #
4
+ #
5
+ def generate_local_aws_send_rb
6
+
7
+ content =
8
+ "require \"fileutils\" \n" +
9
+ "require \"aws-sdk\" \n" +
10
+ " \n" +
11
+ "class AwsSend \n" +
12
+ " \n" +
13
+ " DEFAULT_ENV = \"development_remote\" \n" +
14
+ " \n" +
15
+ " def initialize access_key_id=\"\", secret_access_key=\"\" \n" +
16
+ " AWS.config(:access_key_id => \"\#{access_key_id}\", :secret_access_key => \"\#{secret_access_key}\") \n" +
17
+ " end \n" +
18
+ " \n" +
19
+ " # \n" +
20
+ " # \n" +
21
+ " def send file_name=\"\", bucket_path=\"\" \n" +
22
+ " puts \"File: \#{file_name} ... bucket: \#{bucket_path}\" \n" +
23
+ " \n" +
24
+ " s3 = AWS::S3.new \n" +
25
+ " bucket = s3.buckets[\"\#{bucket_path}\"] \n" +
26
+ " \n" +
27
+ " base_file_name = \"\#{File.basename(file_name, \".*\")}-\#{AwsSend::DEFAULT_ENV}\#{File.extname(file_name)}\" \n" +
28
+ " puts \" ... new file name: \#{base_file_name}\" \n" +
29
+ " \n" +
30
+ " obj = bucket.objects[base_file_name] \n" +
31
+ " obj.delete \n" +
32
+ " obj.write(Pathname.new(\"\#{file_name}\")) \n" +
33
+ " \n" +
34
+ " end \n" +
35
+ " \n" +
36
+ "end \n"
37
+
38
+
39
+ File.delete("#{Rails.root}/script/lib/deploy/aws_send.rb") if File.exists?("#{Rails.root}/script/lib/deploy/aws_send.rb")
40
+
41
+ File.open("#{Rails.root}/script/lib/deploy/aws_send.rb", "w") do |f|
42
+ f.write("#{content}")
43
+ end
44
+
45
+ "#{Rails.root}/script/lib/deploy/aws_send.rb"
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,70 @@
1
+ module AwsDeploy::Tasks::GenerateGitVersionTagRb
2
+
3
+ #
4
+ #
5
+ def generate_local_git_version_tag_rb
6
+
7
+ content =
8
+ "class GitVersionTag \n" +
9
+ " \n" +
10
+ " \n" +
11
+ " def initialize time=\"sample time\", remote_git=\"gitlab\", public_dir=\"../public\" \n" +
12
+ " @time = time \n" +
13
+ " @remote_git = remote_git \n" +
14
+ " @public_dir = public_dir \n" +
15
+ " end \n" +
16
+ " \n" +
17
+ " # \n" +
18
+ " # \n" +
19
+ " # \n" +
20
+ " def version_it \n" +
21
+ " version_content = \"Deployment Version: \#{@time}\" \n" +
22
+ " \n" +
23
+ " File.open(\"\#{@public_dir}/version.txt\", 'w') {|f| f.write(version_content) } \n" +
24
+ " system(\"git branch >> \#{@public_dir}/version.txt\") \n" +
25
+ " system(\"git add .\") \n" +
26
+ " system(\"git commit -am 'updating version.txt' \") \n" +
27
+ " \n" +
28
+ " current_branch = %x[git rev-parse --abbrev-ref HEAD].gsub(\"\\n\", \"\").gsub(\"/\",\".\") \n" +
29
+ " system(\"git push \#{@remote_git} \#{current_branch}\") \n" +
30
+ " end \n" +
31
+ " \n" +
32
+ " \n" +
33
+ " # \n" +
34
+ " # \n" +
35
+ " # \n" +
36
+ " def tag_it \n" +
37
+ " \n" +
38
+ " current_branch = %x[git rev-parse --abbrev-ref HEAD].gsub(\"\\n\", \"\").gsub(\"/\",\".\") \n" +
39
+ " tag_name = \"v.\#{@time}.\#{current_branch}\" \n" +
40
+ " \n" +
41
+ " puts \" - Tag name: \#{tag_name}\" \n" +
42
+ " puts \" - Current Branch: \#{current_branch}\" \n" +
43
+ " \n" +
44
+ " system(\"git add .\") \n" +
45
+ " system(\"git commit -am \\\"deploy from \#{current_branch}\\\"\") \n" +
46
+ " system(\"git push \#{@remote_git} \#{current_branch}\") \n" +
47
+ " \n" +
48
+ " system(\"git tag -a \#{tag_name} -m \\\"tag :: deploy from branch: \#{current_branch}\\\"\") \n" +
49
+ " system(\"git push \#{@remote_git} \#{tag_name}\") \n" +
50
+ " \n" +
51
+ " end \n" +
52
+ " \n" +
53
+ " \n" +
54
+ " \n" +
55
+ "end \n"
56
+
57
+ File.delete("#{Rails.root}/script/lib/deploy/git_version_tag.rb") if File.exists?("#{Rails.root}/script/lib/deploy/git_version_tag.rb")
58
+
59
+ File.open("#{Rails.root}/script/lib/deploy/git_version_tag.rb", "w") do |f|
60
+ f.write("#{content}")
61
+ end
62
+
63
+ "#{Rails.root}/script/lib/deploy/git_version_tag.rb"
64
+ end
65
+
66
+
67
+ end
68
+
69
+
70
+
@@ -0,0 +1,157 @@
1
+ module AwsDeploy::Tasks::GenerateLocalDeployRb
2
+
3
+
4
+ #
5
+ #
6
+ def generate_local_deploy_rb
7
+
8
+ content =
9
+ "#!/usr/bin/env ruby \n" +
10
+ "# \n" +
11
+ "require 'FileUtils' \n" +
12
+ "require './lib/deploy/git_version_tag.rb' \n" +
13
+ "require './lib/deploy/aws_send.rb' \n" +
14
+ " \n" +
15
+ "# ------------------------------------------------------------------------------------- \n" +
16
+ "# CONFIGURABLE \n" +
17
+ "# ------------------------------------------------------------------------------------- \n" +
18
+ " \n" +
19
+ "zip_file = \"#{@project_name}\" \n" +
20
+ "md5_file = \"\#{zip_file}\" \n" +
21
+ " \n" +
22
+ "aws_access_key_id = \"#{@aws_access_key_id}\" \n" +
23
+ "aws_secret_access_key = \"#{@aws_secret_access_key}\" \n" +
24
+ "aws_bucket = \"#{@project_name}/deploy\" \n" +
25
+ " \n" +
26
+ "_temp_dir = \"\#{File.expand_path(\"~\")}/Temp/#{@project_name}\" \n" +
27
+ " \n" +
28
+ "# \n" +
29
+ "# ------------------------------------------------------------------------------------- \n" +
30
+ " \n" +
31
+ " \n" +
32
+ "time = Time.now.strftime(\"%y%m%d.%H%M%S\") \n" +
33
+ "public_dir = Dir.new(\"../public\") \n" +
34
+ " \n" +
35
+ "Dir.mkdir(_temp_dir) unless File.directory?(_temp_dir) \n" +
36
+ "temp_dir = \"\#{_temp_dir}/\#{time}\" \n" +
37
+ "# env = ARGV[0] \n" +
38
+ " \n" +
39
+ " \n" +
40
+ " \n" +
41
+ "puts \"------------------------------------------------------------------------------ \" \n" +
42
+ " \n" +
43
+ " \n" +
44
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
45
+ "puts \"3. Version.txt\" \n" +
46
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
47
+ " \n" +
48
+ "GitVersionTag.new(time, \"gitlab\", public_dir.path).version_it \n" +
49
+ " \n" +
50
+ " \n" +
51
+ " \n" +
52
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
53
+ "puts \"2. Git tag\" \n" +
54
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
55
+ " \n" +
56
+ "GitVersionTag.new(time, \"gitlab\", public_dir.path).tag_it \n" +
57
+ " \n" +
58
+ " \n" +
59
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
60
+ "puts \"3. Packing\" \n" +
61
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
62
+ " \n" +
63
+ " \n" +
64
+ " \n" +
65
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
66
+ "puts \"3.1 - Copying content to a temporary folder - \#{Time.now}\" \n" +
67
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
68
+ " \n" +
69
+ "Dir.mkdir(\"\#{temp_dir}\") \n" +
70
+ " \n" +
71
+ "exclude_dirs = [] \n" +
72
+ "exclude_dirs << \"ie7ref\" \n" +
73
+ "exclude_dirs << \".git\" \n" +
74
+ "exclude_dirs << \".gitignore\" \n" +
75
+ "exclude_dirs << \".autotest\" \n" +
76
+ "exclude_dirs << \"tmp\" \n" +
77
+ "exclude_dirs << \".svn\" \n" +
78
+ "exclude_dirs << \"wip\" \n" +
79
+ "exclude_dirs << \"log/*\" \n" +
80
+ "exclude_dirs << \"test/*\" \n" +
81
+ "exclude_dirs << \"script/security/*\" \n" +
82
+ "exclude_dirs << \"README.rdoc\" \n" +
83
+ "exclude_dirs << \"public/app\" \n" +
84
+ " \n" +
85
+ "rsync_command = \"rsync -avz --exclude '\#{exclude_dirs.join(\"' --exclude '\")}' ../ \#{temp_dir}\" \n" +
86
+ "system(\"\#{rsync_command}\") \n" +
87
+ " \n" +
88
+ " \n" +
89
+ " \n" +
90
+ " \n" +
91
+ " \n" +
92
+ " \n" +
93
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
94
+ "puts \"3.2 - Generating package - \#{Time.now}\" \n" +
95
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
96
+ " \n" +
97
+ "system(\"cd \#{temp_dir}; bundle install\") \n" +
98
+ "system(\"cd \#{temp_dir}; bundle exec rake assets:precompile --trace\") \n" +
99
+ "# system(\"rm -rf \#{temp_dir}/public/assets\") \n" +
100
+ "system(\"rm -rf \#{temp_dir}/../\#{zip_file}.zip\") \n" +
101
+ "system(\"cd \#{temp_dir}; zip -qr ../\#{zip_file}.zip ./*\") \n" +
102
+ " \n" +
103
+ " \n" +
104
+ " \n" +
105
+ " \n" +
106
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
107
+ "puts \"3.3 - Generating MD5 - \#{Time.now}\" \n" +
108
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
109
+ " \n" +
110
+ "system(\"rm -rf \#{temp_dir}/../\#{md5_file}.md5\") \n" +
111
+ "system(\"cd \#{temp_dir}; md5 <<< \\\"\#{Time.now}\\\" >> ../\#{md5_file}.md5\") \n" +
112
+ " \n" +
113
+ " \n" +
114
+ " \n" +
115
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
116
+ "puts \"4. AWS Send\" \n" +
117
+ "# puts \"------------------------------------------------------------------------------ \" \n" +
118
+ " \n" +
119
+ "AwsSend.new(aws_access_key_id, aws_secret_access_key).send(\"\#{temp_dir}/../\#{zip_file}.zip\", aws_bucket) \n" +
120
+ "AwsSend.new(aws_access_key_id, aws_secret_access_key).send(\"\#{temp_dir}/../\#{md5_file}.md5\", aws_bucket) \n" +
121
+ " \n" +
122
+ " \n" +
123
+ "puts \"------------------------------------------------------------------------------ \" \n"
124
+
125
+
126
+
127
+ File.delete("#{Rails.root}/script/deploy.rb") if File.exists?("#{Rails.root}/script/deploy.rb")
128
+
129
+ File.open("#{Rails.root}/script/deploy.rb", "w") do |f|
130
+ f.write("#{content}")
131
+ end
132
+
133
+ "#{Rails.root}/script/deploy.rb"
134
+ end
135
+
136
+
137
+
138
+ def collect_inputs__local_deploy_rb
139
+ print "Name of your project? [directory/deploy] :"
140
+ @project_name = STDIN.gets
141
+ @project_name = (@project_name.blank? ? "project_name" : @project_name)
142
+ puts "#{@project_name.gsub!("\n","")} \n"
143
+
144
+ end
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+ end
@@ -0,0 +1,134 @@
1
+ module AwsDeploy::Tasks::GenerateProductionCronCheckUpdates
2
+
3
+ #
4
+ #
5
+ def generate_production_cron_check_updates
6
+
7
+ content =
8
+ "#!/usr/bin/env ruby \n" +
9
+ "# \n" +
10
+ "require \"fileutils\" \n" +
11
+ "require \"aws-sdk\" \n" +
12
+ " \n" +
13
+ "# ------------------------------------------------------------------------------------- \n" +
14
+ "# CONFIGURABLE \n" +
15
+ "# ------------------------------------------------------------------------------------- \n" +
16
+ " \n" +
17
+ " AWS.config(:access_key_id => \"#{@aws_access_key_id}\", :secret_access_key => \"#{@aws_secret_access_key}\") \n" +
18
+ " \n" +
19
+ "base_dir = \"/app/deploy/\" \n" +
20
+ "project_name = \"#{@file_pattern}\" \n" +
21
+ "bucket = \"#{@file_pattern}/deploy\" \n" +
22
+ " \n" +
23
+ "# \n" +
24
+ "# ------------------------------------------------------------------------------------- \n" +
25
+ " \n" +
26
+ "s3_filename = \"nofile\" \n" +
27
+ " \n" +
28
+ "puts \"------------------------------------------------------------------------------ \" \n" +
29
+ " \n" +
30
+ "if \"\#{ARGV[0]}\".empty? \n" +
31
+ " puts \"ERR - Process stoped. Environment not defined.\" \n" +
32
+ " \n" +
33
+ "else \n" +
34
+ " if !%w(admin development_remote production staging).include?(\"\#{ARGV[0]}\") \n" +
35
+ " puts \"ERR - Invalid Environment: (\#{ARGV[0]})\" \n" +
36
+ " else \n" +
37
+ " \n" +
38
+ " s3_filename = \"\#{project_name}-\#{ARGV[0]}.zip\" \n" +
39
+ " s3_filename_md5 = \"\#{project_name}-\#{ARGV[0]}.md5\" \n" +
40
+ " \n" +
41
+ " \n" +
42
+ " # # puts \"------------------------------------------------------------------------------ \" \n" +
43
+ " puts \"1. Getting MD5 ... \#{bucket}/\#{s3_filename_md5}\" \n" +
44
+ " # # puts \"------------------------------------------------------------------------------ \" \n" +
45
+ " \n" +
46
+ " s3 = AWS::S3.new \n" +
47
+ " bucket = s3.buckets[\"\#{bucket}\"] \n" +
48
+ " \n" +
49
+ " obj = bucket.objects[s3_filename_md5] \n" +
50
+ " \n" +
51
+ " if obj.exists? \n" +
52
+ " File.delete(\"\#{base_dir}\#{s3_filename_md5}\") if File.exist?(\"\#{base_dir}\#{s3_filename_md5}\") \n" +
53
+ " \n" +
54
+ " File.open(\"\#{base_dir}\#{s3_filename_md5}\", 'wb') do |file| \n" +
55
+ " obj.read do |chunk| \n" +
56
+ " file.write(chunk) \n" +
57
+ " end \n" +
58
+ " end \n" +
59
+ " \n" +
60
+ " \n" +
61
+ " # # puts \"------------------------------------------------------------------------------ \" \n" +
62
+ " puts \"2. Checking MD5 ... \" \n" +
63
+ " \n" +
64
+ " # md5 checking... \n" +
65
+ " md5_file_data = File.read(\"\#{base_dir}\#{s3_filename_md5}\") \n" +
66
+ " \n" +
67
+ " if File.exist?(\"\#{base_dir}\#{s3_filename_md5}.local\") \n" +
68
+ " md5_local = File.read(\"\#{base_dir}\#{s3_filename_md5}.local\") \n" +
69
+ " else \n" +
70
+ " md5_local = \"new__\#{md5_file_data}\" \n" +
71
+ " end \n" +
72
+ " \n" +
73
+ " puts \" remote MD5: \#{md5_file_data}\" \n" +
74
+ " puts \" local MD5: \#{md5_local}\" \n" +
75
+ " \n" +
76
+ " \n" +
77
+ " # process the deployment... \n" +
78
+ " if md5_local != md5_file_data \n" +
79
+ " # # puts \"------------------------------------------------------------------------------ \" \n" +
80
+ " puts \"3. Downloading package \" \n" +
81
+ " \n" +
82
+ " obj = bucket.objects[s3_filename] \n" +
83
+ " \n" +
84
+ " if obj.exists? \n" +
85
+ " \n" +
86
+ " File.open(\"\#{base_dir}\#{s3_filename}\", 'w+b') do |file| \n" +
87
+ " obj.read do |chunk| \n" +
88
+ " file.write(chunk) \n" +
89
+ " end \n" +
90
+ " end \n" +
91
+ " \n" +
92
+ " # # puts \"------------------------------------------------------------------------------ \" \n" +
93
+ " puts \"4. Writing controls ... .log and .md5.local files \" \n" +
94
+ " \n" +
95
+ " \n" +
96
+ " system(\"echo \\\"\#{Time.now.strftime(\"%y%m%d_%H%M%S\")}\\\" >> \#{base_dir}\#{project_name}-\#{ARGV[0]}_YES.log\") \n" +
97
+ " # updating local MD5 \n" +
98
+ " File.open(\"\#{base_dir}\#{s3_filename_md5}.local\", 'w+') { |file| file.write(\"\#{md5_file_data}\") } \n " +
99
+ " \n" +
100
+ " puts \"5. Deploying....\" \n" +
101
+ " system(\"\#{base_dir}deploy.sh \#{ARGV[0]}\") \n " +
102
+ " \n" +
103
+ " else \n" +
104
+ " system(\"echo \\\"\#{Time.now.strftime(\"%y%m%d_%H%M%S\")}\\\" >> \#{base_dir}\#{project_name}-\#{ARGV[0]}_NO.log\") \n" +
105
+ " end \n" +
106
+ " else \n" +
107
+ " system(\"echo \\\"\#{Time.now.strftime(\"%y%m%d_%H%M%S\")}\\\" >> \#{base_dir}\#{project_name}-\#{ARGV[0]}_NO.log\") \n" +
108
+ " end \n" +
109
+ " else \n" +
110
+ " system(\"echo \\\"\#{Time.now.strftime(\"%y%m%d_%H%M%S\")}\\\" >> \#{base_dir}\#{project_name}-\#{ARGV[0]}_NO.log\") \n" +
111
+ " end \n" +
112
+ " \n" +
113
+ " end \n" +
114
+ " \n" +
115
+ "end \n" +
116
+ "puts \" ------------------------------------------------------------------------------ \" \n"
117
+
118
+ File.delete("#{Rails.root}/script/production/cron_check_updates.rb") if File.exists?("#{Rails.root}/script/production/cron_check_updates.rb")
119
+
120
+ File.open("#{Rails.root}/script/production/cron_check_updates.rb", "w") do |f|
121
+ f.write("#{content}")
122
+ end
123
+
124
+ "#{Rails.root}/script/production/cron_check_updates.rb"
125
+ end
126
+
127
+
128
+ end
129
+
130
+
131
+
132
+
133
+
134
+