d95156cfdd786699ae0201239da025b8a2d0e7a1
[euphorik.git] / tools / mise_en_prod.rb
1 #!/usr/bin/ruby
2 =begin
3 Copyright 2008 Grégory Burri
4
5 This file is part of Euphorik.
6
7 Euphorik is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Euphorik is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 $rep_remote = '/var/www/euphorik'
22 $host = 'euphorik.ch'
23 $opt_rsync = ''
24
25
26 #TODO
27 # - mettre à jour les numéros de versions en appelant le script "cope_num_version.rb"
28 # - création de unit tests (voir eunit) et validation avant la mise en prod
29
30 def creer_remote_rep(rep)
31 begin
32 `ssh #{$host} "mkdir #{$rep_remote}/#{rep}"`
33 rescue
34 end
35 end
36
37
38 # Compilation de la partie serveur
39 Dir.chdir('../modules')
40 puts `make`
41 if $?.exitstatus != 0
42 puts "Echec de compilation de la partie serveuse"
43 exit 1
44 end
45 Dir.chdir('..')
46
47 # création du repertoire BD
48 creer_remote_rep('BD')
49 `ssh #{$host} "chmod g+w #{$rep_remote}/BD"`
50
51 # copie de la partie statique : css, images, html, etc..
52 print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
53 print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
54 print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
55 print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
56 print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
57
58 # copie des js avec minification
59 rep_js = 'js'
60 creer_remote_rep(rep_js)
61 Dir.entries(rep_js).each{|fichier|
62 if fichier[0..0] != "." and fichier != "debug.js"
63 puts "Minimisation et copie de #{fichier}"
64 print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{$host} "cat > #{$rep_remote}/#{rep_js}/#{fichier}"`
65 end
66 }
67
68 # copie des modules erlang
69 creer_remote_rep('modules')
70 `rsync #{$opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{$host}:#{$rep_remote}/modules`
71 `rsync #{$opt_rsync} -r modules/include #{$host}:#{$rep_remote}/modules`
72
73 # attribution des droits
74 `ssh #{$host} "chmod -R g+rx #{$rep_remote}"`
75
76 # execution du script de mise à jour
77 print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`
78 print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`