Skip to content

Commit

Permalink
Merge staging: Improve deployment scripts with better database handling
Browse files Browse the repository at this point in the history
  • Loading branch information
screenfluent committed Nov 18, 2024
2 parents cf71e6d + 3147fdb commit 6c281a2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 42 deletions.
39 changes: 30 additions & 9 deletions forge/deploy.production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,36 @@ chmod -R 775 public/logos
mkdir -p db
chmod 755 db

# Remove existing database to force recreation with new schema
rm -f db/votes.db
touch db/votes.db
chown llmstxtdirectory:www-data db/votes.db
chmod 664 db/votes.db

# Initialize database with new schema
echo "Initializing database with new schema..."
php db/init.php
# Database handling
if [ ! -f "db/votes.db" ]; then
# Only create new database if it doesn't exist
echo "Creating new database..."
touch db/votes.db
chown llmstxtdirectory:www-data db/votes.db
chmod 664 db/votes.db

# Initialize with schema and sample data
echo "Initializing database with schema and sample data..."
php db/init.php
else
# Database exists, just update schema
echo "Updating existing database schema..."
php -r "
require_once 'db/database.php';
\$db = new Database();
\$schema = file_get_contents('db/schema.sql');
\$db->db->exec('BEGIN TRANSACTION;');
try {
\$db->db->exec(\$schema);
\$db->db->exec('COMMIT;');
echo \"Schema updated successfully.\n\";
} catch (Exception \$e) {
\$db->db->exec('ROLLBACK;');
echo \"Error updating schema: \" . \$e->getMessage() . \"\n\";
exit(1);
}
"
fi

# Set database permissions
chown llmstxtdirectory:www-data db/votes.db
Expand Down
46 changes: 33 additions & 13 deletions forge/deploy.staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,62 @@
set -e

# Configure git
git config --global --add safe.directory /home/forge/staging.llmstxt.directory
git config --global --add safe.directory /home/stagingllmstxtdirectory/staging.llmstxt.directory

# Update repository
cd /home/forge/staging.llmstxt.directory
git fetch origin staging
git reset --hard origin/staging
cd /home/stagingllmstxtdirectory/staging.llmstxt.directory

# Initial git setup
git fetch --all
git checkout -f staging || git checkout -f main
git pull origin staging || git pull origin main

# Set permissions
chown -R forge:forge .
chown -R stagingllmstxtdirectory:stagingllmstxtdirectory .
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

# Create and set permissions for storage directories
mkdir -p public/logos
chown -R forge:www-data public/logos
chown -R stagingllmstxtdirectory:www-data public/logos
chmod -R 775 public/logos

# Ensure db directory exists and is accessible
mkdir -p db
chmod 755 db

# Remove existing database to force recreation with new schema
# Always recreate database in staging for clean testing
echo "Recreating staging database..."
rm -f db/votes.db
touch db/votes.db
chown forge:www-data db/votes.db
chown stagingllmstxtdirectory:www-data db/votes.db
chmod 664 db/votes.db

# Initialize database with new schema
echo "Initializing database with new schema..."
php db/init.php
# Initialize with fresh schema and sample data
echo "Initializing database with fresh schema and sample data..."
php -r "
require_once 'db/database.php';
\$db = new Database();
\$schema = file_get_contents('db/schema.sql');
\$db->db->exec('BEGIN TRANSACTION;');
try {
\$db->db->exec(\$schema);
require_once 'db/init.php';
\$db->db->exec('COMMIT;');
echo \"Database initialized successfully.\n\";
} catch (Exception \$e) {
\$db->db->exec('ROLLBACK;');
echo \"Error initializing database: \" . \$e->getMessage() . \"\n\";
exit(1);
}
"

# Set database permissions
chown forge:www-data db/votes.db
chown stagingllmstxtdirectory:www-data db/votes.db
chmod 664 db/votes.db

# Restart PHP
sudo -S service php8.2-fpm restart
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

echo "Deployment completed successfully!"
48 changes: 28 additions & 20 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@
<?php
$implementations = $db->getFeaturedImplementations();
foreach ($implementations as $impl) {
$homepage = str_replace('/docs/llms.txt', '', $impl['llms_txt_url']);
$homepage = str_replace('/docs/llms.txt', '', $impl['llms_txt_url'] ?? '');
$homepage = str_replace('/llms.txt', '', $homepage);

echo '<div class="card" onclick="window.location.href=\'' . htmlspecialchars($homepage) . '\'">
Expand All @@ -622,24 +622,28 @@
<div class="card-inner">
<div class="card-content">
<div class="title-row">
<div class="logo-wrapper">
<img src="' . htmlspecialchars($impl['logo_url']) . '" alt="' . htmlspecialchars($impl['name']) . ' logo">
</div>
<div class="logo-wrapper">';
if (!empty($impl['logo_url'])) {
echo ' <img src="' . htmlspecialchars($impl['logo_url']) . '" alt="' . htmlspecialchars($impl['name']) . ' logo">';
} else {
echo ' <div class="no-logo">' . htmlspecialchars(substr($impl['name'], 0, 1)) . '</div>';
}
echo ' </div>
<div class="card-title">' . htmlspecialchars($impl['name']) . '</div>
</div>
<div class="description-wrapper">';
if (!empty($impl['description'])) {
echo ' <p class="card-description">' . htmlspecialchars($impl['description']) . '</p>';
echo ' <p class="card-description">' . htmlspecialchars($impl['description']) . '</p>';
} else {
echo ' <p class="card-description">&nbsp;</p>';
echo ' <p class="card-description">&nbsp;</p>';
}
echo ' </div>
echo ' </div>
<div class="card-labels">
<a href="' . htmlspecialchars($impl['llms_txt_url']) . '" class="label label-txt" onclick="event.stopPropagation()">llms.txt</a>';
<a href="' . htmlspecialchars($impl['llms_txt_url'] ?? '#') . '" class="label label-txt" onclick="event.stopPropagation()">llms.txt</a>';
if ($impl['has_full']) {
echo ' <a href="' . str_replace('llms.txt', 'llms-full.txt', htmlspecialchars($impl['llms_txt_url'])) . '" class="label label-full" onclick="event.stopPropagation()">llms-full.txt</a>';
echo ' <a href="' . str_replace('llms.txt', 'llms-full.txt', htmlspecialchars($impl['llms_txt_url'] ?? '')) . '" class="label label-full" onclick="event.stopPropagation()">llms-full.txt</a>';
}
echo ' </div>
echo ' </div>
</div>
</div>
</div>';
Expand Down Expand Up @@ -673,7 +677,7 @@
<?php
$recentImplementations = $db->getRecentlyAddedImplementations();
foreach ($recentImplementations as $impl) {
$homepage = str_replace('/docs/llms.txt', '', $impl['llms_txt_url']);
$homepage = str_replace('/docs/llms.txt', '', $impl['llms_txt_url'] ?? '');
$homepage = str_replace('/llms.txt', '', $homepage);

echo '<div class="card" onclick="window.location.href=\'' . htmlspecialchars($homepage) . '\'">
Expand All @@ -685,24 +689,28 @@
<div class="card-inner">
<div class="card-content">
<div class="title-row">
<div class="logo-wrapper">
<img src="' . htmlspecialchars($impl['logo_url']) . '" alt="' . htmlspecialchars($impl['name']) . ' logo">
</div>
<div class="logo-wrapper">';
if (!empty($impl['logo_url'])) {
echo ' <img src="' . htmlspecialchars($impl['logo_url']) . '" alt="' . htmlspecialchars($impl['name']) . ' logo">';
} else {
echo ' <div class="no-logo">' . htmlspecialchars(substr($impl['name'], 0, 1)) . '</div>';
}
echo ' </div>
<div class="card-title">' . htmlspecialchars($impl['name']) . '</div>
</div>
<div class="description-wrapper">';
if (!empty($impl['description'])) {
echo ' <p class="card-description">' . htmlspecialchars($impl['description']) . '</p>';
echo ' <p class="card-description">' . htmlspecialchars($impl['description']) . '</p>';
} else {
echo ' <p class="card-description">&nbsp;</p>';
echo ' <p class="card-description">&nbsp;</p>';
}
echo ' </div>
echo ' </div>
<div class="card-labels">
<a href="' . htmlspecialchars($impl['llms_txt_url']) . '" class="label label-txt" onclick="event.stopPropagation()">llms.txt</a>';
<a href="' . htmlspecialchars($impl['llms_txt_url'] ?? '#') . '" class="label label-txt" onclick="event.stopPropagation()">llms.txt</a>';
if ($impl['has_full']) {
echo ' <a href="' . str_replace('llms.txt', 'llms-full.txt', htmlspecialchars($impl['llms_txt_url'])) . '" class="label label-full" onclick="event.stopPropagation()">llms-full.txt</a>';
echo ' <a href="' . str_replace('llms.txt', 'llms-full.txt', htmlspecialchars($impl['llms_txt_url'] ?? '')) . '" class="label label-full" onclick="event.stopPropagation()">llms-full.txt</a>';
}
echo ' </div>
echo ' </div>
</div>
</div>
</div>';
Expand Down

0 comments on commit 6c281a2

Please sign in to comment.