mirror 레포 도입
This commit is contained in:
@@ -25,7 +25,13 @@ jobs:
|
||||
mkdir -p ~/.ssh
|
||||
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -p 22 172.16.42.118 >> ~/.ssh/known_hosts
|
||||
ssh-keyscan -p 22 172.16.10.191 >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Refresh source mirror repositories (git fetch --mirror)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "Refreshing mirror repos on 172.16.10.191 ..."
|
||||
ssh engdev@172.16.10.191 'set -euo pipefail; shopt -s nullglob; for repo in */.git; do dir="${repo%/.git}"; echo "Updating ${dir}"; (cd "${dir}" && git fetch --mirror --prune); done'
|
||||
|
||||
- name: Backup Branches (pre-scan → decision → execution)
|
||||
env:
|
||||
@@ -41,11 +47,17 @@ jobs:
|
||||
|
||||
CENTER_ORG="center_dev"
|
||||
AUTH_HEADER="Authorization: token ${BASE_GITEA_TOKEN}"
|
||||
SOURCE_SSH_HOST="engdev@172.16.42.118"
|
||||
SOURCE_SSH_HOST="engdev@172.16.10.191"
|
||||
ROOT_DIR="$(pwd)"
|
||||
NOTIFY_WEBHOOK="${NOTIFY_WEBHOOK:-}"
|
||||
SYNC_TAGS="${SYNC_TAGS:-true}"
|
||||
TARGET_SEED_DEPTH="${TARGET_SEED_DEPTH:-50}"
|
||||
if ! [[ "${TARGET_SEED_DEPTH}" =~ ^[0-9]+$ ]] || (( TARGET_SEED_DEPTH <= 0 )); then
|
||||
echo "::warning::TARGET_SEED_DEPTH(${TARGET_SEED_DEPTH}) is invalid; resetting to 50"
|
||||
TARGET_SEED_DEPTH=50
|
||||
fi
|
||||
CACHE_BASE="${ROOT_DIR}/.cache_sources"
|
||||
mkdir -p "${CACHE_BASE}"
|
||||
TOTAL_SUCCESS=0
|
||||
TOTAL_SKIP=0
|
||||
TOTAL_ERROR=0
|
||||
@@ -155,6 +167,7 @@ jobs:
|
||||
declare -A ENTRY_ALIAS
|
||||
declare -A ENTRY_REPO
|
||||
declare -A SOURCE_REPOS
|
||||
declare -A SOURCE_CACHE_PATH
|
||||
declare -a ENTRY_KEYS=()
|
||||
|
||||
add_entry() {
|
||||
@@ -210,13 +223,48 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
prepare_cache() {
|
||||
local source_repo="$1" cache_dir="${CACHE_BASE}/${source_repo//\//_}.git"
|
||||
if [[ ! -d "${cache_dir}" ]]; then
|
||||
echo "Initializing local cache for ${source_repo} at ${cache_dir}"
|
||||
if ! git clone --mirror "${SOURCE_SSH_HOST}:${source_repo}" "${cache_dir}"; then
|
||||
echo "::warning::Failed to clone cache for ${source_repo}"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "Refreshing cache for ${source_repo}"
|
||||
if ! git -C "${cache_dir}" fetch --mirror --prune; then
|
||||
echo "::warning::Failed to refresh cache for ${source_repo}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
SOURCE_CACHE_PATH["${source_repo}"]="${cache_dir}"
|
||||
}
|
||||
|
||||
echo "Preparing per-source caches..."
|
||||
for source_repo in "${!SOURCE_REPOS[@]}"; do
|
||||
prepare_cache "${source_repo}" || echo "::warning::Cache unavailable for ${source_repo}; will fallback to direct fetch"
|
||||
done
|
||||
|
||||
echo "Step 1) 소스 브랜치 해시 스캔"
|
||||
for source_repo in "${!SOURCE_REPOS[@]}"; do
|
||||
cache_dir="${SOURCE_CACHE_PATH[${source_repo}]:-}"
|
||||
source_repo_url="${SOURCE_SSH_HOST}:${source_repo}"
|
||||
echo " - ${source_repo_url}"
|
||||
if ! remote_output=$(git ls-remote --heads "${source_repo_url}"); then
|
||||
echo "::warning::Failed to ls-remote ${source_repo_url}. Entries for this repo may fail."
|
||||
continue
|
||||
if [[ -n "${cache_dir}" && -d "${cache_dir}" ]]; then
|
||||
echo " - using cache: ${cache_dir}"
|
||||
remote_output=$(git -C "${cache_dir}" for-each-ref --format='%(objectname)\t%(refname)' 'refs/heads/*') || {
|
||||
echo "::warning::Failed to read heads from cache ${cache_dir}; falling back to remote."
|
||||
remote_output=$(git ls-remote --heads "${source_repo_url}") || {
|
||||
echo "::warning::Failed to ls-remote ${source_repo_url}. Entries for this repo may fail."
|
||||
continue
|
||||
}
|
||||
}
|
||||
else
|
||||
echo " - ${source_repo_url}"
|
||||
if ! remote_output=$(git ls-remote --heads "${source_repo_url}"); then
|
||||
echo "::warning::Failed to ls-remote ${source_repo_url}. Entries for this repo may fail."
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
while IFS=$'\t' read -r commit ref || [[ -n "${commit}" ]]; do
|
||||
[[ -z "${commit}" || -z "${ref}" ]] && continue
|
||||
@@ -352,8 +400,9 @@ jobs:
|
||||
echo "Working directory: ${CLONE_DIR}"
|
||||
if ${just_created}; then
|
||||
echo "Target repo newly created; cloning source branch for initial push..."
|
||||
if ! git clone --bare --no-tags --single-branch --branch "${branch_name}" "${SOURCE_SSH_HOST}:${source_repo}" "${CLONE_DIR}"; then
|
||||
echo "::error::Failed to clone source repository ${SOURCE_SSH_HOST}:${source_repo}"
|
||||
SOURCE_FETCH_REMOTE="${SOURCE_CACHE_PATH[${source_repo}]:-${SOURCE_SSH_HOST}:${source_repo}}"
|
||||
if ! git clone --bare --no-tags --single-branch --branch "${branch_name}" "${SOURCE_FETCH_REMOTE}" "${CLONE_DIR}"; then
|
||||
echo "::error::Failed to clone source repository ${SOURCE_FETCH_REMOTE}"
|
||||
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "source clone 실패" "${heads_detail}"
|
||||
rm -rf "${CLONE_DIR}"
|
||||
continue
|
||||
@@ -371,7 +420,8 @@ jobs:
|
||||
continue
|
||||
fi
|
||||
git remote add origin "${GITEA_REMOTE}"
|
||||
git remote add source "${SOURCE_SSH_HOST}:${source_repo}"
|
||||
SOURCE_FETCH_REMOTE="${SOURCE_CACHE_PATH[${source_repo}]:-${SOURCE_SSH_HOST}:${source_repo}}"
|
||||
git remote add source "${SOURCE_FETCH_REMOTE}"
|
||||
fi
|
||||
|
||||
echo "Fetching latest branch '${branch_name}' from source..."
|
||||
|
||||
@@ -23,7 +23,13 @@ jobs:
|
||||
mkdir -p ~/.ssh
|
||||
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -p 22 172.16.42.118 >> ~/.ssh/known_hosts
|
||||
ssh-keyscan -p 22 172.16.10.191 >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Refresh source mirror repositories (git fetch --mirror)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "Refreshing mirror repos on 172.16.10.191 ..."
|
||||
ssh engdev@172.16.10.191 'set -euo pipefail; shopt -s nullglob; for repo in */.git; do dir="${repo%/.git}"; echo "Updating ${dir}"; (cd "${dir}" && git fetch --mirror --prune); done'
|
||||
|
||||
- name: Mirror Branches
|
||||
env:
|
||||
|
||||
Reference in New Issue
Block a user