Skip to content

Commit e35de2c

Browse files
committed
support multiple extra sources
Support specifying `-e $EXTRA_SOURCE_DIR` multiple times. The EXTRA_SRC_DIR environment variable has been removed. Fixes: #76 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
1 parent 31cb4cf commit e35de2c

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

BuildSourceImage.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _usage() {
2020
echo ""
2121
echo -e " -b <path>\tbase path for source image builds"
2222
echo -e " -c <path>\tbuild context for the container image. Can be provided via CONTEXT_DIR env variable"
23-
echo -e " -e <path>\textra src for the container image. Can be provided via EXTRA_SRC_DIR env variable"
23+
echo -e " -e <path>\textra src for the container image. Can be provided multiple times"
2424
echo -e " -s <path>\tdirectory of SRPMS to add. Can be provided via SRPM_DIR env variable"
2525
echo -e " -o <path>\toutput the OCI image to path. Can be provided via OUTPUT_DIR env variable"
2626
echo -e " -d <drivers>\tenumerate specific source drivers to run"
@@ -1032,11 +1032,15 @@ sourcedriver_extra_src_dir() {
10321032
local tarname
10331033
local mimetype
10341034
local source_info
1035+
local counter=0
10351036

1036-
if [ -n "${EXTRA_SRC_DIR}" ]; then
1037+
for extra_src_dir in "${EXTRA_SRC_DIR_ARRAY[@]}"
1038+
do
1039+
_info "adding extra source directory $extra_src_dir"
10371040
_debug "$self: writing to $out_dir and $manifest_dir"
1038-
tarname="extra-src.tar"
1039-
_tar -C "${EXTRA_SRC_DIR}" \
1041+
tarname="extra-src-${counter}.tar"
1042+
counter+=1
1043+
_tar -C "${extra_src_dir}" \
10401044
--sort=name --mtime=@0 --owner=0 --group=0 --mode='a+rw' --no-xattrs --no-selinux --no-acls \
10411045
-cf "${out_dir}/${tarname}" .
10421046
mimetype="$(file --brief --mime-type "${out_dir}"/"${tarname}")"
@@ -1056,14 +1060,14 @@ sourcedriver_extra_src_dir() {
10561060
if [ $ret -ne 0 ] ; then
10571061
return 1
10581062
fi
1059-
fi
1063+
done
10601064
}
10611065

10621066

10631067
main() {
10641068
local base_dir
10651069
local input_context_dir
1066-
local input_extra_src_dir
1070+
local input_extra_src_dir_array
10671071
local input_srpm_dir
10681072
local drivers
10691073
local image_ref
@@ -1080,6 +1084,8 @@ main() {
10801084
local unpack_dir
10811085
local work_dir
10821086

1087+
declare -a input_extra_src_dir_array
1088+
10831089
_init "${@}"
10841090
_subcommand "${@}"
10851091

@@ -1094,7 +1100,7 @@ main() {
10941100
input_context_dir=${OPTARG}
10951101
;;
10961102
e)
1097-
input_extra_src_dir=${OPTARG}
1103+
input_extra_src_dir_array+=("${OPTARG}")
10981104
;;
10991105
d)
11001106
drivers=${OPTARG}
@@ -1143,7 +1149,7 @@ main() {
11431149
# These three variables are slightly special, in that they're globals that
11441150
# specific drivers will expect.
11451151
export CONTEXT_DIR="${CONTEXT_DIR:-$input_context_dir}"
1146-
export EXTRA_SRC_DIR="${EXTRA_SRC_DIR:-$input_extra_src_dir}"
1152+
export EXTRA_SRC_DIR_ARRAY=("${input_extra_src_dir_array[@]}")
11471153
export SRPM_DIR="${SRPM_DIR:-$input_srpm_dir}"
11481154

11491155
output_dir="${OUTPUT_DIR:-$output_dir}"

test/14-extra_src_dirs.bats

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bats -t
2+
3+
load helpers
4+
5+
@test "build with multiple extra source directories" {
6+
local d
7+
d=$(mktemp -d)
8+
echo "temporary directory: ${d}"
9+
10+
extra_dir1=$(mktemp -d)
11+
echo 123 > $extra_dir1/123.txt
12+
extra_dir2=$(mktemp -d)
13+
echo 456 > $extra_dir1/456.txt
14+
15+
run_ctr -v $(pwd)/.testprep/srpms/:/src:ro --mount type=bind,source=${d},destination=/output $CTR_IMAGE -e $extra_dir1 -e $extra_dir2 -o /output
16+
[ "$status" -eq 0 ]
17+
echo ${lines}
18+
[[ ${lines[0]} =~ "[SrcImg][INFO] calling source collection drivers" ]]
19+
[[ ${lines[3]} =~ "[SrcImg][INFO] adding extra source directory $extra_dir1" ]]
20+
# get the number of the last line
21+
n=$(expr ${#lines[@]} - 1)
22+
[[ ${lines[${n}]} =~ "[SrcImg][INFO] copied to oci:/output:latest-source" ]]
23+
24+
echo "${d}"
25+
[ -f "${d}/index.json" ]
26+
[ -f "${d}/oci-layout" ]
27+
[ "$(du -b ${d}/index.json | awk '{ print $1 }')" -gt 0 ]
28+
[ "$(du -b ${d}/oci-layout | awk '{ print $1 }')" -gt 0 ]
29+
30+
# let's press that the files are predictable
31+
[ "$(find ${d} -type f | wc -l)" -eq 6 ]
32+
[ -f "${d}/blobs/sha256/135517984d8f66d4f805ba3c73b7364cc03adc70c5551a08d3f0351df4bbc9c2" ]
33+
[ -f "${d}/blobs/sha256/31ae1ec2e9ea14ff12d3c00a9983faa79943ec9e341165f96800daf24c2ec9fb" ]
34+
}

0 commit comments

Comments
 (0)