From eb8708a7450d6c5147613fab28678b206aeb7c7e Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 17 Aug 2008 20:17:58 +0000 Subject: [PATCH] MOD avancement dans le processus de mise en production (pas fini) --- VERSION | 2 +- js/conf.js | 2 +- js/euphorik.js | 3 +- js/formateur.js | 2 +- tools/mise_en_prod.erl | 2 +- tools/tools.rb | 124 +++++++++++++++++++++++++++++------------ tools/yaws.conf | 7 +-- 7 files changed, 95 insertions(+), 47 deletions(-) diff --git a/VERSION b/VERSION index 30290a6..1cc5f65 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0a \ No newline at end of file +1.1.0 \ No newline at end of file diff --git a/js/conf.js b/js/conf.js index b67fac0..6ab068b 100644 --- a/js/conf.js +++ b/js/conf.js @@ -1,5 +1,5 @@ // coding: utf-8 -// Copyright 2008 Gr�gory Burri +// Copyright 2008 Grégory Burri // // This file is part of Euphorik. // diff --git a/js/euphorik.js b/js/euphorik.js index 00227cd..214c0f8 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -57,7 +57,6 @@ $(document).ready( $("#menu .register").click(function(){ pages.afficherPage("register"); }); $("#menu .about").click(function(){ pages.afficherPage("about"); }); - // TODO : simplifier et pouvoir créer des liens par exemple : Conditions d'utilisation $("#footer .conditions").click(function(){ pages.afficherPage("conditions_utilisation"); }); @@ -70,4 +69,4 @@ $(document).ready( pages.afficherPage(); } -); \ No newline at end of file +); diff --git a/js/formateur.js b/js/formateur.js index 72ecfad..b7ec0eb 100644 --- a/js/formateur.js +++ b/js/formateur.js @@ -159,7 +159,7 @@ euphorik.Formateur.prototype.supprimerSmiles = function(m) { } }); return m; -} +}; /** * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox. diff --git a/tools/mise_en_prod.erl b/tools/mise_en_prod.erl index 680384a..2b9cb17 100755 --- a/tools/mise_en_prod.erl +++ b/tools/mise_en_prod.erl @@ -12,6 +12,6 @@ main(_) -> receive {'EXIT', _, _} -> io:format("mise à jour de la BD..~n"), - spawn(yaws@overnux, euphorik_bd_update, update, []) + spawn(yaws@overnux, euphorik_bd_admin, update, []) end. diff --git a/tools/tools.rb b/tools/tools.rb index 804dac7..a70442e 100644 --- a/tools/tools.rb +++ b/tools/tools.rb @@ -57,7 +57,7 @@ class VerifJS puts "== Vérification de #{dossier}/#{fichier} ==" # TODO : mettre un if pour la version windows si dessous #system("java org.mozilla.javascript.tools.shell.Main jslint.js #{dossier}/#{fichier}") - system("rhino jslint.js #{dossier}/#{fichier}") + system("rhino ./tools/jslint.js #{dossier}/#{fichier}") # puts $?.exitstatus if $?.exitstatus > 0 return false @@ -70,7 +70,7 @@ end # Classe de gestion de la version class Version - # @param dossier la racine du site (par exemple "/var/www/euphorik" + # @param dossier la racine du site (par exemple "/var/www/euphorik") def initialize(dossier) @dossier = dossier File.open(@dossier + '/VERSION') {|file| @@ -100,31 +100,64 @@ class MiseEnProd # obsolète ! @@rep_remote = '/var/www/euphorik' @@host = 'euphorik.ch' - @@opt_rsync = '' - def initialize(prod_uri, preprod_uri) - @prod = prod_uri - @preprod = preprod_uri + def initialize(racine) + Dir.chdir(racine) end + # L'emplacement ou sont copié les fichiers + # A définir avant la mise en prod + def uri=(uri) + plop = uri.split(':') + @uri = plop[0] + @rep = plop[1] + end + # Effectue la mise en production. def miseEnProd + copierFichiers() + maj() end # Effectue la mise en préproduction. def miseEnPreProd + copierFichiers() + copierBD() + lancerYaws() + end + + def copierFichiers + compiler_partie_serveuse() + creer_repertoire_bd() + copier_partie_statique() + pack_js() + copie_modules_serveurs() + set_droits_fichiers() + end + + def copierBD + end + + def lancerYaws + creer_rep("tools") + system("rsync tools/yaws.conf #{@uri}:#{@rep}/tools") + system("rsync tools/start_yaws.sh #{@uri}:#{@rep}/tools") + end + + def exec(commande) + system("ssh #{@uri} \"cd #{@rep} && #{commande}\"") end - def creer_remote_rep(rep) + def creer_rep(rep) begin - `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"` + exec("test -d #{rep} || mkdir #{rep}") rescue end end def compiler_partie_serveuse - Dir.chdir(@@rep_remote + '/modules') - puts `make` + Dir.chdir('modules') + system("make") if $?.exitstatus != 0 puts "Echec de compilation de la partie serveuse" exit 1 @@ -134,49 +167,67 @@ class MiseEnProd def creer_repertoire_bd # création du repertoire BD - creer_remote_rep('BD') - creer_remote_rep('BD/backup') - `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"` + creer_rep('BD') + creer_rep('BD/backups') + exec("chmod -R g+w BD") end # css, images, html, etc.. - def copier_partie_statique - print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}` + def copier_partie_statique + uri = "#{@uri}:#{@rep}" + system("awk '$0 !~ /prod=\"delete\"/' index.yaws | ssh #{@uri} \" cat > #{@rep}/index.yaws\"") + system("rsync favicon.ico #{uri}") + system("rsync --delete -r styles #{uri}") + system("rsync --delete -r pages #{uri}") + system("rsync --delete -r --exclude 'autres' img #{uri}") end # minification et package des fichiers js dans euphorik.js def pack_js - # copie des js avec minification rep_js = 'js' - creer_remote_rep(rep_js) - Dir.entries(rep_js).each{|fichier| - if fichier[0..0] != '.' and fichier != 'debug.js' - puts "Minimisation et copie de #{fichier}" - print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"` + creer_rep(rep_js) + # jquery.js et euphorik.js doivent se trouve en premier + fichiers = ['js/libs/jquery.js', 'js/euphorik.js'].concat(get_fichiers_js(rep_js)) + commande_cat = "cat " + fichiers.each{|f| + commande_cat += f + " " + } + #copie des js concaténés avec minification + system("#{commande_cat} | tools/jsmin.rb | ssh #{@uri} \"cd #{@rep} && cat > #{rep_js}/euphorik.js\"") + end + + #renvoie une liste des fichiers js + def get_fichiers_js(rep) + fichiers = [] + Dir.entries(rep).each{|fichier| + if fichier[0..0] != '.' and fichier != 'euphorik.js' and fichier != 'jquery.js' + fichier = rep + "/" + fichier + if File.directory?(fichier) + fichiers.concat(get_fichiers_js(fichier)) + else + fichiers << fichier + end end } + return fichiers end def copie_modules_serveurs # copie des modules erlang - creer_remote_rep('modules') - `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules` - `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules` + creer_rep('modules') + system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules") + system("rsync -r modules/include #{@uri}:#{@rep}/modules") end def set_droits_fichiers # attribution des droits - `ssh #{$host} "chmod -R g+rx #{$rep_remote}"` + exec("chmod -R g+rx .") end def maj # execution du script de mise à jour - print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"` - print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"` + system("cat tools/mise_en_prod.erl | ssh #{@uri} \"cat > /tmp/mise_en_prod.erl\"") + system("ssh #{@uri} \"chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl\"") end end @@ -184,12 +235,9 @@ end # Traite la ligne de commande lorsque tools.rb est utilisé comme tel class Commande def initialize - @miseEnProd = MiseEnProd.new( - "gburri@euphorik.ch:/var/www/euphorik", - "gburri@euphorik.ch:/var/www/euphorik_preprod" - ) - @verifJS = VerifJS.new("../js") - @version = Version.new("..") + @miseEnProd = MiseEnProd.new("/home/gburri/projets/euphorik/trunk") + @verifJS = VerifJS.new("js") + @version = Version.new(".") end def traiter @@ -201,9 +249,11 @@ class Commande case ARGV[0] when 'prod' @version.maj() + @miseEnProd.uri = "gburri@euphorik.ch:/var/www/euphorik" @miseEnProd.miseEnProd() when 'pre' @version.maj() + @miseEnProd.uri = "gburri@euphorik.ch:/var/www/euphorik_preprod" @miseEnProd.miseEnPreProd() when 'js' @verifJS.verifier() diff --git a/tools/yaws.conf b/tools/yaws.conf index 81a96bb..6c0994d 100644 --- a/tools/yaws.conf +++ b/tools/yaws.conf @@ -3,16 +3,15 @@ logdir = /tmp ebin_dir = /usr/lib/yaws/ebin -ebin_dir = /home/gburri/projets/euphorik/trunk/modules/ebin +ebin_dir = ../modules/ebin include_dir = /usr/lib/yaws/include -include_dir = /home/gburri/projets/euphorik/trunk/modules/include - +include_dir = ../modules/include port = 8090 listen = 0.0.0.0 - docroot = /home/gburri/projets/euphorik/trunk + docroot = .. allowed_scripts = yaws appmods = start_mod = euphorik_daemon -- 2.43.0