Commit 707e5780 authored by Ivan Mazhukin's avatar Ivan Mazhukin

copy local directory, if epm not found in Projects at builder

parent c51b7d4c
......@@ -14,6 +14,7 @@
- `bash`
- `docker` для локального запуска
- `ssh` для fallback/remote-режима
- `rsync` для копирования локального дерева на удалённую сторону
- каталог `eepm`, в котором есть `bin/eepm`
## Быстрый старт
......@@ -117,7 +118,13 @@ bin/eepm
В remote-режиме скрипт подключается по `ssh` и запускает тот же скрипт на удалённой стороне во внутреннем режиме.
При этом дерево `eepm` не копируется. На удалённую сторону передаётся только путь к нему, поэтому remote-сценарий рассчитан на ту же машину или на окружение с общим файловым деревом, где этот путь виден и локально, и из-под `builder-robot`.
Если источник задан как локальный каталог или через `--eepm-dir`, порядок такой:
1. На удалённой стороне проверяется типовой путь `/srv/<user>/Projects/eepm`.
2. Если он найден, используется он.
3. Если он не найден, локальное дерево `eepm` синхронизируется на удалённую сторону через `rsync`.
Если выбран `--eepm-source builder64`, скрипт ожидает, что удалённое дерево уже существует в `/srv/...`.
По умолчанию используются:
......@@ -196,6 +203,12 @@ ${TMPDIR:-/tmp}/epm-docker-test
./epm-docker-test.sh --remote --eepm-dir /srv/<user>/Projects/eepm ayugram fedora
```
Запустить удалённо и при отсутствии `/srv/<user>/Projects/eepm` скопировать локальное дерево на удалённую сторону:
```bash
./epm-docker-test.sh --remote --eepm-dir /path/to/local/eepm ayugram fedora
```
Запустить с builder64-источником:
```bash
......@@ -205,5 +218,5 @@ ${TMPDIR:-/tmp}/epm-docker-test
## Ограничения текущей версии
- поддерживается только `epm play`
- нет отдельного режима для копирования локального дерева на удалённый host; remote-режим ожидает, что удалённая сторона видит то же дерево по тому же пути
- для синхронизации локального дерева на удалённую сторону используется `rsync`
- источник `local` ожидает либо запуска скрипта из корня `eepm`, либо передачи `--eepm-dir`
......@@ -162,12 +162,27 @@ resolve_local_source_path() {
printf '%s\n' "$candidate"
}
resolve_builder_source_path() {
local current_user source_user candidate
resolve_explicit_source_path() {
local candidate="$1"
[[ -n "$candidate" ]] || fatal "Explicit source path is empty"
candidate="$(realpath "$candidate" 2>/dev/null || printf '%s\n' "$candidate")"
verify_eepm_tree "$candidate"
printf '%s\n' "$candidate"
}
default_builder_source_path() {
local current_user source_user
current_user="$(id -un)"
source_user="${BUILDER_USER:-$current_user}"
candidate="${BUILDER_PATH:-/srv/$source_user/Projects/eepm}"
printf '/srv/%s/Projects/eepm\n' "$source_user"
}
resolve_builder_source_path() {
local candidate
candidate="${BUILDER_PATH:-$(default_builder_source_path)}"
candidate="$(realpath "$candidate" 2>/dev/null || printf '%s\n' "$candidate")"
verify_eepm_tree "$candidate"
printf '%s\n' "$candidate"
......@@ -182,10 +197,7 @@ resolve_source_path() {
resolve_builder_source_path
;;
explicit)
[[ -n "$SOURCE_PATH" ]] || fatal "Explicit source path is empty"
SOURCE_PATH="$(realpath "$SOURCE_PATH")"
verify_eepm_tree "$SOURCE_PATH"
printf '%s\n' "$SOURCE_PATH"
resolve_explicit_source_path "$SOURCE_PATH"
;;
*)
fatal "Unsupported eepm source kind: $SOURCE_KIND"
......@@ -193,6 +205,55 @@ resolve_source_path() {
esac
}
build_ssh_base_args() {
SSH_BASE_ARGS=(
-o BatchMode=yes
-o StrictHostKeyChecking=accept-new
)
}
remote_target() {
[[ -n "$REMOTE_USER" ]] || fatal "Remote user is empty"
printf '%s@%s\n' "$REMOTE_USER" "$REMOTE_HOST"
}
remote_eepm_tree_exists() {
local target="$1"
local tree="$2"
build_ssh_base_args
ssh "${SSH_BASE_ARGS[@]}" "$target" \
bash -lc 'test -d "$1" && test -f "$1/bin/eepm" && test -r "$1/bin/eepm"' \
bash "$tree" >/dev/null 2>&1
}
remote_sync_dir_for_source() {
local source_dir="$1"
local local_user base_name
local_user="$(id -un)"
base_name="$(basename "$source_dir")"
printf '/tmp/epm-docker-test-sync/%s-%s\n' "$(slugify "$local_user")" "$(slugify "$base_name")"
}
sync_local_source_to_remote() {
local source_dir="$1"
local target="$2"
local remote_dir
require_command rsync
remote_dir="$(remote_sync_dir_for_source "$source_dir")"
build_ssh_base_args
info "Remote eepm tree not found in /srv; syncing local tree to $target:$remote_dir"
ssh "${SSH_BASE_ARGS[@]}" "$target" mkdir -p "$remote_dir"
rsync -a --delete -e "ssh ${SSH_BASE_ARGS[*]}" "$source_dir"/ "$target:$remote_dir/"
printf '%s\n' "$remote_dir"
}
create_log_file() {
local safe_app safe_system run_dir timestamp
......@@ -333,19 +394,30 @@ run_container_locally() {
build_remote_args() {
local explicit_source
local remote_source
local target
REMOTE_ARGS=(--internal-local-run --mode local)
target="$(remote_target)"
if [[ "$SOURCE_KIND" == "local" ]]; then
explicit_source="${SOURCE_PATH:-$(pwd -P)}"
explicit_source="$(realpath "$explicit_source")"
verify_eepm_tree "$explicit_source"
REMOTE_ARGS+=(--eepm-source explicit --eepm-dir "$explicit_source")
explicit_source="$(resolve_local_source_path)"
remote_source="$(default_builder_source_path)"
if remote_eepm_tree_exists "$target" "$remote_source"; then
info "Remote eepm tree found at: $remote_source"
else
remote_source="$(sync_local_source_to_remote "$explicit_source" "$target")"
fi
REMOTE_ARGS+=(--eepm-source explicit --eepm-dir "$remote_source")
elif [[ "$SOURCE_KIND" == "explicit" ]]; then
[[ -n "$SOURCE_PATH" ]] || fatal "Explicit source path is empty"
explicit_source="$(realpath "$SOURCE_PATH" 2>/dev/null || printf '%s\n' "$SOURCE_PATH")"
verify_eepm_tree "$explicit_source"
REMOTE_ARGS+=(--eepm-source explicit --eepm-dir "$explicit_source")
explicit_source="$(resolve_explicit_source_path "$SOURCE_PATH")"
remote_source="$(default_builder_source_path)"
if remote_eepm_tree_exists "$target" "$remote_source"; then
info "Remote eepm tree found at: $remote_source"
else
remote_source="$(sync_local_source_to_remote "$explicit_source" "$target")"
fi
REMOTE_ARGS+=(--eepm-source explicit --eepm-dir "$remote_source")
else
REMOTE_ARGS+=(--eepm-source "$SOURCE_KIND")
[[ -n "$BUILDER_USER" ]] && REMOTE_ARGS+=(--builder-user "$BUILDER_USER")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment