Compare commits

...

34 Commits

Author SHA1 Message Date
fb7e31ed69 Merge pull request 'Allow Alternative Hugo Website Branches' (#10) from dev into main
Reviewed-on: #10
2025-08-19 15:11:39 -07:00
0478e8e108 Allow specifying the branch of the Hugo project. 2025-08-19 15:05:15 -07:00
2663bb5351 Allow specifying the branch of the Hugo project. 2025-08-19 15:03:12 -07:00
4aa7fa4b00 Merge pull request 'Improve Hugo Configuration' (#9) from dev into main
Reviewed-on: #9
2025-08-17 17:06:11 -07:00
d7a1e6f58a Remove hugo user reference from files. 2025-08-17 11:49:05 -07:00
f622cba366 Add the mail files to the container's log output. 2025-08-17 11:44:16 -07:00
e86660d34e Using the crontab command adds the job to root's jobs. Allow cron to pick up the file automatically by not running any explicit calls. 2025-08-17 11:43:54 -07:00
cfb07a6e93 Use the www-data user rather than creating a hugo user. 2025-08-17 11:26:47 -07:00
4dd0661e1e Move permission commands to a single command after the cronjob file is copied. 2025-08-17 11:02:13 -07:00
d6e1186d86 Modify script to remove NGINX default files and check HTTP codes rather than curl response status. 2025-08-17 11:01:10 -07:00
57ade9f67d Give the cronjob some safety so that it churns less. 2025-08-17 11:00:34 -07:00
ddeadcf723 Add safeguards to cron job so that website does not get deleted without having replacement files. 2025-08-17 09:12:23 -07:00
dbb54b6f81 Do not continue if the git repo does not exist. 2025-08-17 09:01:24 -07:00
5afc3bfaee Merge pull request 'Productionize Hugo Configuration' (#8) from dev into main
Reviewed-on: #8
2025-08-15 12:13:15 -07:00
5323b6647f Change restart loop timers. 2025-08-15 11:49:00 -07:00
6dac535211 Remove running service commands since they don't actually keep the programs enabled. 2025-08-15 11:46:23 -07:00
d035f9d8e7 Refactor how the project is run, using nginx instead of hugo server, a cron job to pull git changes, and a start script to ensure the correct services are started each run and are monitored to stay up. 2025-08-15 11:45:23 -07:00
dfb9a306c5 Allow copies of Hugo configuration to exist outside of the Git project. 2025-08-15 11:43:46 -07:00
1ba2739665 Merge pull request 'Add Example Hugo Configuration' (#7) from dev into main
Reviewed-on: #7
2025-08-14 12:36:40 -07:00
0ca793423b Add working configuration for how to run a slim Hugo container. 2025-08-14 12:30:25 -07:00
1284fc3946 Merge pull request 'LibreTranslate Reboot Fix' (#6) from dev into main
Reviewed-on: #6
2025-07-26 13:57:57 -07:00
a3d6cdcee1 Number list rather than relying on autoincrement. 2025-07-26 13:55:04 -07:00
a868f874d7 Add file paths. 2025-07-26 13:54:37 -07:00
7046699ed6 Reapply changes from previous commits. Unsure why the synced branch did not have them if it was up to date. 2025-07-26 13:42:12 -07:00
eb2dda9d66 Allow container to reboot properly if using /tmp/ for models. Fixes newly created folder having permissions issues. 2025-07-26 13:35:32 -07:00
15f01061ba Move request characters to the env file. 2025-07-26 12:36:29 -07:00
4aebf1e21d Fix typo in header and set ordered list to number itself. 2025-07-26 12:17:18 -07:00
5af5c13f43 Merge pull request 'Add LibreTranslate' (#5) from dev into main
Reviewed-on: #5
2025-07-26 12:02:50 -07:00
27689e25d8 Be more specific about the docker home location, rather than accidentally promoting the use of a variable which would not work. 2025-07-26 12:01:10 -07:00
29d1affcd8 Be more specific about the docker home location, rather than accidentally promoting the use of a variable which would not work. 2025-07-26 12:00:43 -07:00
43ee8de7ef Add comments and an explicit exit. 2025-07-26 11:59:45 -07:00
83fdb54768 Move the LT_LOAD_ONLY to the value so that it can be omitted if wanting to download all languages. 2025-07-26 11:28:04 -07:00
16df857f08 Shrink down to just 1 yml file, putting the CPU and RAM into the env file, since the only docker-compose differences were the resource configuration. 2025-07-23 06:05:29 -07:00
620f3f81b2 Shrink down to just 1 yml file, putting the CPU and RAM into the env file, since the only docker-compose differences were the resource configuration. 2025-07-23 06:05:21 -07:00
13 changed files with 266 additions and 76 deletions

6
.gitignore vendored
View File

@@ -35,6 +35,10 @@ docker-compose.yml
# 2024-01-24 Hide static files for Hyperling.com.
Config/Hyperling.com/files/*
# Ignore things like Config/Hyperling.com-Stage/
# Ignore things like "Config/Hyperling.com-Stage/""
*-Stage
Stage-*
# Ignore copies of the Hugo configuration, such as "Config/Hugo-MyWebsite".
Hugo-*
*-Hugo

View File

@@ -0,0 +1,35 @@
# 2025-08-13 Hyperling
## Image ##
FROM debian:bookworm-slim
## Setup ##
# System Dependencies
RUN apt-get update && apt-get install -y git hugo nginx cron curl bash sudo htop
# User and Group
#RUN groupadd -r hugo && useradd -r -g hugo hugo
# Hugo Directory Tree
RUN mkdir -pv /var/www/hugo/
# NGINX Directory Tree
RUN mkdir -pv /var/www/html/
# Copy Cron Job to Update Git Repo
COPY files/crontab /etc/crontab
COPY files/cronjob.sh /var/www/hugo/cronjob.sh
# Hugo User Permissions
RUN chown -Rv www-data:www-data /var/www/
RUN chmod +x /var/www/hugo/cronjob.sh
# Copy Start Script
COPY files/main.sh /root/main.sh
RUN chmod +x /root/main.sh
## Main ##
# Install + Run Website
WORKDIR /var/www/
USER root
CMD /root/main.sh "$REPO" "$BRANCH" "$PROD" "$DEV"

View File

@@ -0,0 +1,30 @@
# 2025-08-13
# Configuration for running a Hugo website pulled from Git.
services:
app:
container_name: hugo
build:
context: ./
network: host
restart: always
ports:
- 8013:80 # Production minified files served using NGINX.
- 1380:1380 # Development files with drafts served by Hugo Server.
environment:
- REPO=$REPO
- BRANCH=$BRANCH
- PROD=$PROD
- DEV=$DEV
healthcheck:
test: curl -sS http://localhost:80 || curl -sS http://localhost:1380 || exit 1
interval: 1m
timeout: 10s
retries: 2
start_period: 30s
deploy:
mode: global
resources:
limits:
cpus: '0.10'
memory: 64M

View File

@@ -0,0 +1,22 @@
# 2025-08-13 Hyperling
#
## Docker ##
#
COMPOSE_BAKE=true
#
## Git Website Repository
#
REPO=https://git.hyperling.com/me/hugo-jackanope
BRANCH=main
#
## Web Environments
# Please use values YES/TRUE and NO/FALSE.
# Whether to start NGINX
PROD=YES
# Whether to start Hugo Server
DEV=NO

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
cd /var/www/hugo/site
echo "*** Running cronjob @ `date` ***"
# Pull any updates, and if the project is already up to date, exit successfully.
git pull | grep -v "up to date"
status="$?"
echo "* Pull status is '$status'."
if [[ $status != 0 && -e /var/www/html/index.html ]]; then
echo "* Site is already up to date and copied, exiting."
exit 0
fi
# If the project was not already up to date, build the new files for NGINX.
hugo --gc --minify
status="$?"
echo "* Hugo status is '$status'."
if [[ $status == 0 && -e public/index.html ]]; then
echo "* Copying files..."
rm -rfv /var/www/html/*
mv -v public/* /var/www/html/
fi
exit 0

View File

@@ -0,0 +1 @@
* * * * * www-data /var/www/hugo/cronjob.sh

View File

@@ -0,0 +1,87 @@
#!/usr/bin/env bash
REPO="$1"
echo "REPO='$REPO'"
BRANCH="$2"
if [[ -n $BRANCH ]]; then
BRANCH="--branch $BRANCH"
fi
echo "BRANCH='$BRANCH'"
PROD="$3"
typeset -u PROD
echo "PROD='$PROD'"
DEV="$4"
typeset -u DEV
echo "DEV='$DEV'"
echo "*** Creating Git Repo ***"
sudo -u www-data git clone --recurse-submodules $BRANCH $REPO /var/www/hugo/site
status="$?"
echo "*** Validating Git Repo ***"
if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then
echo "ERROR: Hugo project may not have cloned correctly. status='$status'"
echo "Aborting."
exit 1
fi
echo "* Site exists!"
echo "*** Copying Static Files to NGINX ***"
rm -rfv /var/www/html/*
sudo -u www-data /var/www/hugo/cronjob.sh
echo "*** Starting Cron ***"
service cron start
service cron status
if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then
echo "*** Starting Production Server Loop ***"
while true; do
http_code="`curl -sS http://localhost:80 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Prod server not detected, starting..."
service nginx status
service nginx start
service nginx status
fi
sleep 15
done &
cd /var/log/nginx
tail -f access.log error.log &
fi
if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then
echo "*** Starting Development Server Loop ***"
while true; do
http_code="`curl -sS http://localhost:1380 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Dev server not detected, starting..."
cd /var/www/hugo/site
killall hugo 2>/dev/null
sudo -u www-data hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 &
fi
sleep 30
done &
fi
echo "*** Following Mail Files ***"
cd /var/mail
touch mail www-data
chown -v mail:mail mail
chown -v www-data:mail www-data
chmod -v 660 mail www-data
tail -f mail www-data &
cd
echo "*** Finished $0 @ `date` ***"
wait -n
exit $?

View File

@@ -1,8 +1,8 @@
# Libreranslate Configuration
# LibreTranslate Configuration
## Install
0. Copy `env.example` to `.env` and adjust the values as necessary.
1. Copy `env.example` to `.env` and adjust the values as necessary.
```
cd $DOCKER_HOME/Config/LibreTranslate
@@ -10,21 +10,22 @@ cp env.example .env
vi .env
```
1. Run the `prep.sh` file to create the volume mounts.
2. Run the `prep.sh` file to create the volume mounts.
```
$DOCKER_HOME/Config/LibreTranslate/prep.sh
./prep.sh
```
2. If using a temporary location for `models/` such as `/tmp/`, ensure
that `prep.sh` is in `root`'s crontab.
3. If using a temporary location for `models/` such as `/tmp/`, ensure
that the reboot script is in `root`'s crontab to set the folders back up.
```
@reboot $DOCKER_HOME/Config/LibreTranslate/prep.sh
@reboot /opt/Docker/Config/LibreTranslate/cron-reboot.sh
```
3. Start the container up as normal.
4. Start the container up as normal.
```
cp docker-compose.main.yml docker-compose.yml
docker compose up -d
```

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# 2025-07-26 Hyperling
# Ensure the LibreTranslate container starts correctly after a reboot, especially if placing models/ under /tmp/.
## Setup ##
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
cd $DIR
source ./.env
## Main ##
# Shutdown the container.
docker compose down
# Create folders.
./prep.sh
# Start the container.
docker compose up -d
# Finish successfully.
exit 0

View File

@@ -1,4 +1,4 @@
# LibreTranslate configuration for a capable server.
# LibreTranslate configuration.
# Example docker-compose.yml:
# https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml
@@ -34,14 +34,14 @@ services:
tty: true
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
command: --req-limit 100 --char-limit 2000
command: --req-limit $REQUESTS --char-limit $CHARACTERS
environment:
# Allow the saving of API Keys. Requires volume libretranslate_api_keys.
- LT_API_KEYS=true
- LT_API_KEYS_DB_PATH=/app/db/api_keys.db
# Optimize loading time. Requires volume libretranslate_models.
- LT_UPDATE_MODELS=$UPDATE_MODELS
- LT_LOAD_ONLY=$LANGUAGES
- $LANGUAGES
volumes:
# Store the API keys.
- libretranslate_api_keys:/app/db
@@ -51,5 +51,5 @@ services:
mode: global
resources:
limits:
cpus: '2.00'
memory: 4G
cpus: $CPU
memory: $RAM

View File

@@ -1,55 +0,0 @@
# LibreTranslate configuration for a small-scale server (1 CPU, 1GB RAM).
# Example docker-compose.yml:
# https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml
# Named volumes ensure that the container user gets the correct permissions.
volumes:
libretranslate_api_keys:
driver: local
driver_opts:
type: none
device: $API_KEYS_DIR
o: bind
libretranslate_models:
driver: local
driver_opts:
type: none
device: $MODELS_DIR
o: bind
services:
## Main ##
lt-app:
container_name: lt-app
build:
context: ./
network: host
restart: always
ports:
- "5000:5000"
# Uncomment this for logging in docker compose logs
tty: true
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
command: --req-limit 100 --char-limit 2000
environment:
# Allow the saving of API Keys. Requires volume libretranslate_api_keys.
- LT_API_KEYS=true
- LT_API_KEYS_DB_PATH=/app/db/api_keys.db
# Optimize loading time. Requires volume libretranslate_models.
- LT_UPDATE_MODELS=$UPDATE_MODELS
- LT_LOAD_ONLY=$LANGUAGES
volumes:
# Store the API keys.
- libretranslate_api_keys:/app/db
# Avoid re-downloading language models every reboot.
- libretranslate_models:/home/libretranslate/.local:rw
deploy:
mode: global
resources:
limits:
cpus: '0.25'
memory: 640M

View File

@@ -2,17 +2,30 @@
COMPOSE_BAKE=true
### Container Specs ###
## For a small-scale server (such as 1 CPU, 1GB RAM).
# CPU=0.25
# RAM=640M
## For a fully capable server.
CPU=2.00
RAM=4.0G
# How much the users are able to utilize the server.
REQUESTS=100
CHARACTERS=2000
### Languages ###
## Check for language model updates on each run.
UPDATE_MODELS=true
## Leave commented, blank, or set to "All" for default behavior.
# LANGUAGES=
# LANGUAGES=All
## Use default behavior of downloading all models.
# LANGUAGES=ALL
## Otherwise set to a comma-separated list to enable only the desired models.
LANGUAGES=en,es,fr,de
LANGUAGES='LT_LOAD_ONLY=en,es,fr,de'
### API Keys ###
@@ -31,7 +44,6 @@ MODELS_DIR=../../Volumes/LibreTranslate/models
# MODELS_DIR=
## Storing them in /tmp/ will cause them to get reset after reboots, but hides
## them from backup type locations such as Volumes/LibreTranslate and /var/.
## This will require a CRON entry for prepping the project after a reboot.
## `@reboot $DOCKER_HOME/Config/LibreTranslate/prep.sh`
## them from backup type locations such as Volumes/LibreTranslate/ and /var/.
## Please see the README for the CRON command related to this setting.
# MODELS_DIR=/tmp/LibreTranslate/models

View File

@@ -10,6 +10,7 @@ source $DIR/.env
## Main ##
# Create folders.
if [[ $API_KEYS_DIR == "../*" ]]; then
API_KEYS_DIR="$DIR/$API_KEYS_DIR"
fi
@@ -19,3 +20,6 @@ if [[ $MODELS_DIR == "../*" ]]; then
MODELS_DIR="$DIR/$MODELS_DIR"
fi
mkdir -pv $MODELS_DIR
# Finish successfully.
exit 0