-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorre
executable file
·118 lines (98 loc) · 3.57 KB
/
corre
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env ruby
# Ejecuta aplicación usando Procfile de ser posible
# Si hay un archivo .env toma variables de configuración de ese
# Las variables usadas son:
# RAILS_ENV: Modo de ejecución development, production (o test que no se usa)
# RC: Script de arranque en modo producción en /etc/rc.d/
# PUERTODES: En modo desarrollo puerto por usar
# IPDES: En modo desarrollo IP por usar
# R: Si tiene un valor ejecuta rápido (no instala dependencias ni elimina caches ni regenera recursos)
# Aunque si el valor es r recompila (sin eliminar dependencias)
# Y si el valor es f o si no hay Procfile no intenta correr con foreman
require 'fileutils'
#require 'byebug'
# ENV.each {|l,v| puts "#{l}=#{v}" } # Depuración
# Ruta a directorio raíz de aplicación
RAIZ_AP = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Falló la orden #{args} ==")
end
FileUtils.chdir RAIZ_AP do
if File.exist?('./.env')
require 'dotenv'
Dotenv.load
end
if !ENV['RC'] || ENV['RC'] == ''
nap=`git remote -v | grep "(fetch)" | sed -e "s/.*\\/\\(.*\\) (fetch)/\\1/g"`
if !nap || nap == ''
nap = 'apconsip'
end
ENV['RC'] = nap.strip
end
puts "\n== Ejecutando aplicacion #{ENV['RC']} =="
if !File.exist?('/tmp/node')
puts "\n== Enlace a /usr/local/bin/node desde /tmp =="
system! 'doas ln -s /usr/local/bin/node /tmp'
end
if !ENV['RAILS_ENV'] || ENV['RAILS_ENV'] == ''
ENV['RAILS_ENV'] = 'development'
end
if !ENV['PUERTODES']
ENV['PUERTODES'] = '2300'
end
if !ENV['IPDES'] || ENV['IPDES'] == ''
ENV['IPDES'] = '127.0.0.1'
end
if !ENV['R'] || ENV['R'] == ''
puts "\n== Instalando dependencias =="
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Instala dependencias Javascript
system! 'CXX=c++ bin/yarn'
puts "\n== Preparando base de datos =="
system! "RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails db:prepare"
puts "\n== Actualizando índices =="
system!("RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails msip:indices")
puts "\n== Eliminando bitácoras y archivos temporales =="
system! 'bin/rails log:clear tmp:clear'
end
if !ENV['R'] || ENV['R'] == '' || ENV['R'] == 'r'
puts "\n== Eliminando recursos public/packs* y public/#{ENV['RUTA_RELATIVA']}/assets/* =="
system! 'rm -rf public/packs*'
system! "rm -rf public/#{ENV['RUTA_RELATIVA']}/assets/*"
system! "rm -rf app/assets/builds/*"
puts "\n== Enlaza controladores stimulus de motores =="
system! 'bin/rails msip:stimulus_motores'
puts "\n== Crea recursos CSS y Javascript =="
system! "RAILS_ENV=#{ENV['RAILS_ENV']} bin/rails assets:precompile --trace"
end
if ENV['RAILS_ENV'] == "development"
puts "\n== Ejecutando en modo desarrollo =="
if File.exist?('Procfile') && ENV['R'] != 'f'
ord="foreman start -f Procfile"
else
ord = ""
if ENV['CONFIG_HOSTS'] && ENV['CONFIG_HOSTS'] != ''
ord += "CONFIG_HOSTS=\"#{ENV['CONFIG_HOSTS'].downcase}\" "
end
ord += "RAILS_RELATIVE_URL_ROOT='' "
ord += "bin/rails s "
if ENV['PUERTODES'] != ''
ord += "-p #{ENV['PUERTODES']} "
end
ord += "-b '#{ENV['IPDES']}' "
end
puts "#{ord}"
elsif ENV['RAILS_ENV'] == 'production'
if File.exist?('bin/corre-local')
system!('bin/corre-local')
end
if !File.exist?("/etc/rc.d/#{ENV['RC']}")
puts "\nFalta script /etc/rc.d/#{ENV['RC']}"
exit 1
end
puts "\n== Ejecutando en modo producción =="
ord = "doas rcctl -d start #{ENV['RC']}"
end
system!(ord)
end