add a script for update

This commit is contained in:
kbe
2025-08-19 23:48:30 +02:00
parent 98f639b913
commit ef7951c1e4
38 changed files with 229 additions and 29 deletions

37
scripts/README.md Normal file
View File

@@ -0,0 +1,37 @@
# Website Update Script
This script triggers the builder container to update the website content using Docker Compose.
## Usage
1. Make the script executable:
```sh
chmod +x scripts/update-website.sh
```
2. Run the script manually to test it:
```sh
./scripts/update-website.sh
```
3. To set up a cron job, add the following line to your crontab (edit with `crontab -e`):
```sh
0 2 * * * /home/acid/Documents/mistergeek/scripts/update-website.sh >> /home/acid/Documents/mistergeek/logs/update-website.log 2>&1
```
This will run the update script every day at 2:00 AM.
Alternatively, you can run the update script every 6 hours:
```sh
0 */6 * * * /home/acid/Documents/mistergeek/scripts/update-website.sh >> /home/acid/Documents/mistergeek/logs/update-website.log 2>&1
```
## Logs
Logs are stored in `/home/acid/Documents/mistergeek/logs/update-website.log`.
## Requirements
- Docker
- Docker Compose
- The `docker` and `docker compose` commands must be available in the system's PATH

View File

@@ -3,18 +3,33 @@
# Exit immediately if a command exits with a non-zero status.
set -e
# Log the start of the build process
echo "Starting build process..."
# Log the beginning of CSS compilation
echo "Building CSS..."
# Assuming sass is installed and available in the environment or Docker image
# Compile theme.scss to theme.css
echo "Compiling SASS to CSS..."
sass assets/css/scss/theme.scss static/assets/css/theme.css
echo "CSS compilation completed successfully."
# Log the beginning of data fetching from WordPress
echo "Fetching content from WordPress..."
# Assuming Node.js is installed and available in the environment or Docker image
node scripts/fetch-wordpress.js
# Assuming Node.js and Yarn are installed and available in the environment or Docker image
yarn run fetch-data
echo "Content fetched successfully from WordPress."
# Log the beginning of content generation for Hugo
echo "Generating content for Hugo..."
yarn run generate-content
echo "Content generation for Hugo completed successfully."
# Log the beginning of Hugo production build
echo "Generating production build with Hugo..."
# Assuming Hugo is installed and available in the environment or Docker image
hugo --minify --environment production --config hugo.toml
echo "Hugo production build completed successfully."
# Log the successful completion of the build process
echo "Build process completed successfully!"

View File

@@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const WORDPRESS_API = 'https://www.mistergeek.net/wp-json/wp/v2';
const WORDPRESS_API = 'https://wp.mistergeek.net/wp-json/wp/v2';
const OUTPUT_DIR = path.join(__dirname, '..', 'data', 'wordpress');
const HUGO_DATA_DIR = path.join(__dirname, '..', 'data');

View File

@@ -0,0 +1,7 @@
# Crontab file for updating the website
# Run the update script every day at 2:00 AM
0 2 * * * /home/acid/Documents/mistergeek/scripts/update-website.sh >> /home/acid/Documents/mistergeek/logs/update-website.log 2>&1
# Alternatively, run the update script every 6 hours
# 0 */6 * * * /home/acid/Documents/mistergeek/scripts/update-website.sh >> /home/acid/Documents/mistergeek/logs/update-website.log 2>&1

24
scripts/update-website.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/sh
# Exit immediately if a command exits with a non-zero status.
set -e
# Log the start of the update process
echo "Starting website update process..."
# Navigate to the project directory
cd "$(dirname "$0")/.."
# Build the Docker image if it doesn't exist
echo "Checking for Docker image..."
if ! docker compose ls | grep -q "builder"; then
echo "Docker image not found. Building image..."
docker compose build
fi
# Start the builder container
echo "Starting builder container..."
docker compose run --rm builder
# Log the successful completion of the update process
echo "Website update process completed successfully!"