Skip to content

Commit f3ef267

Browse files
authored
Merge pull request #78 from vrothberg/fix-76
support multiple extra sources
2 parents 31cb4cf + 6ee5fb8 commit f3ef267

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
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}"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM docker.io/library/fedora:31
1+
FROM registry.fedoraproject.org/fedora:33
22

33
RUN dnf install -y jq skopeo findutils file wget 'dnf-command(download)'
44

test/10-from_rpms.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ load helpers
2323

2424
# let's press that the files are predictable
2525
[ "$(find ${d} -type f | wc -l)" -eq 7 ]
26-
[ -f "${d}/blobs/sha256/4ff0b5eb60927dc1aee6a7080790cfcc50765294b5939ea9e4c59ba1d7c83848" ]
27-
[ -f "${d}/blobs/sha256/81a0ee6e731852c9729cb1beb5d195a08671bd72f00f32be3a63c5243ec95f5c" ]
28-
[ -f "${d}/blobs/sha256/df4fddb6365e1e652941463dac3054ca58e9302e1bbdc454b611f84fde2e9cdd" ]
26+
[ -f "${d}/blobs/sha256/0a7d6bf1ec0c131b804cc85018b998988b39b66594db73475cf21adb54ab77d5" ]
27+
[ -f "${d}/blobs/sha256/b890aaedaf242fa7b42a467cffa2ead943171f34c4d81d566c198829f4e16e00" ]
28+
[ -f "${d}/blobs/sha256/e4d273091c8390bedb25ed76271faf1ef24d4456453b0a4eb305b0d202b9c3c6" ]
2929
}
3030

3131
@test "build from RPMS and push" {

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)