jenkins-pipelines/scripts/publish-docker-images.sh
Davlet Panech 93f0b873b6 Better safe_copy_dir & friends
This patch improves safe_copy_dir() and related functions:
* clean up & simplify implementation
* path sanity checks no longer depend on $PROJECT.
* safe_copy_dir(): --chown: resolve user name to UID on host
* safe_copy_dir(): interpret dest_dir as in "cp" command,
  but src_dir as in "rsync"

Story: 2010226
Task: 46386

Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
Change-Id: I9428d9fceb50f78840fc9fb93e8a6a132425cddc
2022-09-22 09:08:42 -04:00

46 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
source $(dirname "$0")/lib/job_utils.sh
require_job_env BUILD_HOME
require_job_env BUILD_STREAM
require_job_env TIMESTAMP
load_build_env
src_dir="$STX_BUILD_HOME/workspace/std/build-images"
dst_dir="$PUBLISH_DIR/outputs/docker-images"
if [[ ! -d "$src_dir" ]] ; then
bail "$src_dir doesn't exist, exiting"
fi
mkdir -p "$dst_dir"
declare -a find_args
or=
for os in $(echo $DOCKER_OS_LIST | sed 's/,/ /g') ; do
find_args+=(
$or
"-name" "images-$os-$BUILD_STREAM-versioned.lst" -o
"-name" "images-$os-$BUILD_STREAM-latest.lst"
)
or="-or"
done
if [[ ${#find_args[@]} -gt 0 ]] && [[ -d "$src_dir" ]] ; then
notice "publishing $DOCKER_BASE_OS $BUILD_STREAM docker image lists"
for src in $(find "$src_dir" -maxdepth 1 -type f \( "${find_args[@]}" \) ) ; do
if $DRY_RUN ; then
info "$src => $dst_dir/"
else
cp -v "$src" "$dst_dir/"
fi
done
fi