Compare commits
21 Commits
a3d6cdcee1
...
main
Author | SHA1 | Date | |
---|---|---|---|
fb7e31ed69 | |||
0478e8e108 | |||
2663bb5351 | |||
4aa7fa4b00 | |||
d7a1e6f58a | |||
f622cba366 | |||
e86660d34e | |||
cfb07a6e93 | |||
4dd0661e1e | |||
d6e1186d86 | |||
57ade9f67d | |||
ddeadcf723 | |||
dbb54b6f81 | |||
5afc3bfaee | |||
5323b6647f | |||
6dac535211 | |||
d035f9d8e7 | |||
dfb9a306c5 | |||
1ba2739665 | |||
0ca793423b | |||
1284fc3946 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -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
|
||||
|
35
Config/HugoExample/Dockerfile
Normal file
35
Config/HugoExample/Dockerfile
Normal 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"
|
30
Config/HugoExample/docker-compose.example.yml
Normal file
30
Config/HugoExample/docker-compose.example.yml
Normal 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
|
22
Config/HugoExample/env.example
Normal file
22
Config/HugoExample/env.example
Normal 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
|
26
Config/HugoExample/files/cronjob.sh
Normal file
26
Config/HugoExample/files/cronjob.sh
Normal 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
|
1
Config/HugoExample/files/crontab
Normal file
1
Config/HugoExample/files/crontab
Normal file
@@ -0,0 +1 @@
|
||||
* * * * * www-data /var/www/hugo/cronjob.sh
|
87
Config/HugoExample/files/main.sh
Normal file
87
Config/HugoExample/files/main.sh
Normal 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 $?
|
Reference in New Issue
Block a user