ADD: Implementación de MongoDB y conexión con compass

This commit is contained in:
Juan Felipe Zapata Moreno 2025-10-16 15:55:19 -06:00
parent e8da447b68
commit 2bb87e7daf
10 changed files with 391 additions and 132 deletions

View File

@ -1,7 +1,7 @@
server {
listen 80;
server_name _;
root /var/www/golscontrols/public;
root /var/www/repuve-v1/public;
index index.php index.html;
# Logging
@ -17,7 +17,7 @@ server {
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass golscontrols:9000;
fastcgi_pass repuve-backend:9000;
fastcgi_index index.php;
# Timeouts importantes para evitar errores 500
@ -45,17 +45,17 @@ server {
# Handle storage files (Laravel storage link)
location /storage {
alias /var/www/golscontrols/storage/app;
alias /var/www/repuve-v1/storage/app;
try_files $uri =404;
}
location /profile {
alias /var/www/golscontrols/storage/app/profile;
alias /var/www/repuve-v1/storage/app/profile;
try_files $uri =404;
}
location /images {
alias /var/www/golscontrols/storage/app/images;
alias /var/www/repuve-v1/storage/app/images;
try_files $uri =404;
}

View File

@ -0,0 +1,82 @@
<?php namespace App\Http\Controllers\Repuve;
/**
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
*/
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Notsoweb\ApiResponse\Enums\ApiResponse;
class RepuveController extends Controller
{
/**
* Obtener información de vehículo (datos hardcodeados)
*/
public function information()
{
$data = [
"ANIO_PLACA" => "2020",
"PLACA" => "WNU700B",
"NO_SERIE" => "LSGHD52H0ND032457",
"RFC" => "GME111116GJA",
"FOLIO" => "3962243",
"VIGENCIA" => "2025",
"FECHA_IMPRESION" => "10-01-2025",
"QR_HASH" => "Vu5TF4kYsbbltzjDdGQyenKfZoIk2wro34a5Gkh9JVh0CFxfPlrd92YEWK21JF.nLjQNyzKmqRvWYuPiS.kU7A--",
"VALIDO" => true,
"FOLIOTEMP" => false,
"NOMBRE" => "GOLSYSTEMS DE MEXICO S DE RL DE CV",
"NOMBRE2" => "GOLS*MS DXICOE RL*CV",
"MUNICIPIO" => "CENTRO",
"LOCALIDAD" => "VILLAHERMOSA",
"CALLE" => "C BUGAMBILIAS 118 ",
"CALLE2" => "C BU*ILIA*18 ",
"TIPO" => "SEDAN",
"TIPO_SERVICIO" => "PARTICULAR",
"MARCA" => "CHEVROLET G.M.C.",
"LINEA" => "AVEO",
"SUBLINEA" => "PAQ. \"A\" LS",
"MODELO" => 2022,
"NUMERO_SERIE" => "LSGHD52H0ND032457",
"NUMERO_MOTOR" => "H. EN WUHANLL,SGM",
"DESCRIPCION_ORIGEN" => "IMPORTADO",
"COLOR" => "BLANCO",
"CODIGO_POSTAL" => "86179",
"SERIE_FOLIO" => "D3962243",
"SFOLIO" => "3962243"
];
return ApiResponse::OK->response($data);
}
public function store(Request $request)
{
$data = $request->all();
$data['ID'] = rand(1000, 9999);
$data['created_at'] = now()->toDateTimeString();
return ApiResponse::OK->response([
'message' => 'Información almacenada correctamente',
'data' => $data
]);
}
public function update(Request $request, $id)
{
$data = $this->information();
$updata['ID'] = $id;
$updata['updated_at'] = now()->toDateTimeString();
return ApiResponse::OK->response([
'message' => 'Información actualizada correctamente',
'data' => $updata
]);
}
public function delete($id)
{
return ApiResponse::OK->response([
'message' => "Información con ID {$id} eliminada correctamente"
]);
}
}

View File

@ -12,6 +12,7 @@
"laravel/pulse": "^1.4",
"laravel/reverb": "^1.4",
"laravel/tinker": "^2.10",
"mongodb/laravel-mongodb": "^5.0",
"notsoweb/laravel-core": "dev-main",
"spatie/laravel-permission": "^6.16",
"tightenco/ziggy": "^2.5"

268
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0cdf26aa072a7f833793cfba72e94e81",
"content-hash": "f2d5ed49c5f41d77138255d29d89b754",
"packages": [
{
"name": "brick/math",
@ -2968,6 +2968,192 @@
],
"time": "2025-04-12T22:26:52+00:00"
},
{
"name": "mongodb/laravel-mongodb",
"version": "5.5.0",
"source": {
"type": "git",
"url": "https://github.com/mongodb/laravel-mongodb.git",
"reference": "c483b99a69ea9916d17719b86e7e5ea2f8b44c8a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mongodb/laravel-mongodb/zipball/c483b99a69ea9916d17719b86e7e5ea2f8b44c8a",
"reference": "c483b99a69ea9916d17719b86e7e5ea2f8b44c8a",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2.0.0",
"ext-mongodb": "^1.21|^2",
"illuminate/cache": "^10.36|^11|^12",
"illuminate/container": "^10.0|^11|^12",
"illuminate/database": "^10.30|^11|^12",
"illuminate/events": "^10.0|^11|^12",
"illuminate/support": "^10.0|^11|^12",
"mongodb/mongodb": "^1.21|^2",
"php": "^8.1",
"symfony/http-foundation": "^6.4|^7"
},
"conflict": {
"illuminate/bus": "< 10.37.2"
},
"replace": {
"jenssegers/mongodb": "self.version"
},
"require-dev": {
"doctrine/coding-standard": "12.0.x-dev",
"laravel/scout": "^10.3",
"league/flysystem-gridfs": "^3.28",
"league/flysystem-read-only": "^3.0",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.3|^11.5.3",
"rector/rector": "^1.2",
"spatie/laravel-query-builder": "^5.6|^6"
},
"suggest": {
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"MongoDB\\Laravel\\MongoDBServiceProvider",
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"MongoDB\\Laravel\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Andreas Braun",
"email": "andreas.braun@mongodb.com",
"role": "Leader"
},
{
"name": "Pauline Vos",
"email": "pauline.vos@mongodb.com",
"role": "Maintainer"
},
{
"name": "Jérôme Tamarelle",
"email": "jerome.tamarelle@mongodb.com",
"role": "Maintainer"
},
{
"name": "Jeremy Mikola",
"email": "jmikola@gmail.com",
"role": "Maintainer"
},
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com",
"role": "Creator"
}
],
"description": "A MongoDB based Eloquent model and Query builder for Laravel",
"homepage": "https://github.com/mongodb/laravel-mongodb",
"keywords": [
"database",
"eloquent",
"laravel",
"model",
"mongo",
"mongodb"
],
"support": {
"issues": "https://www.mongodb.com/support",
"security": "https://www.mongodb.com/security",
"source": "https://github.com/mongodb/laravel-mongodb/tree/5.5.0"
},
"time": "2025-08-12T05:06:10+00:00"
},
{
"name": "mongodb/mongodb",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/mongodb/mongo-php-library.git",
"reference": "f399d24905dd42f97dfe0af9706129743ef247ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/f399d24905dd42f97dfe0af9706129743ef247ac",
"reference": "f399d24905dd42f97dfe0af9706129743ef247ac",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2.0",
"ext-mongodb": "^2.1",
"php": "^8.1",
"psr/log": "^1.1.4|^2|^3",
"symfony/polyfill-php85": "^1.32"
},
"replace": {
"mongodb/builder": "*"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"phpunit/phpunit": "^10.5.35",
"rector/rector": "^1.2",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "6.5.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"MongoDB\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Andreas Braun",
"email": "andreas.braun@mongodb.com"
},
{
"name": "Jeremy Mikola",
"email": "jmikola@gmail.com"
},
{
"name": "Jérôme Tamarelle",
"email": "jerome.tamarelle@mongodb.com"
}
],
"description": "MongoDB driver library",
"homepage": "https://jira.mongodb.org/browse/PHPLIB",
"keywords": [
"database",
"driver",
"mongodb",
"persistence"
],
"support": {
"issues": "https://github.com/mongodb/mongo-php-library/issues",
"source": "https://github.com/mongodb/mongo-php-library/tree/2.1.1"
},
"time": "2025-08-13T20:50:05+00:00"
},
{
"name": "monolog/monolog",
"version": "3.9.0",
@ -6970,6 +7156,86 @@
],
"time": "2024-09-09T11:45:10+00:00"
},
{
"name": "symfony/polyfill-php85",
"version": "v1.33.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php85.git",
"reference": "d4e5fcd4ab3d998ab16c0db48e6cbb9a01993f91"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/d4e5fcd4ab3d998ab16c0db48e6cbb9a01993f91",
"reference": "d4e5fcd4ab3d998ab16c0db48e6cbb9a01993f91",
"shasum": ""
},
"require": {
"php": ">=7.2"
},
"type": "library",
"extra": {
"thanks": {
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Php85\\": ""
},
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 8.5+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php85/tree/v1.33.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2025-06-23T16:12:55+00:00"
},
{
"name": "symfony/polyfill-uuid",
"version": "v1.32.0",

View File

@ -112,6 +112,22 @@
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
],
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('MONGO_DSN', null),
'host' => env('MONGO_HOST', '127.0.0.1'),
'port' => env('MONGO_PORT', '27017'),
'database' => env('MONGO_DATABASE', 'holos'),
'username' => env('MONGO_USERNAME', null),
'password' => env('MONGO_PASSWORD', null),
'options' => [
'ssl' => env('MONGO_SSL', true),
'authSource' => env('MONGO_AUTH_SOURCE', 'admin'),
'retryWrites' => env('MONGO_RETRY_WRITES', true),
'w' => env('MONGO_W', 'majority'),
],
],
],
/*

View File

@ -2,7 +2,7 @@ services:
repuve-backend:
build:
context: .
dockerfile: dockerfile.dev
dockerfile: dockerfile
working_dir: /var/www/repuve-v1
environment:
- DB_HOST=mysql
@ -18,8 +18,6 @@ services:
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
nginx:
image: nginx:alpine
@ -63,24 +61,9 @@ services:
networks:
- repuve-network
redis:
image: redis:alpine
ports:
- "${REDIS_PORT}:6379"
volumes:
- redis_data:/data
networks:
- repuve-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
timeout: 5s
retries: 5
volumes:
mysql_data:
driver: local
redis_data:
driver: local
networks:
repuve-network:

View File

@ -14,10 +14,15 @@ RUN apt-get update && apt-get install -y\
unzip \
libzip-dev\
nano \
openssl
openssl \
libssl-dev \
libcurl4-openssl-dev \
pkg-config
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
RUN pecl install mongodb && docker-php-ext-enable mongodb
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.lock ./
@ -26,6 +31,8 @@ RUN composer install --optimize-autoloader --no-interaction --no-scripts
COPY . .
RUN chown -R www-data:www-data /var/www/repuve-v1
COPY entrypoint-dev.sh /usr/local/bin/entrypoint-dev.sh
RUN chmod +x /usr/local/bin/entrypoint-dev.sh

View File

@ -5,6 +5,9 @@ git config --global --add safe.directory /var/www/repuve-v1
echo "=== Iniciando entrypoint DESARROLLO ==="
chown -R www-data:www-data /var/www/repuve-v1/storage /var/www/repuve-v1/bootstrap/cache
chmod -R 775 /var/www/repuve-v1/storage /var/www/repuve-v1/bootstrap/cache
# Variables desde Docker environment
DB_HOST=${DB_HOST:-mysql}
DB_USERNAME=${DB_USERNAME:-root}

View File

@ -1,105 +0,0 @@
#!/bin/bash
set -e
echo "=== Iniciando entrypoint ==="
# Variables desde Docker environment
DB_HOST=${DB_HOST:-mysql}
DB_USERNAME=${DB_USERNAME:-root}
DB_PASSWORD=${DB_PASSWORD:-}
DB_DATABASE=${DB_DATABASE:-laravel}
MAX_RETRIES=30
RETRY_COUNT=0
echo "Configuración de BD: Host=${DB_HOST}, Usuario=${DB_USERNAME}, Base=${DB_DATABASE}"
# Función para verificar conectividad con MySQL usando PHP
check_mysql() {
php -r "
try {
\$pdo = new PDO('mysql:host=${DB_HOST};port=3306', '${DB_USERNAME}', '${DB_PASSWORD}');
\$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
exit(0);
} catch (Exception \$e) {
exit(1);
}
"
}
# Esperar a que MySQL esté disponible
echo "Esperando conexión a MySQL..."
until check_mysql; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "ERROR: No se pudo conectar a MySQL después de $MAX_RETRIES intentos"
exit 1
fi
echo "Intento $RETRY_COUNT/$MAX_RETRIES - Esperando a MySQL..."
sleep 2
done
echo "✓ MySQL está disponible"
# Comandos de inicialización
echo "Ejecutando comandos de inicialización..."
echo "Ejecutando package:discover..."
php artisan package:discover --ansi
echo "Creando enlaces simbólicos..."
php artisan storage:link --force || true
echo "Ejecutando configuración de producción..."
composer run env:prod
echo "Creando directorio de claves Passport..."
mkdir -p storage/app/keys
echo "Generando claves de Passport..."
php artisan passport:keys --force || true
# Verificar que las claves se crearon
if [ ! -f "storage/app/keys/oauth-private.key" ] || [ ! -f "storage/app/keys/oauth-public.key" ]; then
echo "ERROR: Las claves de Passport no se generaron correctamente"
echo "Intentando generar manualmente..."
# Generar claves manualmente usando OpenSSL
openssl genrsa -out storage/app/keys/oauth-private.key 4096
openssl rsa -in storage/app/keys/oauth-private.key -pubout -out storage/app/keys/oauth-public.key
echo "✓ Claves generadas manualmente"
fi
# Establecer permisos correctos para las claves
chmod 600 storage/app/keys/oauth-private.key
chmod 644 storage/app/keys/oauth-public.key
chown www-data:www-data storage/app/keys/oauth-*.key
echo "✓ Claves de Passport verificadas"
# Archivo de control para primera ejecución
FIRST_RUN_FLAG="/var/www/holos.backend/.first_run_completed"
# Solo en la primera ejecución
if [ ! -f "$FIRST_RUN_FLAG" ]; then
echo "=== PRIMERA EJECUCIÓN DETECTADA ==="
echo "Ejecutando migraciones y seeders..."
if composer run db:prod; then
echo "✓ db:prod completado"
else
echo "ERROR: Falló db:prod"
exit 1
fi
# Marcar como completado
touch "$FIRST_RUN_FLAG"
echo "✓ Primera ejecución completada exitosamente"
else
echo "✓ No es primera ejecución, omitiendo setup inicial"
fi
echo "=== Iniciando PHP-FPM ==="
# Iniciar PHP-FPM
exec "$@"

View File

@ -1,16 +1,17 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Repuve\RepuveController;
/**
* Rutas del núcleo de la aplicación.
*
*
* Se recomienda que no se modifiquen estas rutas a menos que sepa lo que está haciendo.
*/
require('core.php');
/**
* Rutas de tu aplicación.
*
*
* Estas rutas son de la aplicación AP I que desarrollarás. Siéntete libre de agregar lo que consideres necesario.
* Procura revisar que no existan rutas que entren en conflicto con las rutas del núcleo.
*/
@ -22,3 +23,8 @@
/** Rutas públicas */
// Tus rutas públicas
Route::get('information', [RepuveController::class, 'information']);
Route::post('information', [RepuveController::class, 'store']);
Route::put('information/{id}', [RepuveController::class, 'update']);
Route::delete('information/{id}', [RepuveController::class, 'delete']);