e2ed15341b134ff8cdd74bb974192fe5449cfe30
4 Copyright 2008 Grégory Burri
6 This file is part of Euphorik.
8 Euphorik is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Euphorik is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
23 # - création de unit tests (voir eunit) et validation avant la mise en prod
25 # Met à disposition plusieurs outils (classes), tel que :
26 # - Vérification du code javascript
27 # - Mise à jour du numéro de version à partir du fichier VERSION
28 # - Mise en production et en preproduction
29 # tools.rb peut s'utiliser à la ligne de commande, exemples :
30 # * Mise en production :
31 # ./tools.rb prod gburri@euphorik.ch:/var/www/euphorik
32 # * Mise en préproduction, l'emplacement de production peut être indiqué pour copier la base
33 # ./tools.rb pre gburri@euphorik.ch:/var/www/euphorik_preprod gburri@euphorik.ch:/var/www/euphorik
35 # voir : http://net-ssh.rubyforge.org/ssh/v2/api/index.html
38 # Classe permettant la vérification du code JS pas jslint.
39 # Passe en revu chaque fichier js de manière récursive à partir d'un dossier de départ.s
42 def initialize(dossier
)
47 verifierRecur(@dossier)
50 def verifierRecur(dossier
)
51 Dir
.foreach(dossier
){|fichier
|
52 cheminComplet
= "#{dossier}/#{fichier}"
53 if fichier
[0,1] !
= '.' and File
.directory
?(cheminComplet
) and fichier !
= 'libs'
54 if not verifierRecur(cheminComplet
)
57 elsif fichier
[-3, 3] == '.js'
58 puts
"== Vérification de #{cheminComplet} =="
59 # TODO : mettre un if pour la version windows si dessous
60 #system("java org.mozilla.javascript.tools.shell.Main jslint.js #{cheminComplet}")
61 system("rhino ./tools/jslint.js #{cheminComplet}")
72 # Classe de gestion de la version
74 # @param dossier la racine du site (par exemple "/var/www/euphorik")
75 def initialize(dossier
)
77 File
.open(@dossier +
'/VERSION') {|file
|
78 @version = file
.readline()
80 # les fichiers HTML dans lesquels mettre à jour la version
81 @fichiers = ['/pages/about.html']
82 @balise = /(<span.+?class.*?=.*?"version".*?>).*?(<\/span
>)/
85 # met à jour la version dans les fichiers @fichiers
87 @fichiers.each
{|fichier
|
88 fichier
= @dossier + fichier
89 lines
= IO
.readlines(fichier
)
90 File
.open(fichier
, 'w') {|io
|
92 io
.write(l
.sub(@balise){|m
| $1 +
@version +
$2})
99 # Permet la mise en production et preproduction
102 @
@rep_remote = '/var/www/euphorik'
103 @
@host = 'euphorik.ch'
105 def initialize(racine
)
109 # L'emplacement ou sont copié les fichiers
110 # A définir avant la mise en prod
112 plop
= uri
.split(':')
117 # Effectue la mise en production.
123 # Effectue la mise en préproduction.
131 compiler_partie_serveuse()
132 creer_repertoire_bd()
133 copier_partie_statique()
135 copie_modules_serveurs()
136 set_droits_fichiers()
145 system("rsync tools/yaws.conf #{@uri}:#{@rep}/tools")
146 system("rsync tools/start_yaws.sh #{@uri}:#{@rep}/tools")
150 system("ssh #{@uri} \"cd #{@rep} && #{commande}\"")
155 exec("test -d #{rep} || mkdir #{rep}")
160 def compiler_partie_serveuse
163 if $
?.exitstatus !
= 0
164 puts
"Echec de compilation de la partie serveuse"
170 def creer_repertoire_bd
171 # création du repertoire BD
173 creer_rep('BD/backups')
174 exec("chmod -R g+w BD
")
177 # css, images, html, etc..
178 def copier_partie_statique
179 uri = "#{@uri}:#{@rep}"
180 system("awk
'$0 !~
/prod=\"delete\"/' index.yaws | ssh #{@uri} \" cat > #{@rep}/index.yaws\"")
181 system("rsync favicon.ico #{uri}")
182 system("rsync --delete -r styles #{uri}")
183 system("rsync --delete -r pages #{uri}")
184 system("rsync --delete -r --exclude 'autres
' img #{uri}")
187 # minification et package des fichiers js dans euphorik.js
191 # jquery.js et euphorik.js doivent se trouve en premier
192 fichiers = ['js
/libs
/jquery
.js
', 'js
/euphorik
.js
'].concat(get_fichiers_js(rep_js))
193 commande_cat = "cat "
195 commande_cat += f +
" "
197 #copie des js concaténés avec minification
198 system("#{commande_cat} | tools/jsmin.rb | ssh #{@uri} \"cd #{@rep} && cat > #{rep_js}/euphorik.js\"")
201 #renvoie une liste des fichiers js
202 def get_fichiers_js(rep
)
204 Dir
.entries(rep
).each
{|fichier
|
205 if fichier
[0..0] !
= '.' and fichier !
= 'euphorik.js' and fichier !
= 'jquery.js'
206 fichier
= rep +
"/" + fichier
207 if File
.directory
?(fichier
)
208 fichiers
.concat(get_fichiers_js(fichier
))
217 def copie_modules_serveurs
218 # copie des modules erlang
220 system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
221 system("rsync -r modules/include #{@uri}:#{@rep}/modules")
224 def set_droits_fichiers
225 # attribution des droits
226 exec("chmod -R g+rx
.")
230 # execution du script de mise à jour
231 system("cat tools
/mise_en_prod
.erl
| ssh
#{@uri} \"cat
> /tmp
/mise_en_prod
.erl
\"")
232 system("ssh
#{@uri} \"chmod u+x
/tmp/mise_en_prod
.erl
; /tmp/mise_en_prod
.erl
; rm
/tmp/mise_en_prod
.erl
\"")
237 # Traite la ligne de commande lorsque tools.rb est utilisé comme tel
241 @miseEnProd = MiseEnProd.new(".")
242 @verifJS = VerifJS.new("js
")
243 @version = Version.new(".")
255 @miseEnProd.uri = "gburri
@euphorik.ch
:/var/www
/euphorik
"
256 @miseEnProd.miseEnProd()
259 @miseEnProd.uri = "gburri
@euphorik.ch
:/var/www
/euphorik_preprod
"
260 @miseEnProd.miseEnPreProd()
268 Net::SSH.start('euphorik.ch', 'gburri') {|ssh|
269 output = ssh.exec!("hostname")
271 ssh
.exec!
("ls -l /tmp"){|channel
, stream
, data|
272 stdout << data if stream
== :stdout
280 puts
"Usage : tools.rb (prod | pre | js | version)\n" +
281 " prod : Mise en production\n" +
282 " pre : Mise en préproduction, copie les données en production\n" +
283 " js : vérification des fichiers JavaScript\n" +
284 " version : met à jour la version à partir du fichier VERSION"