Merge pull request #1175 from pikasTech/fix/1148-d518-build-proxy-restore
fix(agentrun): honor D518 YAML build proxy
This commit is contained in:
@@ -631,41 +631,84 @@ export function yamlLaneSourceRestoreScript(spec: AgentRunLaneSpec): string {
|
||||
return [
|
||||
"set +e",
|
||||
`workspace=${shQuote(spec.source.workspace)}`,
|
||||
`remote=${shQuote(spec.source.remote)}`,
|
||||
`branch=${shQuote(spec.source.branch)}`,
|
||||
"tmp_dir=$(mktemp -d)",
|
||||
"trap 'rm -rf \"$tmp_dir\"' EXIT",
|
||||
"git_user=''",
|
||||
"git_home=''",
|
||||
"case \"$workspace\" in",
|
||||
" /home/*/*)",
|
||||
" git_user=${workspace#/home/}",
|
||||
" git_user=${git_user%%/*}",
|
||||
" git_home=/home/$git_user",
|
||||
" if ! id \"$git_user\" >/dev/null 2>&1; then git_user=''; git_home=''; fi",
|
||||
" ;;",
|
||||
"esac",
|
||||
"case \"$remote\" in",
|
||||
" git@*:*)",
|
||||
" if [ -n \"$git_user\" ] && [ -f \"$git_home/.ssh/id_ed25519\" ]; then",
|
||||
" if [ -z \"${GIT_SSH_COMMAND:-}\" ]; then GIT_SSH_COMMAND=\"ssh -i $git_home/.ssh/id_ed25519 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$git_home/.ssh/known_hosts\"; fi",
|
||||
" export GIT_SSH_COMMAND",
|
||||
" else",
|
||||
" mkdir -p \"$HOME/.ssh\"",
|
||||
" chmod 700 \"$HOME/.ssh\" 2>/dev/null || true",
|
||||
" if [ -z \"${GIT_SSH_COMMAND:-}\" ]; then GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=accept-new\"; fi",
|
||||
" export GIT_SSH_COMMAND",
|
||||
" fi",
|
||||
" ;;",
|
||||
" ssh://*)",
|
||||
" if [ -n \"$git_user\" ] && [ -f \"$git_home/.ssh/id_ed25519\" ]; then",
|
||||
" if [ -z \"${GIT_SSH_COMMAND:-}\" ]; then GIT_SSH_COMMAND=\"ssh -i $git_home/.ssh/id_ed25519 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$git_home/.ssh/known_hosts\"; fi",
|
||||
" export GIT_SSH_COMMAND",
|
||||
" else",
|
||||
" mkdir -p \"$HOME/.ssh\"",
|
||||
" chmod 700 \"$HOME/.ssh\" 2>/dev/null || true",
|
||||
" if [ -z \"${GIT_SSH_COMMAND:-}\" ]; then GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=accept-new\"; fi",
|
||||
" export GIT_SSH_COMMAND",
|
||||
" fi",
|
||||
" ;;",
|
||||
"esac",
|
||||
"git_cmd() {",
|
||||
" if [ -n \"$git_user\" ]; then",
|
||||
" sudo -u \"$git_user\" env HOME=\"$git_home\" GIT_SSH_COMMAND=\"$GIT_SSH_COMMAND\" git \"$@\"",
|
||||
" else",
|
||||
" git \"$@\"",
|
||||
" fi",
|
||||
"}",
|
||||
"workspace_exists=false",
|
||||
"git config --global --add safe.directory \"$workspace\" 2>/dev/null || true",
|
||||
"if git -C \"$workspace\" rev-parse --git-dir >/dev/null 2>&1; then workspace_exists=true; fi",
|
||||
"git_cmd config --global --add safe.directory \"$workspace\" 2>/dev/null || true",
|
||||
"if git_cmd -C \"$workspace\" rev-parse --git-dir >/dev/null 2>&1; then workspace_exists=true; fi",
|
||||
"if [ \"$workspace_exists\" != true ]; then",
|
||||
" WORKSPACE=\"$workspace\" BRANCH=\"$branch\" node <<'NODE'",
|
||||
"console.log(JSON.stringify({ ok: false, status: 'skipped', failureKind: 'source-worktree-missing', workspace: process.env.WORKSPACE, branch: process.env.BRANCH, valuesPrinted: false }));",
|
||||
"NODE",
|
||||
" exit 0",
|
||||
"fi",
|
||||
"before_branch=$(git -C \"$workspace\" rev-parse --abbrev-ref HEAD 2>/dev/null || true)",
|
||||
"before_head=$(git -C \"$workspace\" rev-parse HEAD 2>/dev/null || true)",
|
||||
"status_short=$(git -C \"$workspace\" status --short 2>/dev/null || true)",
|
||||
"before_branch=$(git_cmd -C \"$workspace\" rev-parse --abbrev-ref HEAD 2>/dev/null || true)",
|
||||
"before_head=$(git_cmd -C \"$workspace\" rev-parse HEAD 2>/dev/null || true)",
|
||||
"status_short=$(git_cmd -C \"$workspace\" status --short 2>/dev/null || true)",
|
||||
"if [ -n \"$status_short\" ]; then",
|
||||
" WORKSPACE=\"$workspace\" BRANCH=\"$branch\" BEFORE_BRANCH=\"$before_branch\" BEFORE_HEAD=\"$before_head\" STATUS_SHORT=\"$status_short\" node <<'NODE'",
|
||||
"console.log(JSON.stringify({ ok: false, status: 'skipped', failureKind: 'source-worktree-dirty', workspace: process.env.WORKSPACE, branch: process.env.BRANCH, before: { branch: process.env.BEFORE_BRANCH || null, head: process.env.BEFORE_HEAD || null, detached: process.env.BEFORE_BRANCH === 'HEAD' }, statusShort: process.env.STATUS_SHORT || null, valuesPrinted: false }));",
|
||||
"NODE",
|
||||
" exit 0",
|
||||
"fi",
|
||||
"git -C \"$workspace\" fetch origin \"$branch\" > \"$tmp_dir/fetch.out\" 2> \"$tmp_dir/fetch.err\"",
|
||||
"git_cmd -C \"$workspace\" fetch origin \"$branch\" > \"$tmp_dir/fetch.out\" 2> \"$tmp_dir/fetch.err\"",
|
||||
"fetch_exit=$?",
|
||||
"remote_branch_commit=$(git -C \"$workspace\" rev-parse \"refs/remotes/origin/$branch\" 2>/dev/null || true)",
|
||||
"remote_branch_commit=$(git_cmd -C \"$workspace\" rev-parse \"refs/remotes/origin/$branch\" 2>/dev/null || true)",
|
||||
"checkout_exit=1",
|
||||
"if [ \"$fetch_exit\" -eq 0 ] && [ -n \"$remote_branch_commit\" ]; then",
|
||||
" git -C \"$workspace\" checkout -B \"$branch\" \"refs/remotes/origin/$branch\" > \"$tmp_dir/checkout.out\" 2> \"$tmp_dir/checkout.err\"",
|
||||
" git_cmd -C \"$workspace\" checkout -B \"$branch\" \"refs/remotes/origin/$branch\" > \"$tmp_dir/checkout.out\" 2> \"$tmp_dir/checkout.err\"",
|
||||
" checkout_exit=$?",
|
||||
"else",
|
||||
" : > \"$tmp_dir/checkout.out\"",
|
||||
" : > \"$tmp_dir/checkout.err\"",
|
||||
"fi",
|
||||
"after_branch=$(git -C \"$workspace\" rev-parse --abbrev-ref HEAD 2>/dev/null || true)",
|
||||
"after_head=$(git -C \"$workspace\" rev-parse HEAD 2>/dev/null || true)",
|
||||
"after_status_short=$(git -C \"$workspace\" status --short 2>/dev/null || true)",
|
||||
"after_branch=$(git_cmd -C \"$workspace\" rev-parse --abbrev-ref HEAD 2>/dev/null || true)",
|
||||
"after_head=$(git_cmd -C \"$workspace\" rev-parse HEAD 2>/dev/null || true)",
|
||||
"after_status_short=$(git_cmd -C \"$workspace\" status --short 2>/dev/null || true)",
|
||||
"fetch_err=$(tail -n 20 \"$tmp_dir/fetch.err\" 2>/dev/null | tr '\\n' ' ' | cut -c1-1200)",
|
||||
"checkout_err=$(tail -n 20 \"$tmp_dir/checkout.err\" 2>/dev/null | tr '\\n' ' ' | cut -c1-1200)",
|
||||
"WORKSPACE=\"$workspace\" BRANCH=\"$branch\" BEFORE_BRANCH=\"$before_branch\" BEFORE_HEAD=\"$before_head\" FETCH_EXIT=\"$fetch_exit\" CHECKOUT_EXIT=\"$checkout_exit\" REMOTE_BRANCH_COMMIT=\"$remote_branch_commit\" AFTER_BRANCH=\"$after_branch\" AFTER_HEAD=\"$after_head\" AFTER_STATUS_SHORT=\"$after_status_short\" FETCH_ERR=\"$fetch_err\" CHECKOUT_ERR=\"$checkout_err\" node <<'NODE'",
|
||||
@@ -778,9 +821,15 @@ export function yamlLaneBuildImageSubmitScript(spec: AgentRunLaneSpec, sourceCom
|
||||
" trap write_failed_status EXIT",
|
||||
" cd \"$workspace\"",
|
||||
" image=\"$image_repository:$env_identity\"",
|
||||
" all_proxy_value=${https_proxy_value:-$http_proxy_value}",
|
||||
" if [ -n \"$http_proxy_value\" ]; then export HTTP_PROXY=\"$http_proxy_value\" http_proxy=\"$http_proxy_value\"; fi",
|
||||
" if [ -n \"$https_proxy_value\" ]; then export HTTPS_PROXY=\"$https_proxy_value\" https_proxy=\"$https_proxy_value\"; fi",
|
||||
" if [ -n \"$all_proxy_value\" ]; then export ALL_PROXY=\"$all_proxy_value\" all_proxy=\"$all_proxy_value\"; fi",
|
||||
" if [ -n \"$no_proxy_value\" ]; then export NO_PROXY=\"$no_proxy_value\" no_proxy=\"$no_proxy_value\"; fi",
|
||||
" args=\"--network $network\"",
|
||||
" if [ -n \"$http_proxy_value\" ]; then args=\"$args --build-arg HTTP_PROXY=$http_proxy_value --build-arg http_proxy=$http_proxy_value\"; fi",
|
||||
" if [ -n \"$https_proxy_value\" ]; then args=\"$args --build-arg HTTPS_PROXY=$https_proxy_value --build-arg https_proxy=$https_proxy_value\"; fi",
|
||||
" if [ -n \"$all_proxy_value\" ]; then args=\"$args --build-arg ALL_PROXY=$all_proxy_value --build-arg all_proxy=$all_proxy_value\"; fi",
|
||||
" if [ -n \"$no_proxy_value\" ]; then args=\"$args --build-arg NO_PROXY=$no_proxy_value --build-arg no_proxy=$no_proxy_value\"; fi",
|
||||
" build_arg_values=$(BUILD_ARGS_JSON=\"$build_args_json\" node <<'NODE'",
|
||||
"const values = JSON.parse(process.env.BUILD_ARGS_JSON || '[]');",
|
||||
|
||||
Reference in New Issue
Block a user