Skip to content

Commit

Permalink
Merge pull request #78 from vrothberg/fix-76
Browse files Browse the repository at this point in the history
support multiple extra sources
  • Loading branch information
vrothberg authored Jan 7, 2021
2 parents 31cb4cf + 6ee5fb8 commit f3ef267
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
22 changes: 14 additions & 8 deletions BuildSourceImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _usage() {
echo ""
echo -e " -b <path>\tbase path for source image builds"
echo -e " -c <path>\tbuild context for the container image. Can be provided via CONTEXT_DIR env variable"
echo -e " -e <path>\textra src for the container image. Can be provided via EXTRA_SRC_DIR env variable"
echo -e " -e <path>\textra src for the container image. Can be provided multiple times"
echo -e " -s <path>\tdirectory of SRPMS to add. Can be provided via SRPM_DIR env variable"
echo -e " -o <path>\toutput the OCI image to path. Can be provided via OUTPUT_DIR env variable"
echo -e " -d <drivers>\tenumerate specific source drivers to run"
Expand Down Expand Up @@ -1032,11 +1032,15 @@ sourcedriver_extra_src_dir() {
local tarname
local mimetype
local source_info
local counter=0

if [ -n "${EXTRA_SRC_DIR}" ]; then
for extra_src_dir in "${EXTRA_SRC_DIR_ARRAY[@]}"
do
_info "adding extra source directory $extra_src_dir"
_debug "$self: writing to $out_dir and $manifest_dir"
tarname="extra-src.tar"
_tar -C "${EXTRA_SRC_DIR}" \
tarname="extra-src-${counter}.tar"
counter+=1
_tar -C "${extra_src_dir}" \
--sort=name --mtime=@0 --owner=0 --group=0 --mode='a+rw' --no-xattrs --no-selinux --no-acls \
-cf "${out_dir}/${tarname}" .
mimetype="$(file --brief --mime-type "${out_dir}"/"${tarname}")"
Expand All @@ -1056,14 +1060,14 @@ sourcedriver_extra_src_dir() {
if [ $ret -ne 0 ] ; then
return 1
fi
fi
done
}


main() {
local base_dir
local input_context_dir
local input_extra_src_dir
local input_extra_src_dir_array
local input_srpm_dir
local drivers
local image_ref
Expand All @@ -1080,6 +1084,8 @@ main() {
local unpack_dir
local work_dir

declare -a input_extra_src_dir_array

_init "${@}"
_subcommand "${@}"

Expand All @@ -1094,7 +1100,7 @@ main() {
input_context_dir=${OPTARG}
;;
e)
input_extra_src_dir=${OPTARG}
input_extra_src_dir_array+=("${OPTARG}")
;;
d)
drivers=${OPTARG}
Expand Down Expand Up @@ -1143,7 +1149,7 @@ main() {
# These three variables are slightly special, in that they're globals that
# specific drivers will expect.
export CONTEXT_DIR="${CONTEXT_DIR:-$input_context_dir}"
export EXTRA_SRC_DIR="${EXTRA_SRC_DIR:-$input_extra_src_dir}"
export EXTRA_SRC_DIR_ARRAY=("${input_extra_src_dir_array[@]}")
export SRPM_DIR="${SRPM_DIR:-$input_srpm_dir}"

output_dir="${OUTPUT_DIR:-$output_dir}"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/fedora:31
FROM registry.fedoraproject.org/fedora:33

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

Expand Down
6 changes: 3 additions & 3 deletions test/10-from_rpms.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ load helpers

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

@test "build from RPMS and push" {
Expand Down
34 changes: 34 additions & 0 deletions test/14-extra_src_dirs.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bats -t

load helpers

@test "build with multiple extra source directories" {
local d
d=$(mktemp -d)
echo "temporary directory: ${d}"

extra_dir1=$(mktemp -d)
echo 123 > $extra_dir1/123.txt
extra_dir2=$(mktemp -d)
echo 456 > $extra_dir1/456.txt

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
[ "$status" -eq 0 ]
echo ${lines}
[[ ${lines[0]} =~ "[SrcImg][INFO] calling source collection drivers" ]]
[[ ${lines[3]} =~ "[SrcImg][INFO] adding extra source directory $extra_dir1" ]]
# get the number of the last line
n=$(expr ${#lines[@]} - 1)
[[ ${lines[${n}]} =~ "[SrcImg][INFO] copied to oci:/output:latest-source" ]]

echo "${d}"
[ -f "${d}/index.json" ]
[ -f "${d}/oci-layout" ]
[ "$(du -b ${d}/index.json | awk '{ print $1 }')" -gt 0 ]
[ "$(du -b ${d}/oci-layout | awk '{ print $1 }')" -gt 0 ]

# let's press that the files are predictable
[ "$(find ${d} -type f | wc -l)" -eq 6 ]
[ -f "${d}/blobs/sha256/135517984d8f66d4f805ba3c73b7364cc03adc70c5551a08d3f0351df4bbc9c2" ]
[ -f "${d}/blobs/sha256/31ae1ec2e9ea14ff12d3c00a9983faa79943ec9e341165f96800daf24c2ec9fb" ]
}

0 comments on commit f3ef267

Please sign in to comment.