Files
rkm-conectasus-ci-sandbox/docker/entrypoint.sh
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

64 lines
2.2 KiB
Bash

#!/bin/bash
set -euo pipefail
APP_PATH="/var/www/api"
FRONTEND_PATH="/var/www/frontend"
log() { echo "[entrypoint] $*"; }
fail() { echo "[entrypoint][ERRO] $*" >&2; exit 1; }
cd "$APP_PATH"
if [ ! -f "${APP_PATH}/.env" ]; then
fail "${APP_PATH}/.env nao encontrado. Monte o arquivo em runtime (bind mount/secret)."
fi
# Config de runtime do frontend. Fica FORA do dist de proposito: o dist traz um
# config.js vazio (placeholder de desenvolvimento), e exigir o arquivo montado
# num caminho separado e o que permite distinguir "montado" de "nao montado".
# Sem isso, um deploy sem o mount subiria silenciosamente apontando para lugar
# nenhum, em vez de falhar.
if [ ! -f "${FRONTEND_PATH}/config.js" ]; then
fail "${FRONTEND_PATH}/config.js nao encontrado. Monte a config de runtime do frontend (modelo em docker/config.js.example)."
fi
if ! grep -q '__APP_CONFIG__' "${FRONTEND_PATH}/config.js"; then
fail "${FRONTEND_PATH}/config.js nao define window.__APP_CONFIG__."
fi
# Instala no dist, de onde o Apache serve e o index.html carrega.
cp "${FRONTEND_PATH}/config.js" "${FRONTEND_PATH}/dist/config.js"
if [ ! -f "${APP_PATH}/connections.json" ]; then
fail "${APP_PATH}/connections.json nao encontrado. config/database.php le esse arquivo no boot; sem ele a aplicacao nao sobe."
fi
if ! php -r 'json_decode(file_get_contents("connections.json"), true); exit(json_last_error() === JSON_ERROR_NONE ? 0 : 1);'; then
fail "connections.json presente mas com JSON invalido."
fi
mkdir -p \
storage/framework/cache \
storage/framework/views \
storage/framework/sessions \
storage/logs \
storage/app/public \
storage/app/documento \
storage/app/intranet \
bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || \
log "AVISO: nao foi possivel ajustar o dono de storage/ (mount read-only?). Seguindo."
chmod -R ug+rwX storage bootstrap/cache 2>/dev/null || true
php artisan config:clear >/dev/null 2>&1 || true
if [ "${CACHE_CONFIG:-false}" = "true" ]; then
log "CACHE_CONFIG=true -> gerando bootstrap/cache/config.php"
php artisan config:cache
fi
log "API ${APP_VERSION:-dev} pronta. Iniciando: $*"
exec "$@"