Compare commits

...

16 Commits

Author SHA1 Message Date
e178141357 Add extra backup locations. Did this a few days ago but it seems it did not get pushed and the commit disappeared. 2025-08-22 13:44:48 -07:00
6062818475 Add the version of Express as being done in package.json. 2025-08-21 13:24:53 -07:00
f77557151a Add size to container check. 2025-08-21 11:22:24 -07:00
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
11 changed files with 86 additions and 35 deletions

View File

@@ -8,19 +8,21 @@ FROM debian:bookworm-slim
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
#RUN groupadd -r hugo && useradd -r -g hugo hugo
# Hugo Directory Tree
RUN mkdir -pv /var/www/hugo && chown -Rv hugo:hugo /var/www/hugo
RUN mkdir -pv /var/www/hugo/
# NGINX Directory Tree
RUN mkdir -pv /var/www/html/ && chown -Rv hugo:hugo /var/www/html/
RUN mkdir -pv /var/www/html/
# Copy Cron Job to Update Git Repo
COPY files/hugo.crontab /etc/cron.d/hugo
COPY files/hugo.cronjob.sh /var/www/hugo/cronjob.sh
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
RUN crontab /etc/cron.d/hugo
# Copy Start Script
COPY files/main.sh /root/main.sh
@@ -30,4 +32,4 @@ RUN chmod +x /root/main.sh
# Install + Run Website
WORKDIR /var/www/
USER root
CMD /root/main.sh "$REPO" "$PROD" "$DEV"
CMD /root/main.sh "$REPO" "$BRANCH" "$PROD" "$DEV"

View File

@@ -13,6 +13,7 @@ services:
- 1380:1380 # Development files with drafts served by Hugo Server.
environment:
- REPO=$REPO
- BRANCH=$BRANCH
- PROD=$PROD
- DEV=$DEV
healthcheck:

View File

@@ -9,6 +9,7 @@ COMPOSE_BAKE=true
## Git Website Repository
#
REPO=https://git.hyperling.com/me/hugo-jackanope
BRANCH=main
#
## Web Environments

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

@@ -1,10 +0,0 @@
#!/usr/bin/env bash
cd /var/www/hugo/site
git pull
hugo --gc --minify
rm -rfv /var/www/html/*
cp -rfv public/* /var/www/html/

View File

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

View File

@@ -1,33 +1,53 @@
#!/usr/bin/env bash
REPO="$1"
echo "REPO=$REPO"
echo "REPO='$REPO'"
PROD="$2"
BRANCH="$2"
if [[ -n $BRANCH ]]; then
BRANCH="--branch $BRANCH"
fi
echo "BRANCH='$BRANCH'"
PROD="$3"
typeset -u PROD
echo "PROD=$PROD"
echo "PROD='$PROD'"
DEV="$3"
DEV="$4"
typeset -u DEV
echo "DEV=$DEV"
echo "DEV='$DEV'"
echo "*** Creating Git Repo ***"
sudo -u hugo git clone --recurse-submodules $REPO /var/www/hugo/site
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 ***"
sudo -u hugo /var/www/hugo/cronjob.sh
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
curl -sS http://localhost:80 > /dev/null || {
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 &
@@ -39,19 +59,28 @@ if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then
echo "*** Starting Development Server Loop ***"
while true; do
curl -sS http://localhost:1380 > /dev/null || {
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 hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 &
}
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 ***"
echo "*** Finished $0 @ `date` ***"
wait -n

View File

@@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y git php-cli sudo curl
# Cache Node Dependencies
RUN mkdir -p /var/www/api
WORKDIR /var/www/api
RUN echo '{ "dependencies": { "express": "" } }' > package.json
RUN echo '{ "dependencies": { "express": ">=4.18.1 < 5.0.0" } }' > package.json
RUN npm install
# Install + Run Website

View File

@@ -24,8 +24,10 @@ echo -e "\n`date` - Take down services for a cold backup."
manage.sh -d
echo -e "\n`date` - Create the backup for '$DOCKER_HOME'."
cd $DOCKER_HOME
$time zip -r $file.tmp . 1>/dev/null
$time zip -r $file.tmp \
$DOCKER_HOME \
/etc/crontab /etc/cron.d /var/spool/cron \
/var/{log,mail} 1>/dev/null
mv -v $file.tmp $file
echo -e "\n`date` - Done with zipping, check size."

View File

@@ -130,7 +130,7 @@ fi
if [[ -z $up && -z $down && -z $build && -z $pull && -z $clean
&& -z $interact && -z $logs && -z $stats
]]; then
docker ps
docker ps --size
exit 0
fi