Files
git.taskfile.build/image/entrypoint.sh
T
Janik von Rotz 20f829a845 feat(image): enhance git repo handling and simplify README env vars
- Simplify README.md by removing redundant comments from env var examples
- Improve entrypoint.sh to handle GIT_URL presence/absence gracefully
- Add repo pull support when GIT_PATH exists (instead of only clone)
- Initialize and update submodules only if .gitmodules exists
- Skip git operations entirely if GIT_URL is not set
- Remove redundant blank lines and improve script flow readability
2026-06-19 13:46:13 +02:00

75 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
echo "pnpm version: $(pnpm --version)"
echo "hugo version: $(hugo version)"
echo "git version: $(git -v)"
echo "curl version: $(curl -V)"
echo "opencode version: $(opencode --version)"
echo 'Ensure opencode config dir exists.'
mkdir -p "${OPENCODE_CONFIG_DIR:-/app/.config/opencode}"
GIT_PATH="/app/repo"
if [[ -n "$GIT_URL" ]]; then
if [[ ! -d "$GIT_PATH" ]]; then
echo "Cloning git repo: $GIT_URL (shallow clone)"
git clone --depth 1 "$GIT_URL" "$GIT_PATH"
else
echo "Pull git repo: $GIT_URL"
git -C "$GIT_PATH" reset --hard
git -C "$GIT_PATH" pull
fi
if [[ -f "$GIT_PATH/.gitmodules" ]]; then
echo 'Found .gitmodules, initializing submodules (shallow).'
git -C "$GIT_PATH" submodule init
git -C "$GIT_PATH" submodule update --recursive --depth 1
fi
else
echo 'GIT_URL not set, skipping git clone/pull.'
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
case "$1" in
caddy)
echo 'Start Caddy.'
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
;;
*)
exec "$@"
;;
esac