akitaonrails-locarails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ bin/locarails
2
+ bin/locarails.cmd
3
+ LICENSE
4
+ Manifest
5
+ README
6
+ locarails.gemspec
7
+ lib/locarails.rb
8
+ lib/locarails/version.rb
9
+ templates/database.locaweb.yml
10
+ templates/deploy.rb
11
+ templates/locaweb_backup.rb
data/README ADDED
@@ -0,0 +1,65 @@
1
+ = locarails
2
+
3
+ * http://www.locaweb.com.br/rails
4
+
5
+ == DESCRICAO:
6
+
7
+ Facilitar a instalacao de aplicacoes Rails na hospedagem Linux da
8
+ Locaweb. Configura receita de Capistrano padrao que deve funcionar
9
+ na maioria dos cenarios
10
+
11
+ == SINOPSE:
12
+
13
+ cd seu_projeto_rails
14
+ locarails .
15
+ cap deploy:setup
16
+ cap deploy
17
+
18
+ == AVISOS:
19
+
20
+ * Não use o locarails se voce ja tem Capistrano instalado no seu
21
+ projeto. Este programa tem como objetivo ajudar quem nao conhece
22
+ nada a respeito de Capistrano
23
+ * Tenha em maos as seguintes informacoes:
24
+ - seu usuario de hospedagem (o usuario da conta linux, nao o
25
+ usuario de cliente)
26
+ - seus dados de MySQL (usuario, senha, servidor, nome do banco)
27
+ * Crie o apontamento do seu dominio via o Painel da Locaweb em
28
+ painel.locaweb.com.br e aponte para o diretorio /public_html/app
29
+ sendo 'app' o nome da sua aplicacao
30
+
31
+ == REQUERIMENTOS:
32
+
33
+ * Estar em Linux (Ubuntu ou outros) ou Mac OS X
34
+ * Ter Ruby instalado (sudo apt-get install ruby1.8 ruby1.8-dev)
35
+ * Ter Rails instalado (sudo gem install rails)
36
+ * Ter Capistrano instalado (sudo gem install capistrano)
37
+
38
+ == INSTALL:
39
+
40
+ * gem install akitaonrails-locarails --source=http://gems.github.com
41
+
42
+ == LICENSE:
43
+
44
+ (The MIT License)
45
+
46
+ Copyright (c) 2008 Fabio Akita
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of this software and associated documentation files (the
50
+ 'Software'), to deal in the Software without restriction, including
51
+ without limitation the rights to use, copy, modify, merge, publish,
52
+ distribute, sublicense, and/or sell copies of the Software, and to
53
+ permit persons to whom the Software is furnished to do so, subject to
54
+ the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/locarails ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-8-19.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'ostruct'
13
+ require 'optparse'
14
+
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Uso: #{File.basename($0)} [caminho]"
17
+
18
+ opts.on("-h", "--help", "Mostra esta tela de ajuda") do
19
+ puts opts
20
+ exit 0
21
+ end
22
+
23
+ begin
24
+ opts.parse!(ARGV)
25
+ rescue OptionParser::ParseError => e
26
+ warn e.message
27
+ puts opts
28
+ exit 1
29
+ end
30
+ end
31
+
32
+ if ARGV.empty?
33
+ abort "Por favor, especifique o diretorio do seu projeto Rails, e.g. `#{File.basename($0)} .'"
34
+ elsif !File.exists?(ARGV.first)
35
+ abort "`#{ARGV.first}' nao existe. Tente novamente."
36
+ elsif !File.directory?(ARGV.first)
37
+ abort "`#{ARGV.first}' nao eh um diretorio. Tente novamente."
38
+ elsif ARGV.length > 1
39
+ abort "Argumentos demais; por favor especifique somente o diretorio da aplicacao Rails.."
40
+ end
41
+
42
+ def get_input(message)
43
+ print "* #{message} > "
44
+ gets.strip
45
+ end
46
+
47
+ # configuracoes da sua hospedagem
48
+ config = OpenStruct.new
49
+ mysqlcfg = OpenStruct.new
50
+
51
+ # configuracoes locais da sua maquina
52
+ config.bin_path = File.dirname(File.expand_path(__FILE__))
53
+ config.local_path = File.expand_path(ARGV.shift)
54
+ config.app_name = config.local_path.split('/').last
55
+
56
+ if File.exists?(File.join(config.local_path, 'config/deploy.rb'))
57
+ abort "Voce ja tem capistrano configurado em config/deploy.rb. Configuracao abortada."
58
+ end
59
+
60
+ puts <<-STR
61
+ ==================================================
62
+ Bem Vindos ao configurador de projetos da Locaweb
63
+ Vamos configurar seu projeto Rails para melhor se
64
+ Adequar nas nossas hospedagens Linux compartilhada
65
+ Para tanto precisaremos de algumas informacoes:
66
+ ==================================================
67
+
68
+ Garanta que a seguinte pasta contem sua aplicacao
69
+ Rails: #{config.local_path}
70
+
71
+ STR
72
+
73
+ # configuracoes inseridas manualmente pelo usuario
74
+ config.app_name = get_input( "O nome da sua aplicacao" ) if config.app_name.nil? || config.app_name.empty?
75
+ config.dominio = get_input "O dominio do seu site (ex. teste.tempsite.ws)"
76
+ config.usuario = get_input "Seu usuario de hospedagem"
77
+ mysqlcfg.db = get_input "O nome do seu banco mysql"
78
+ mysqlcfg.user = get_input "Seu usuario de mysql"
79
+ mysqlcfg.pass = get_input "Sua senha de mysql"
80
+ mysqlcfg.host = get_input "Seu servidor mysql (ex. mysqlxxx.locaweb.com.br)"
81
+
82
+ # forca rodar capistrano
83
+ unless File.exists?("#{config.local_path}/Capfile")
84
+ puts "- Executando Capistrano no seu projeto ..."
85
+ `capify .`
86
+ end
87
+
88
+ FileUtils.copy_file("#{config.bin_path}/../templates/locaweb_backup.rb",
89
+ "#{config.local_path}/config/locaweb_backup.rb")
90
+
91
+ File.open("#{config.local_path}/config/deploy.rb", 'w+') do |out|
92
+ buffer = File.open("#{config.bin_path}/../templates/deploy.rb", 'r') do | f |
93
+ f.read.gsub('seu.usuario', config.usuario).
94
+ gsub('seu.dominio', config.dominio).
95
+ gsub('sua.aplicacao', config.app_name).
96
+ gsub('seu.projeto', config.local_path)
97
+ end
98
+ out.puts buffer
99
+ end
100
+
101
+ File.open("#{config.local_path}/config/database.locaweb.yml", 'w+') do |out|
102
+ buffer = File.open("#{config.bin_path}/../templates/database.locaweb.yml", 'r') do | f |
103
+ f.read.gsub('mysql.database', mysqlcfg.db).
104
+ gsub('mysql.username', mysqlcfg.user).
105
+ gsub('mysql.password', mysqlcfg.pass).
106
+ gsub('mysql.hostname', mysqlcfg.host)
107
+ end
108
+ out.puts buffer
109
+ end
110
+
111
+ puts <<-STR
112
+
113
+ # Parabéns, voce terminou de configurar sua aplicacao Rails!
114
+ # Para configurar sua hospedagem execute 'cap deploy:setup'.
115
+ # Para subir seu projeto execute 'cap deploy'
116
+ [finalizado!]
117
+ STR
data/bin/locarails.cmd ADDED
@@ -0,0 +1 @@
1
+ @ruby "C:/ruby/bin/locarails" %*
data/lib/locarails.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Locarails
5
+
6
+ end
@@ -0,0 +1,9 @@
1
+ module Locarails
2
+ module VERSION #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/locarails.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{locarails}
3
+ s.version = "1.0.0"
4
+
5
+ s.specification_version = 2 if s.respond_to? :specification_version=
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Fabio Akita"]
9
+ s.date = %q{2008-08-19}
10
+ s.default_executable = %q{locarails}
11
+ s.description = %q{A maneira mais simples para instalar aplicacoes Rails na hospedagem Linux da Locaweb.}
12
+ s.email = %q{fabio.akita@locaweb.com.br}
13
+ s.executables = ["locarails"]
14
+ s.files = ["bin/locarails", "bin/locarails.cmd", "LICENSE", "Manifest", "README", "lib/locarails.rb", "lib/locarails/version.rb", "templates/database.locaweb.yml", "templates/deploy.rb", "templates/locaweb_backup.rb", "locarails.gemspec"]
15
+ s.has_rdoc = true
16
+ s.homepage = %q{http://www.locaweb.com.br/rails}
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{locarails}
19
+ s.rubygems_version = %q{1.1.1}
20
+ s.summary = %q{Configuracao de Capistrano automatica para hospedagens Linux Locaweb.}
21
+ end
@@ -0,0 +1,7 @@
1
+ production:
2
+ adapter: mysql
3
+ encoding: utf8
4
+ database: mysql.database
5
+ username: mysql.username
6
+ password: mysql.password
7
+ host: mysql.hostname
@@ -0,0 +1,146 @@
1
+ # =============================================================================
2
+ # Receita de Capistrano 2.x para hospedagem compartilhada Linux
3
+ # utilizando estratégia de cópia sem servidor de versionamento
4
+ # =============================================================================
5
+ #
6
+ # Para que esta receita funcione realize os seguintes passos:
7
+ #
8
+ # 1. copie o arquivo backup_locaweb.rb no diretorio 'config' de sua aplicacao
9
+ # 2. crie um arquivo 'config/database.locaweb.yml' configurando de acordo com
10
+ # os dados de sua hospedagem (que você recebeu por e-mail com o título de
11
+ # "Instrucoes - MySQL - Incluso"). Um exemplo seria assim:
12
+ #
13
+ # production:
14
+ # adapter: mysql
15
+ # encoding: utf8
16
+ # database: railsdemo
17
+ # username: railsdemo
18
+ # password: xxxxxxxxx
19
+ # host: mysql1179.locaweb.com.br
20
+ #
21
+ # 3. se você estiver utilizando subversion, git ou outro versionador, garanta
22
+ # que os arquivos 'config/database.yml' e o 'config/database.locaweb.yml'
23
+ # estão na lista de arquivos ignorados. Eh boa pratica nao mante-los num
24
+ # repositorio
25
+ # 4. garanta que voce tem capistrano instalado executando 'sudo gem install
26
+ # capistrano'
27
+ # 5. garanta que, a partir do diretorio do seu projeto, voce executou o comando
28
+ # 'capify .' para que o capistrano se configure corretamente no seu projeto
29
+ # 6. substitua o arquivo 'config/deploy.rb' gerado, por este arquivo que voce
30
+ # baixou da Locaweb
31
+ # 7. altere o arquivo 'config/deploy.rb' conforme o exemplo abaixo:
32
+ #
33
+ # set :user, "railsdemo"
34
+ # set :domain, "railsdemo.tecnologia.ws"
35
+ # set :application, "demo"
36
+ # set :repository, "~/Sites/rails/demo"
37
+ #
38
+ # Note que 'application' eh o nome do diretorio que voce configurou no
39
+ # Painel de Controle da Locaweb, onde ele mostra /public_html/demo, por
40
+ # exemplo.
41
+ #
42
+ # 8. Feito isso digite 'cap deploy:setup'. Isso deve ser executado apenas uma vez
43
+ # para que toda a configuracao necessaria seja feita na sua hospedagem
44
+ #
45
+ # 9. Finalmente, para colocar sua aplicação em produção, apenas execute
46
+ # 'cap deploy'. Se nada der errado, já deve estar tudo no ar.
47
+ #
48
+ # 10. Se em algum momento, voce notar que a instalacao atual subiu com problemas
49
+ # sempre podera voltar atras usando o comando 'cap deploy:rollback', garantindo
50
+ # que problemas inesperados nao o deixem fora do ar.
51
+ #
52
+ # Autor: Fabio Akita
53
+ # E-mail: fabio.akita@locaweb.com.br
54
+ # Locaweb Serviços de Internet S/A
55
+ # Todos os direitos reservados
56
+
57
+ # =============================================================================
58
+ # CONFIGURE OS VALORES DE ACORDO COM SUA HOSPEDAGEM
59
+ # =============================================================================
60
+ set :user, "seu.usuario"
61
+ set :domain, "seu.dominio"
62
+ set :application, "sua.aplicacao"
63
+ set :repository, "seu.projeto"
64
+ #ssh_options[:keys] = File.expand_path("~/.ssh/id_rsa") # apenas descomente se tiver chave
65
+
66
+ # =============================================================================
67
+ # NAO MEXER DAQUI PARA BAIXO
68
+ # =============================================================================
69
+ role :web, domain
70
+ role :app, domain
71
+ role :db, domain
72
+
73
+ set :deploy_to, "/home/#{user}/rails_app/#{application}"
74
+ set :public_html, "/home/#{user}/public_html"
75
+ set :site_path, "#{public_html}/#{application}"
76
+ set :runner, nil
77
+ set :use_sudo, false
78
+ set :no_release, true
79
+
80
+ set :scm, :none # nenhum repositorio
81
+ set :deploy_via, :copy
82
+ set :copy_exclude, %w(.git/* .svn/* log/* tmp/*)
83
+
84
+ ssh_options[:username] = user
85
+ ssh_options[:paranoid] = false
86
+
87
+ set :backup_rb, "#{deploy_to}/current/config/locaweb_backup.rb"
88
+
89
+ # =============================================================================
90
+ # TAREFAS - NAO MEXER A MENOS QUE SAIBA O QUE ESTA FAZENDO
91
+ # =============================================================================
92
+ desc "Garante que o database.yml foi corretamente configurado"
93
+ task :before_symlink do
94
+ on_rollback {}
95
+ run "test -d #{release_path}/tmp || mkdir -m 755 #{release_path}/tmp"
96
+ run "cp #{deploy_to}/etc/database.yml #{release_path}/config/database.yml"
97
+ run "cd #{release_path} && rake db:migrate RAILS_ENV=production"
98
+ end
99
+
100
+ desc "Garante que as configuracoes estao adequadas"
101
+ task :before_setup do
102
+ ts = Time.now.strftime("%y%m%d%H%M%S")
103
+ run "if [ -d #{deploy_to} ]; then mv #{deploy_to} #{deploy_to}-#{ts}.old ; fi"
104
+ run "test -d #{deploy_to} || mkdir -m 755 #{deploy_to}"
105
+ run "test -d #{deploy_to}/etc || mkdir -m 755 #{deploy_to}/etc"
106
+ run "if [ -d #{site_path} ]; then mv #{site_path} #{site_path}-#{ts}.old ; fi"
107
+ run "if [ -h #{site_path} ]; then mv #{site_path} #{site_path}-#{ts}.old ; fi"
108
+ run "ln -s #{deploy_to}/current/public #{public_html}/#{application}"
109
+ put File.read(File.dirname(__FILE__) + "/database.locaweb.yml"), "#{deploy_to}/etc/database.yml"
110
+ end
111
+
112
+ desc "Prepare the production database before migration"
113
+ task :before_cold do
114
+ end
115
+
116
+ namespace :deploy do
117
+ desc "Pede restart ao servidor Passenger"
118
+ task :restart, :roles => :app do
119
+ run "touch #{deploy_to}/current/tmp/restart.txt"
120
+ end
121
+ end
122
+
123
+ [:start, :stop].each do |t|
124
+ desc "A tarefa #{t} nao eh necessaria num ambiente com Passenger"
125
+ task t, :roles => :app do ; end
126
+ end
127
+
128
+ namespace :log do
129
+ desc "tail production log files"
130
+ task :tail, :roles => :app do
131
+ run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
132
+ puts # para uma linha extra
133
+ puts "#{channel[:host]}: #{data}"
134
+ break if stream == :err
135
+ end
136
+ end
137
+ end
138
+
139
+ namespace :db do
140
+ desc "Faz o backup remoto do banco de dados MySQL e ja faz o download"
141
+ task :backup, :roles => :db do
142
+ run "if [ -f #{backup_rb} ]; then ruby #{backup_rb} #{deploy_to} ; fi"
143
+ get "#{deploy_to}/etc/dump.tar.gz", "dump.tar.gz"
144
+ run "rm #{deploy_to}/etc/dump.tar.gz"
145
+ end
146
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby -wKU
2
+ require 'yaml'
3
+
4
+ deploy_to = ARGV[0]
5
+ cfg = YAML::load(File.open("#{deploy_to}/etc/database.yml"))
6
+ exit! unless cfg['production'] # sai se nao encontrar o arquivo de banco
7
+
8
+ cfg = cfg['production']
9
+ cmd_mysql = "mysqldump -u #{cfg['username']} -p#{cfg['password']} -h #{cfg['host']} #{cfg['database']} > #{deploy_to}/etc/dump.sql"
10
+ cmd_compress = "cd #{deploy_to}/etc && tar cvfz dump.tar.gz dump.sql"
11
+ cmd_rm = "rm #{deploy_to}/etc/dump.sql"
12
+
13
+ puts "executing: #{cmd_mysql.gsub(cfg['password'], 'xxxxxxxx')}"
14
+ `#{cmd_mysql}`
15
+ puts "executing: #{cmd_compress}"
16
+ `#{cmd_compress}`
17
+ puts "executing: #{cmd_rm}"
18
+ `#{cmd_rm}`
19
+ puts "db backup finished."
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akitaonrails-locarails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Akita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-19 00:00:00 -07:00
13
+ default_executable: locarails
14
+ dependencies: []
15
+
16
+ description: A maneira mais simples para instalar aplicacoes Rails na hospedagem Linux da Locaweb.
17
+ email: fabio.akita@locaweb.com.br
18
+ executables:
19
+ - locarails
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/locarails
26
+ - bin/locarails.cmd
27
+ - LICENSE
28
+ - Manifest
29
+ - README
30
+ - lib/locarails.rb
31
+ - lib/locarails/version.rb
32
+ - templates/database.locaweb.yml
33
+ - templates/deploy.rb
34
+ - templates/locaweb_backup.rb
35
+ - locarails.gemspec
36
+ has_rdoc: true
37
+ homepage: http://www.locaweb.com.br/rails
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: locarails
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Configuracao de Capistrano automatica para hospedagens Linux Locaweb.
62
+ test_files: []
63
+