Files
git.taskfile.build/image/entrypoint.sh
T

70 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "pnpm version: $(pnpm --version)"
echo "hugo version: $(hugo version)"
if [ -z "$GIT_URL" ]; then
echo "Error: GIT_URL environment variable is required." >&2
exit 1
fi
GIT_PATH="/app/repo"
if [ ! -d "$GIT_PATH" ]; then
echo "Cloning git repo: $GIT_URL"
git clone "$GIT_URL" "$GIT_PATH"
else
echo "Pull git repo: $GIT_URL"
git -C "$GIT_PATH" pull
fi
if [ -f "$GIT_PATH/.gitmodules" ]; then
echo "Found .gitmodules, initializing submodules."
git -C "$GIT_PATH" submodule init
git -C "$GIT_PATH" submodule update --recursive
fi
if [ -f "${GIT_PATH}/task" ]; then
if [ -z "$TASK_COMMANDS" ]; then
echo "Error: TASK_COMMANDS environment variable is required." >&2
exit 1
fi
echo "Ensure task file is executable."
chmod +x "${GIT_PATH}/task"
cd "$GIT_PATH"
COMMANDS=$(echo "$TASK_COMMANDS" | tr "," "\n")
for COMMAND in $COMMANDS; do
echo "Run task command: $COMMAND"
./task "$COMMAND"
done
fi
echo "Template Caddyfile."
cat > /etc/caddy/Caddyfile <<EOF
:80 {
root * ${GIT_PATH}/${CADDY_ROOT}
file_server
try_files {path} {path}/ /index.html
encode gzip
header {
X-Content-Type-Options nosniff
X-Frame-Options DENY
X-XSS-Protection "1; mode=block"
Referrer-Policy strict-origin-when-cross-origin
}
@static {
file
path *.css *.js *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
}
header @static Cache-Control "public, max-age=31536000, immutable"
}
EOF
echo "Start Caddy."
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile