【发布时间】:2023-02-18 12:08:11
【问题描述】:
我在服务器上设置 git 以便能够编译一个 hugo 网站并将其发布到 /var/www/html 准备好在互联网上提供服务。
简而言之,我所做的是:
- 创建一个临时的 hugo 站点
- 检出同一目录中的存储库及其子模块(hugo 主题)
- 使用 hugo 构建将静态文件直接部署到 /var/www/html
我不明白的是为什么git --work-tree=$TARGET_DIR --git-dir=./ checkout -f --recurse-submodules 没有按预期拉取子模块。
谁能阐明我做错了什么? 这是脚本:
#!/bin/bash
# Directory where to work on our site
TARGET_DIR=/tmp/site-compile
# Public dir where to push the site once compiled
PUBLIC_WWW="/var/www/html"
BACKUP_WWW=$HOME/site-backup
SITE_DOMAIN=https://site.ext
# repository logical name
REPO="site.ext"
# Branch that is going to be deployed to server
BRANCH="master"
# date to be appended to latest tag
NOW=$(date +"%d%m%Y-%H%M")
set -xe
# delete the working directory first
rm -rf $TARGET_DIR
# create new temporary site
/usr/local/bin/hugo new site $TARGET_DIR
# backup public www directory first then setup trap
rsync -avz --no-t $PUBLIC_WWW/ $BACKUP_WWW
trap "echo 'A problem occurred. Reverting to backup.'; rsync -avz --no-t --del $BACKUP_WWW/ $PUBLIC_WWW; rm -rf $TARGET_DIR" EXIT
while read oldrev newrev ref
do
# if TARGET_DIR is empty we don't want deploy for this project
if [[ ! $TARGET_DIR == "" ]]; then
if [[ "$GL_REPO" == "$REPO" ]]; then
# let's check that we are deploying to the correct branch
if [[ $ref = refs/heads/${BRANCH} ]]; then
echo "Ref $ref received. Deploying '${BRANCH}' branch to production..."
git --work-tree=$TARGET_DIR --git-dir=./ checkout -f --recurse-submodules
rm ${TARGET_DIR}/config.toml
rm -rf $PUBLIC_WWW/*
/usr/local/bin/hugo -s $TARGET_DIR -d $PUBLIC_WWW -b "${SITE_DOMAIN}" -t "dagreynix" --noTimes --minify
git tag release_$NOW $BRANCH
echo " /==============================="
echo " | DEPLOYMENT COMPLETED - ${REPO}"
echo " | Target branch: ${BRANCH}"
echo " | Target folder: ${PUBLIC_WWW}"
echo " | Tag name : release_${NOW}"
echo " \=============================="
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
fi
else
echo "Target directory not declared. Skipping deploy to server."
fi
done
rm -rf $TARGET_DIR
trap - EXIT
site.ext 存储库包含content/ 目录、hugo.toml 设置文件和static/ 目录,子模块是一个hugo 主题。
简而言之,接收后脚本应该更新 themes/theme-folder 中的子模块并拉取相关文件,否则 hugo 无法正确构建站点。
提前致谢
【问题讨论】:
标签: git git-submodules hugo post-update