From 8dcc57ddd7e5cd3be09a7589665776bf8e26dc58 Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Fri, 17 Apr 2026 12:00:01 +0200 Subject: [PATCH] feat(ssh-key): add generate-ssh-key script and update entrypoint for shallow clones and submodule depth --- bin/generate-ssh-key | 11 +++++++++++ image/entrypoint.sh | 24 ++++++++++-------------- library.md | 6 ++++++ task.template | 1 + 4 files changed, 28 insertions(+), 14 deletions(-) create mode 100755 bin/generate-ssh-key diff --git a/bin/generate-ssh-key b/bin/generate-ssh-key new file mode 100755 index 0000000..8e46b71 --- /dev/null +++ b/bin/generate-ssh-key @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +generate-ssh-key() { + echo 'Generate SSH private and public keys.' + mkdir -p tmp + if [[ ! -f "tmp/ed25519" ]]; then + ssh-keygen -t ed25519 -C admin@example.com -f tmp/ed25519 -N '' + fi + export GIT_SSH_PRIVATE_KEY=$(cat tmp/ed25519 | base64 -w0) + export GIT_SSH_PUBLIC_KEY=$(cat tmp/ed25519.pub) +} \ No newline at end of file diff --git a/image/entrypoint.sh b/image/entrypoint.sh index 25a0eee..c4ee21d 100755 --- a/image/entrypoint.sh +++ b/image/entrypoint.sh @@ -3,37 +3,33 @@ set -e echo "pnpm version: $(pnpm --version)" echo "hugo version: $(hugo version)" +echo "git version: $(git -v)" +echo "curl version: $(curl -V)" if [[ -z "$GIT_URL" ]]; then - echo "Error: GIT_URL environment variable is required." >&2 + echo 'Error: GIT_URL environment variable is required.' >&2 exit 1 fi -HOST=$(echo "$GIT_URL" | awk -F'[@/]' '{print $2}' | awk -F':' '{print $1}' | awk -F'/' '{print $1}') -if ! grep -q "^$HOST" ~/.ssh/known_hosts 2>/dev/null; then - mkdir -p ~/.ssh - ssh-keyscan -t rsa "$HOST" >> ~/.ssh/known_hosts -fi - GIT_PATH="/app/repo" if [[ ! -d "$GIT_PATH" ]]; then - echo "Cloning git repo: $GIT_URL" - git clone "$GIT_URL" "$GIT_PATH" + 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" pull fi if [[ -f "$GIT_PATH/.gitmodules" ]]; then - echo "Found .gitmodules, initializing submodules." + echo 'Found .gitmodules, initializing submodules (shallow).' git -C "$GIT_PATH" submodule init - git -C "$GIT_PATH" submodule update --recursive + git -C "$GIT_PATH" submodule update --recursive --depth 1 fi if [[ -f "${GIT_PATH}/task" ]]; then if [[ -z "$TASK_COMMANDS" ]]; then - echo "Error: TASK_COMMANDS environment variable is required." >&2 + echo 'Error: TASK_COMMANDS environment variable is required.' >&2 exit 1 fi @@ -49,7 +45,7 @@ if [[ -f "${GIT_PATH}/task" ]]; then fi -echo "Template Caddyfile." +echo 'Template Caddyfile.' cat > /etc/caddy/Caddyfile < /etc/caddy/Caddyfile <