Commit 8feb0cff by arquitecturati

Se aagrega readme y profiles en dockerfile

parent 56b79471
...@@ -21,3 +21,10 @@ KOHA_INTRA_SERVER_NAME=koha-intra.local ...@@ -21,3 +21,10 @@ KOHA_INTRA_SERVER_NAME=koha-intra.local
# Memcached (interno al contenedor — no cambiar) # Memcached (interno al contenedor — no cambiar)
MEMCACHED_SERVERS=127.0.0.1:11211 MEMCACHED_SERVERS=127.0.0.1:11211
# Timezone para conexiones MySQL/MariaDB
# Si la BD NO tiene cargadas las tablas mysql.time_zone* (típico en MariaDB
# self-hosted), usar un offset UTC: -05:00 para Bogotá (UTC-5, sin DST).
# Si la BD tiene las tablas cargadas (mysql_tzinfo_to_sql), se puede usar
# America/Bogota directamente.
KOHA_TIMEZONE=-05:00
...@@ -27,6 +27,15 @@ RUN wget -qO- https://debian.koha-community.org/koha/gpg.asc \ ...@@ -27,6 +27,15 @@ RUN wget -qO- https://debian.koha-community.org/koha/gpg.asc \
RUN apt-get update && apt-get install -y koha-common \ RUN apt-get update && apt-get install -y koha-common \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Bug en scripts shell de Koha: usan "xmlstarlet sel -t -v" sin -T, lo que
# re-escapa entidades XML al output (& → &). Passwords con caracteres
# como & quedan mal cuando koha-mysql los pasa al cliente mysql. Parche:
# agregar -T para que xmlstarlet emita texto plano decodificado.
RUN for f in /usr/sbin/koha-* /usr/share/koha/bin/*.sh; do \
[ -f "$f" ] && grep -q "xmlstarlet sel -t" "$f" && \
sed -i 's|xmlstarlet sel -t |xmlstarlet sel -T -t |g' "$f"; \
done; true
# List::MoreUtils: la versión de Ubuntu 20.04 no exporta zip6 correctamente. # List::MoreUtils: la versión de Ubuntu 20.04 no exporta zip6 correctamente.
# cpanm instala una versión consistente PP+XS desde CPAN. # cpanm instala una versión consistente PP+XS desde CPAN.
RUN apt-get update && apt-get install -y cpanminus build-essential && \ RUN apt-get update && apt-get install -y cpanminus build-essential && \
...@@ -54,7 +63,12 @@ RUN apt-get update && \ ...@@ -54,7 +63,12 @@ RUN apt-get update && \
echo "MySQL client activo: $(mysql --version)" echo "MySQL client activo: $(mysql --version)"
# Fase 3.7 — Habilitar módulos Apache requeridos # Fase 3.7 — Habilitar módulos Apache requeridos
RUN a2enmod rewrite cgi headers proxy_http # remoteip: leer X-Forwarded-For del ALB y reemplazar REMOTE_ADDR
RUN a2enmod rewrite cgi headers proxy_http remoteip
# Fase 3.8 — Configuración para ALB / reverse proxy
COPY docker/alb-proxy.conf /etc/apache2/conf-available/alb-proxy.conf
RUN a2enconf alb-proxy
# --- Archivos de migración --- # --- Archivos de migración ---
# SQL dump de la base de datos (Fase 4.1) # SQL dump de la base de datos (Fase 4.1)
......
This diff is collapsed. Click to expand it.
services: services:
# ------------------------------------------------------- # -------------------------------------------------------
# BD local para pruebas — reemplaza al RDS en desarrollo. # BD local para pruebas — solo activa con: --profile local
# Para usar RDS real: comentar este bloque y ajustar .env # Para RDS: no pasar el perfil y ajustar DB_HOST en .env
# ------------------------------------------------------- # -------------------------------------------------------
db: db:
profiles: ["local"]
image: mariadb:10.6 image: mariadb:10.6
environment: environment:
MYSQL_ROOT_PASSWORD: ${DB_ADMIN_PASSWORD} MYSQL_ROOT_PASSWORD: ${DB_ADMIN_PASSWORD}
...@@ -24,19 +25,38 @@ services: ...@@ -24,19 +25,38 @@ services:
ports: ports:
- "8080:80" - "8080:80"
env_file: .env env_file: .env
environment:
# Apuntar al servicio db local en vez del RDS
DB_HOST: db
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
required: false # ignorado cuando db no está activa (perfil RDS)
volumes: volumes:
# Persistir estado de inicialización, uploads, plugins e índices Zebra.
# Si se elimina este volumen, el entrypoint ejecuta la restauración completa.
- koha_data:/var/lib/koha - koha_data:/var/lib/koha
- koha_logs:/var/log/koha - koha_logs:/var/log/koha
restart: unless-stopped restart: unless-stopped
# -------------------------------------------------------
# Proxy nginx local — simula el ALB con terminación TLS.
# Solo activa con: --profile local
#
# Antes del primer uso ejecutar:
# bash docker/gen-local-certs.sh
#
# Flujo de prueba ALB:
# https://koha.local → nginx (443) → koha:80 (X-Forwarded-Proto: https)
# https://koha-intra.local → nginx (443) → koha:80 (X-Forwarded-Proto: https)
# -------------------------------------------------------
proxy:
profiles: ["local"]
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./docker/nginx-local.conf:/etc/nginx/nginx.conf:ro
- ./docker/certs:/etc/nginx/certs:ro
depends_on:
- koha
volumes: volumes:
db_data: db_data:
koha_data: koha_data:
......
...@@ -8,6 +8,28 @@ INIT_FLAG="/var/lib/koha/${INSTANCE}/.docker_initialized" ...@@ -8,6 +8,28 @@ INIT_FLAG="/var/lib/koha/${INSTANCE}/.docker_initialized"
echo "ServerName localhost" >> /etc/apache2/apache2.conf echo "ServerName localhost" >> /etc/apache2/apache2.conf
# ------------------------------------------------------- # -------------------------------------------------------
# Health check temporal — responde HTTP 200 en puerto 80
# desde el primer segundo del arranque, incluso durante el
# FIRST_RUN (DB restore puede tardar 10-20 min en ECS).
# ECS ve siempre 200 → no reinicia el task por timeout.
# Se mata justo antes de que Apache tome el puerto.
# -------------------------------------------------------
python3 -c "
import http.server, socketserver
class H(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'starting')
def log_message(self, *a): pass
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(('', 8099), H) as s:
s.serve_forever()
" &
HEALTHCHECK_PID=$!
echo "[koha] Health check temporal iniciado (pid ${HEALTHCHECK_PID})"
# -------------------------------------------------------
# Aplica variables de entorno sobre la plantilla koha-conf.xml. # Aplica variables de entorno sobre la plantilla koha-conf.xml.
# Se llama tanto en el primer arranque como en reinicios. # Se llama tanto en el primer arranque como en reinicios.
# ------------------------------------------------------- # -------------------------------------------------------
...@@ -15,16 +37,38 @@ apply_koha_config() { ...@@ -15,16 +37,38 @@ apply_koha_config() {
local tpl="/etc/koha/koha-conf.xml.tpl" local tpl="/etc/koha/koha-conf.xml.tpl"
local dst="/etc/koha/sites/${INSTANCE}/koha-conf.xml" local dst="/etc/koha/sites/${INSTANCE}/koha-conf.xml"
sed \ # Perl en vez de sed: el password puede tener caracteres que rompen sed
-e "s|<hostname>localhost</hostname>|<hostname>${DB_HOST}</hostname>|g" \ # (& en el reemplazo = "todo lo matcheado") y bash parameter expansion
-e "s|<port>3306</port>|<port>${DB_PORT:-3306}</port>|g" \ # también trata & especial. Perl hace XML-encoding y string replace limpio.
-e "s|<database>koha_prod_humboldt</database>|<database>${DB_NAME:-koha_prod_humboldt}</database>|g" \ DB_HOST="$DB_HOST" \
-e "s|<user>koha_prod_humboldt</user>|<user>${DB_USER:-koha_prod_humboldt}</user>|g" \ DB_PORT="${DB_PORT:-3306}" \
-e "s|<pass>KohaProd2026!Secure</pass>|<pass>${DB_PASSWORD}</pass>|g" \ DB_NAME="${DB_NAME:-koha_prod_humboldt}" \
-e "s|<memcached_servers>127\.0\.0\.1:11211</memcached_servers>|<memcached_servers>${MEMCACHED_SERVERS:-127.0.0.1:11211}</memcached_servers>|g" \ DB_USER="${DB_USER:-koha_prod_humboldt}" \
"${tpl}" > "${dst}" DB_PASSWORD="$DB_PASSWORD" \
MEMCACHED_SERVERS="${MEMCACHED_SERVERS:-127.0.0.1:11211}" \
echo "[koha] koha-conf.xml aplicado (DB_HOST=${DB_HOST})" KOHA_TIMEZONE="${KOHA_TIMEZONE:--05:00}" \
perl -p -e '
BEGIN {
for my $k (qw(DB_HOST DB_PORT DB_NAME DB_USER DB_PASSWORD MEMCACHED_SERVERS KOHA_TIMEZONE)) {
my $v = $ENV{$k};
$v =~ s/&/&amp;/g;
$v =~ s/</&lt;/g;
$v =~ s/>/&gt;/g;
$v =~ s/"/&quot;/g;
$v =~ s/\x27/&apos;/g;
$enc{$k} = $v;
}
}
s|<hostname>localhost</hostname>|<hostname>$enc{DB_HOST}</hostname>|g;
s|<port>3306</port>|<port>$enc{DB_PORT}</port>|g;
s|<database>koha_prod_humboldt</database>|<database>$enc{DB_NAME}</database>|g;
s|<user>koha_prod_humboldt</user>|<user>$enc{DB_USER}</user>|g;
s|<pass>KohaProd2026!Secure</pass>|<pass>$enc{DB_PASSWORD}</pass>|g;
s|<memcached_servers>127\.0\.0\.1:11211</memcached_servers>|<memcached_servers>$enc{MEMCACHED_SERVERS}</memcached_servers>|g;
s|<timezone>[^<]*</timezone>|<timezone>$enc{KOHA_TIMEZONE}</timezone>|g;
' "$tpl" > "$dst"
echo "[koha] koha-conf.xml aplicado (DB_HOST=$DB_HOST)"
} }
# ------------------------------------------------------- # -------------------------------------------------------
...@@ -123,7 +167,8 @@ if [ ! -f "${INIT_FLAG}" ]; then ...@@ -123,7 +167,8 @@ if [ ! -f "${INIT_FLAG}" ]; then
echo "SET sql_mode='';" echo "SET sql_mode='';"
zcat /migration/prod_humboldt-2026-04-30.sql.gz \ zcat /migration/prod_humboldt-2026-04-30.sql.gz \
| awk 'BEGIN{prev=""} /^\s*CONSTRAINT .* FOREIGN KEY/{sub(/,\s*$/,"",prev); if(prev!="") print prev; prev=""; next} {if(prev!="") print prev; prev=$0} END{if(prev!="") print prev}' \ | awk 'BEGIN{prev=""} /^\s*CONSTRAINT .* FOREIGN KEY/{sub(/,\s*$/,"",prev); if(prev!="") print prev; prev=""; next} {if(prev!="") print prev; prev=$0} END{if(prev!="") print prev}' \
| grep -v "ADD CONSTRAINT.*FOREIGN KEY" | grep -v "ADD CONSTRAINT.*FOREIGN KEY" \
| grep -Eiv "^\s*(GRANT|REVOKE|CREATE USER|DROP USER|ALTER USER|SET PASSWORD)\b"
echo "SET FOREIGN_KEY_CHECKS=1;" echo "SET FOREIGN_KEY_CHECKS=1;"
echo "SET UNIQUE_CHECKS=1;" echo "SET UNIQUE_CHECKS=1;"
} | koha-mysql "${INSTANCE}" } | koha-mysql "${INSTANCE}"
...@@ -190,16 +235,36 @@ if [ ! -f "${INIT_FLAG}" ]; then ...@@ -190,16 +235,36 @@ if [ ! -f "${INIT_FLAG}" ]; then
fi fi
# ------------------------------------------------------- # -------------------------------------------------------
# Sincronizar OPACBaseURL / staffClientBaseURL con las variables de entorno.
# Se ejecuta en cada arranque para que un cambio de dominio (ej. local → prod)
# se refleje sin entrar al panel de administración.
# Las URLs usan https:// porque el ALB siempre termina TLS; en local el nginx
# proxy también usa HTTPS, por lo que el esquema es siempre correcto.
# -------------------------------------------------------
koha-mysql "${INSTANCE}" -e "
UPDATE systempreferences
SET value='https://${KOHA_OPAC_SERVER_NAME}'
WHERE variable='OPACBaseURL';
UPDATE systempreferences
SET value='https://${KOHA_INTRA_SERVER_NAME}'
WHERE variable='staffClientBaseURL';" 2>/dev/null || true
# -------------------------------------------------------
# Limpiar PIDs stale de ejecuciones anteriores # Limpiar PIDs stale de ejecuciones anteriores
# ------------------------------------------------------- # -------------------------------------------------------
rm -f /var/run/koha/"${INSTANCE}"/*.pid 2>/dev/null || true rm -f /var/run/koha/"${INSTANCE}"/*.pid 2>/dev/null || true
# Garantizar permisos en logs para el usuario de la instancia (Plack escribe aquí)
chown -R "${INSTANCE}-koha:${INSTANCE}-koha" "/var/log/koha/${INSTANCE}/" 2>/dev/null || true
# ------------------------------------------------------- # -------------------------------------------------------
# Fase 5 — Arranque de servicios # Fase 5 — Arranque de servicios
# ------------------------------------------------------- # -------------------------------------------------------
# Pre-crear los archivos de log con ownership correcto ANTES de cualquier
# servicio. koha-plack --start dispara "apache2 restart" que crea opac-error.log
# e intranet-error.log como root; si ya existen con ownership prod_humboldt-koha
# Apache los abre en modo append sin cambiar el owner, y Plack puede escribir.
mkdir -p "/var/log/koha/${INSTANCE}"
touch "/var/log/koha/${INSTANCE}/opac-error.log" \
"/var/log/koha/${INSTANCE}/intranet-error.log"
chown -R "${INSTANCE}-koha:${INSTANCE}-koha" "/var/log/koha/${INSTANCE}/"
echo "[koha] Iniciando Memcached..." echo "[koha] Iniciando Memcached..."
service memcached start service memcached start
...@@ -226,8 +291,10 @@ echo "[koha] OPAC: http://${KOHA_OPAC_SERVER_NAME:-koha.local}" ...@@ -226,8 +291,10 @@ echo "[koha] OPAC: http://${KOHA_OPAC_SERVER_NAME:-koha.local}"
echo "[koha] Intranet: http://${KOHA_INTRA_SERVER_NAME:-koha-intra.local}" echo "[koha] Intranet: http://${KOHA_INTRA_SERVER_NAME:-koha-intra.local}"
echo "" echo ""
# koha-plack --start hace service apache2 restart en Koha 25.11. # Liberar puerto 80 antes de que Apache arranque en foreground
# Detener y limpiar antes de tomar el control en foreground. kill "${HEALTHCHECK_PID}" 2>/dev/null || true
wait "${HEALTHCHECK_PID}" 2>/dev/null || true
service apache2 stop 2>/dev/null || true service apache2 stop 2>/dev/null || true
rm -f /var/run/apache2/apache2.pid 2>/dev/null || true rm -f /var/run/apache2/apache2.pid 2>/dev/null || true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment