Files
Investidor-V2/outputs/offers-preinstall-verification-20261114/preflight-reviewed.sh
T

31 lines
4.9 KiB
Bash

set -eu
python3 - <<'REMOTE'
import json,pathlib,subprocess,os
assert os.environ.get('SSH_CONNECTION')
root=pathlib.Path('/var/www/html/teste-investidor.tempo.co.mz/current').resolve()
php=r"""<?php
require 'vendor/autoload.php';$app=require 'bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Schema;
DB::beginTransaction();DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
try{
$id=DB::selectOne('select current_database() as database,inet_server_port() as port');if($id->database!=='teste_investidor'||(int)$id->port!==5432)throw new RuntimeException('Wrong source');
$tables=['opportunities'=>['management_version','workflow_context','owner_user_id','organization_id','management_draft'], 'users'=>['portal_access_revision'],'portal_role_assignments'=>['role','opportunity_types'],'portal_superuser_pair'=>[], 'portal_profile_requests'=>[], 'portal_security_approvals'=>[], 'opportunity_images'=>[], 'opportunity_documents'=>[], 'opportunity_locations'=>[], 'documents'=>['storage_encryption','malware_scan_status','malware_scanned_sha256'],'portal_editorial_editions'=>[], 'portal_editorial_notifications'=>['opportunity_id','opportunity_version','content_hash'],'audit_events'=>[], 'tasks'=>[], 'desk_cases'=>['payload','simulation_id'], 'investor_navigation_preferences'=>[], 'simulation_form_drafts'=>[]];
$schema=[];foreach($tables as $table=>$columns){$exists=Schema::hasTable($table);$schema[$table]=['exists'=>$exists,'missing_columns'=>$exists?array_values(array_filter($columns,fn($c)=>!Schema::hasColumn($table,$c))):$columns];}
$offer=Schema::hasColumn('opportunities','workflow_context')?DB::selectOne("select count(*) filter(where workflow_context->'private_offer_preparation' is not null) as private_offers,count(*) filter(where workflow_context->'private_offer_preparation' is not null and (status='published' or published_at is not null)) as unexpected_published,count(*) filter(where workflow_context->'offer_publication' is not null) as stored_projections from opportunities"):null;
$routes=[];foreach($app->make('router')->getRoutes() as $route){if(str_contains($route->uri(),'ofertas')||str_contains($route->uri(),'offers'))$routes[]=['uri'=>$route->uri(),'methods'=>$route->methods(),'action'=>$route->getActionName()];}
$recipients=config('portal.notification_recipients',[]);sort($recipients);
echo json_encode(['database'=>$id,'php'=>PHP_VERSION,'gd'=>extension_loaded('gd'),'imagecreatefromstring'=>function_exists('imagecreatefromstring'),'imagewebp'=>function_exists('imagewebp'),'schema'=>$schema,'offers'=>$offer,'offer_routes'=>$routes,'flags'=>['profile_access'=>(bool)config('portal.profile_access_enabled'),'editorial'=>(bool)config('editorial_workflow.enabled'),'notifications'=>(bool)config('portal.notifications_enabled'),'homologation_only'=>(bool)config('portal.homologation_only'),'homologation_access_mode'=>config('portal.homologation_access_mode'),'nda_present'=>config('private_offers.nda')!==null,'expiry_scheduler'=>(bool)config('private_offers.expiry_scheduler_enabled',false)],'mail'=>['mailer'=>config('mail.default'),'smtp_host_configured'=>(bool)config('mail.mailers.smtp.host'),'recipient_count'=>count($recipients),'recipient_set_sha256'=>hash('sha256',json_encode($recipients))],'runtime'=>['queue'=>config('queue.default'),'private_disk'=>config('filesystems.default'),'scanner_host_configured'=>(bool)config('services.malware.host'),'scanner_socket_configured'=>(bool)config('services.malware.socket')],'migration_count'=>DB::table('migrations')->count(),'config_cached'=>$app->configurationIsCached(),'operational_data_writes'=>0],JSON_THROW_ON_ERROR);
}finally{DB::rollBack();}
"""
q=json.loads(subprocess.check_output(['php8.4'],input=php.encode(),cwd=root,timeout=90))
info=subprocess.run(['php-fpm8.4','-i'],capture_output=True,text=True,timeout=20).stdout
q['fpm_image_capabilities']={'gd_enabled':'GD Support => enabled' in info,'webp_enabled':'WebP Support => enabled' in info}
units=subprocess.run(['systemctl','list-units','--type=service','--all','--plain','--no-legend'],capture_output=True,text=True,timeout=15).stdout.splitlines()
q['service_units']=[' '.join(line.split()[:4]) for line in units if any(x in line.lower() for x in ['teste-investidor','investmoz','nginx','php8.4','postgresql','clamav'])]
config=json.loads(pathlib.Path('/etc/investmoz-deploy/delivery.json').read_text());q['restore_image']=config.get('postgis_image');q['executor_config_keys']=sorted(config)
installed=json.loads(pathlib.Path('/var/lib/investmoz-deploy/installed.json').read_text());q['installed_revision']=installed.get('commit')
rev=root/'public/build/revision.json';q['served_build_revision']=json.loads(rev.read_text()).get('commit') if rev.exists() else None
q['executor_service_state']=subprocess.run(['systemctl','is-active','teste-investidor-deploy.service'],capture_output=True,text=True).stdout.strip()
print(json.dumps(q))
REMOTE