*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
#!/bin/bash
|
2019-09-05 21:10:39 +00:00
|
|
|
|
|
|
|
# This script builds a Source Image via "drivers" to collect source
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
export ABV_NAME="SrcImg"
|
|
|
|
# TODO maybe a flag for this?
|
|
|
|
export source_image_suffix="-source"
|
|
|
|
|
2019-09-10 13:17:24 +00:00
|
|
|
# output version string
|
|
|
|
_version() {
|
|
|
|
echo "$(basename "${0}") version 0.1"
|
|
|
|
}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-10 13:17:24 +00:00
|
|
|
# output the cli usage and exit
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_usage() {
|
2019-09-10 13:17:24 +00:00
|
|
|
_version
|
2019-09-06 20:23:02 +00:00
|
|
|
echo "Usage: $(basename "$0") [-D] [-b <path>] [-c <path>] [-e <path>] [-r <path>] [-o <path>] [-i <image>] [-p <image>] [-l] [-d <drivers>]"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
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"
|
2019-09-10 13:10:56 +00:00
|
|
|
echo -e " -s <path>\tdirectory of SRPMS to add. Can be provided via SRPM_DIR env variable"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo -e " -o <path>\toutput the OCI image to path. Can be provided via OUTPUT_DIR env variable"
|
2019-09-06 20:23:02 +00:00
|
|
|
echo -e " -d <drivers>\tenumerate specific source drivers to run"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo -e " -l\t\tlist the source drivers available"
|
2019-09-06 20:42:59 +00:00
|
|
|
echo -e " -i <image>\timage reference to fetch and inspect its rootfs to derive sources"
|
|
|
|
echo -e " -p <image>\tpush source image to specified reference after build"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo -e " -D\t\tdebuging output. Can be set via DEBUG env variable"
|
2019-09-10 13:17:24 +00:00
|
|
|
echo -e " -h\t\tthis usage information"
|
|
|
|
echo -e " -v\t\tversion"
|
2019-07-31 23:19:47 +00:00
|
|
|
exit 1
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# sanity checks on startup
|
|
|
|
_init() {
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
# check for tools we depend on
|
2019-09-05 21:10:39 +00:00
|
|
|
for cmd in jq skopeo dnf file find tar stat date ; do
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
if [ -z "$(command -v ${cmd})" ] ; then
|
|
|
|
# TODO: maybe this could be individual checks so it can report
|
|
|
|
# where to find the tools
|
2019-09-09 18:32:13 +00:00
|
|
|
_error "please install package to provide '${cmd}'"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:32:13 +00:00
|
|
|
# _is_sourced tests whether this script is being source, or executed directly
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_is_sourced() {
|
|
|
|
# https://unix.stackexchange.com/a/215279
|
|
|
|
# thanks @tianon
|
|
|
|
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# count $character $string
|
2019-09-09 18:32:13 +00:00
|
|
|
_count_char_in_string() {
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
c="${2//[^${1}]}"
|
|
|
|
echo -n ${#c}
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:32:13 +00:00
|
|
|
# size of file/directory in bytes
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_size() {
|
2019-09-09 18:32:13 +00:00
|
|
|
du -b "${1}" | awk '{ ORS=""; print $1 }'
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 02:02:02 +00:00
|
|
|
# date timestamp in RFC 3339, to the nanosecond, but slightly golang style ...
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_date_ns() {
|
2019-09-06 02:02:02 +00:00
|
|
|
date --rfc-3339=ns | tr ' ' 'T' | tr -d '\n'
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# local `mktemp -d`
|
|
|
|
_mktemp_d() {
|
2019-09-09 18:32:13 +00:00
|
|
|
local v
|
|
|
|
v=$(mktemp -d "${TMPDIR:-/tmp}/${ABV_NAME}.XXXXXX")
|
|
|
|
_debug "mktemp -d --> ${v}"
|
|
|
|
echo "${v}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# local `mktemp`
|
|
|
|
_mktemp() {
|
2019-09-09 18:32:13 +00:00
|
|
|
local v
|
|
|
|
v=$(mktemp "${TMPDIR:-/tmp}/${ABV_NAME}.XXXXXX")
|
|
|
|
_debug "mktemp --> ${v}"
|
|
|
|
echo "${v}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# local rm -rf
|
|
|
|
_rm_rf() {
|
2019-09-06 20:23:02 +00:00
|
|
|
_debug "rm -rf ${*}"
|
|
|
|
rm -rf "${@}"
|
2019-09-05 21:10:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# local mkdir -p
|
|
|
|
_mkdir_p() {
|
|
|
|
if [ -n "${DEBUG}" ] ; then
|
2019-09-06 20:23:02 +00:00
|
|
|
mkdir -vp "${@}"
|
2019-09-05 21:10:39 +00:00
|
|
|
else
|
2019-09-06 20:23:02 +00:00
|
|
|
mkdir -p "${@}"
|
2019-09-05 21:10:39 +00:00
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# local tar
|
|
|
|
_tar() {
|
|
|
|
if [ -n "${DEBUG}" ] ; then
|
2019-09-06 20:23:02 +00:00
|
|
|
tar -v "${@}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
2019-09-06 20:23:02 +00:00
|
|
|
tar "${@}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# output things, only when $DEBUG is set
|
2019-09-04 20:48:52 +00:00
|
|
|
_debug() {
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
if [ -n "${DEBUG}" ] ; then
|
2019-09-09 18:32:13 +00:00
|
|
|
echo "[${ABV_NAME}][DEBUG] ${*}" >&2
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
}
|
2019-07-12 18:44:41 +00:00
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# general echo but with prefix
|
2019-09-04 20:48:52 +00:00
|
|
|
_info() {
|
2019-09-06 20:23:02 +00:00
|
|
|
echo "[${ABV_NAME}][INFO] ${*}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
_warn() {
|
2019-09-06 20:23:02 +00:00
|
|
|
echo "[${ABV_NAME}][WARN] ${*}" >&2
|
2019-09-05 21:10:39 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 20:48:52 +00:00
|
|
|
# general echo but with prefix
|
|
|
|
_error() {
|
2019-09-06 20:23:02 +00:00
|
|
|
echo "[${ABV_NAME}][ERROR] ${*}" >&2
|
2019-09-04 20:48:52 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
#
|
|
|
|
# parse the OCI image reference, accounting for:
|
|
|
|
# * transport name
|
|
|
|
# * presence or lack of transport port number
|
|
|
|
# * presence or lack of digest
|
|
|
|
# * presence or lack of image tag
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# return the image reference's digest, if any
|
|
|
|
#
|
|
|
|
parse_img_digest() {
|
|
|
|
local ref="${1}"
|
|
|
|
local digest=""
|
2019-09-09 18:32:13 +00:00
|
|
|
if [ "$(_count_char_in_string '@' "${ref}")" -gt 0 ] ; then
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
digest="${ref##*@}" # the digest after the "@"
|
2019-07-12 18:44:41 +00:00
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo -n "${digest}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# determine image base name (without tag or digest)
|
|
|
|
#
|
|
|
|
parse_img_base() {
|
|
|
|
local ref="${1%@*}" # just the portion before the digest "@"
|
2019-09-06 20:23:02 +00:00
|
|
|
local base="${ref}" # default base is their reference
|
|
|
|
local last_word="" # splitting up their reference to get the last word/chunk
|
|
|
|
last_word="$(echo "${ref}" | tr '/' '\n' | tail -1 )"
|
2019-09-09 18:32:13 +00:00
|
|
|
if [ "$(_count_char_in_string ':' "${last_word}")" -gt 0 ] ; then
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# which means everything before it is the base image name, **including
|
2019-09-06 20:23:02 +00:00
|
|
|
# transport (which could have a port delineation), and even a URI like network ports.
|
|
|
|
base="$(echo "${ref}" | rev | cut -d : -f 2 | rev )"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
echo -n "${base}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# determine, or guess, the image tag from the provided image reference
|
|
|
|
#
|
|
|
|
parse_img_tag() {
|
|
|
|
local ref="${1%@*}" # just the portion before the digest "@"
|
|
|
|
local tag="latest" # default tag
|
2019-09-05 21:10:39 +00:00
|
|
|
|
|
|
|
if [ -z "${ref}" ] ; then
|
|
|
|
echo -n "${tag}"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
local last_word="" # splitting up their reference to get the last word/chunk
|
|
|
|
last_word="$(echo "${ref}" | tr '/' '\n' | tail -1 )"
|
2019-09-09 18:32:13 +00:00
|
|
|
if [ "$(_count_char_in_string ':' "${last_word}")" -gt 0 ] ; then
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# if there are colons in the last segment after '/', then get that tag name
|
2019-09-06 20:23:02 +00:00
|
|
|
tag="${last_word#*:}" # this parameter expansion removes the prefix pattern before the ':'
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
echo -n "${tag}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# an inline prefixer for containers/image tools
|
|
|
|
#
|
|
|
|
ref_prefix() {
|
|
|
|
local ref="${1}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local pfxs
|
2019-09-09 18:32:13 +00:00
|
|
|
local ret
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# get the supported prefixes of the current version of skopeo
|
2019-09-06 20:23:02 +00:00
|
|
|
mapfile -t pfxs < <(skopeo copy --help | grep -A1 "Supported transports:" | grep -v "Supported transports" | sed 's/, /\n/g')
|
2019-09-09 18:32:13 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
2019-09-06 20:23:02 +00:00
|
|
|
|
|
|
|
for pfx in "${pfxs[@]}" ; do
|
|
|
|
if echo "${ref}" | grep -q "^${pfx}:" ; then
|
|
|
|
# break if we match a known prefix
|
|
|
|
echo "${ref}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# else default
|
|
|
|
echo "docker://${ref}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# an inline namer for the source image
|
|
|
|
# Initially this is a tagging convention (which if we try estesp/manifest-tool
|
|
|
|
# can be directly mapped into a manifest-list/image-index).
|
|
|
|
#
|
|
|
|
ref_src_img_tag() {
|
|
|
|
local ref="${1}"
|
2019-09-06 20:23:02 +00:00
|
|
|
echo -n "$(parse_img_tag "${ref}")""${source_image_suffix}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# call out to registry for the image reference's digest checksum
|
|
|
|
#
|
|
|
|
fetch_img_digest() {
|
|
|
|
local ref="${1}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local dgst
|
|
|
|
local ret
|
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
2019-09-06 20:23:02 +00:00
|
|
|
dgst=$(skopeo inspect "$(ref_prefix "${ref}")" | jq .Digest | tr -d \")
|
|
|
|
ret=$?
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
echo "ERROR: check the image reference: ${ref}" >&2
|
|
|
|
return $ret
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "${dgst}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# pull down the image to an OCI layout
|
|
|
|
# arguments: image ref
|
|
|
|
# returns: path:tag to the OCI layout
|
|
|
|
#
|
|
|
|
# any commands should only output to stderr, so that the caller can receive the
|
|
|
|
# path reference to the OCI layout.
|
|
|
|
#
|
|
|
|
fetch_img() {
|
|
|
|
local ref="${1}"
|
|
|
|
local dst="${2}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local base
|
|
|
|
local tag
|
|
|
|
local dgst
|
|
|
|
local from
|
2019-09-09 18:32:13 +00:00
|
|
|
local ret
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${dst}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
base="$(parse_img_base "${ref}")"
|
|
|
|
tag="$(parse_img_tag "${ref}")"
|
|
|
|
dgst="$(parse_img_digest "${ref}")"
|
|
|
|
from=""
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# skopeo currently only support _either_ tag _or_ digest, so we'll be specific.
|
|
|
|
if [ -n "${dgst}" ] ; then
|
2019-09-06 20:23:02 +00:00
|
|
|
from="$(ref_prefix "${base}")@${dgst}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
2019-09-06 20:23:02 +00:00
|
|
|
from="$(ref_prefix "${base}"):${tag}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
|
|
|
## destination name must have the image tag included (umoci expects it)
|
|
|
|
skopeo \
|
|
|
|
copy \
|
|
|
|
"${from}" \
|
|
|
|
"oci:${dst}:${tag}" >&2
|
2019-09-09 18:32:13 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo -n "${dst}:${tag}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# upack_img <oci layout path> <unpack path>
|
|
|
|
#
|
|
|
|
unpack_img() {
|
|
|
|
local image_dir="${1}"
|
|
|
|
local unpack_dir="${2}"
|
2019-09-06 20:42:59 +00:00
|
|
|
local ret
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
if [ -d "${unpack_dir}" ] ; then
|
|
|
|
_rm_rf "${unpack_dir}"
|
|
|
|
fi
|
|
|
|
|
2019-09-06 21:04:04 +00:00
|
|
|
if [ -n "$(command -v umoci)" ] ; then
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# can be done as non-root (even in a non-root container)
|
|
|
|
unpack_img_umoci "${image_dir}" "${unpack_dir}"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
|
|
|
# can be done as non-root (even in a non-root container)
|
|
|
|
unpack_img_bash "${image_dir}" "${unpack_dir}"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# unpack an image layout using only jq and bash
|
|
|
|
#
|
|
|
|
unpack_img_bash() {
|
|
|
|
local image_dir="${1}"
|
|
|
|
local unpack_dir="${2}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local mnfst_dgst
|
|
|
|
local layer_dgsts
|
2019-09-06 20:42:59 +00:00
|
|
|
local ret
|
|
|
|
|
|
|
|
_debug "unpacking with bash+jq"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# for compat with umoci (which wants the image tag as well)
|
|
|
|
if echo "${image_dir}" | grep -q ":" ; then
|
|
|
|
image_dir="${image_dir%:*}"
|
|
|
|
fi
|
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
mnfst_dgst="$(jq '.manifests[0].digest' "${image_dir}"/index.json | tr -d \")"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# Since we're landing the reference as an OCI layout, this mediaType is fairly predictable
|
|
|
|
# TODO don't always assume +gzip
|
2019-09-06 20:23:02 +00:00
|
|
|
layer_dgsts="$(jq '.layers[] | select(.mediaType == "application/vnd.oci.image.layer.v1.tar+gzip") | .digest' "${image_dir}"/blobs/"${mnfst_dgst/:/\/}" | tr -d \")"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${unpack_dir}/rootfs"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
for dgst in ${layer_dgsts} ; do
|
|
|
|
path="${image_dir}/blobs/${dgst/:/\/}"
|
2019-09-05 21:10:39 +00:00
|
|
|
tmp_file=$(_mktemp)
|
2019-09-06 20:42:59 +00:00
|
|
|
zcat "${path}" | _tar -t > "$tmp_file"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# look for '.wh.' entries. They must be removed from the rootfs
|
|
|
|
# _before_ extracting the archive, then the .wh. entries themselves
|
|
|
|
# need to not remain afterwards
|
2019-09-06 20:23:02 +00:00
|
|
|
grep '\.wh\.' "${tmp_file}" | while read -r wh_path ; do
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# if `some/path/.wh.foo` then `rm -rf `${unpack_dir}/some/path/foo`
|
|
|
|
# if `some/path/.wh..wh..opq` then `rm -rf `${unpack_dir}/some/path/*`
|
2019-09-06 20:23:02 +00:00
|
|
|
if [ "$(basename "${wh_path}")" == ".wh..wh..opq" ] ; then
|
|
|
|
_rm_rf "${unpack_dir}/rootfs/$(dirname "${wh_path}")/*"
|
|
|
|
elif basename "${wh_path}" | grep -qe '^\.wh\.' ; then
|
|
|
|
name=$(basename "${wh_path}" | sed -e 's/^\.wh\.//')
|
|
|
|
_rm_rf "${unpack_dir}/rootfs/$(dirname "${wh_path}")/${name}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-09-04 20:48:52 +00:00
|
|
|
_info "[unpacking] layer ${dgst}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# unpack layer to rootfs (without whiteouts)
|
2019-09-05 21:10:39 +00:00
|
|
|
zcat "${path}" | _tar --restrict --no-xattr --no-acls --no-selinux --exclude='*.wh.*' -x -C "${unpack_dir}/rootfs"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# some of the directories get unpacked as 0555, so removing them gives an EPERM
|
|
|
|
find "${unpack_dir}" -type d -exec chmod 0755 "{}" \;
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# unpack using umoci
|
|
|
|
#
|
|
|
|
unpack_img_umoci() {
|
|
|
|
local image_dir="${1}"
|
|
|
|
local unpack_dir="${2}"
|
|
|
|
|
2019-09-06 20:42:59 +00:00
|
|
|
_debug "unpacking with umoci"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# always assume we're not root I reckon
|
|
|
|
umoci unpack --rootless --image "${image_dir}" "${unpack_dir}" >&2
|
2019-09-06 02:30:38 +00:00
|
|
|
ret=$?
|
|
|
|
return $ret
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 02:30:38 +00:00
|
|
|
#
|
|
|
|
# copy an image from one location to another
|
|
|
|
#
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
push_img() {
|
2019-09-06 02:30:38 +00:00
|
|
|
local src="${1}"
|
|
|
|
local dst="${2}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-06 20:42:59 +00:00
|
|
|
_debug "pushing image ${src} to ${dst}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
2019-09-06 20:23:02 +00:00
|
|
|
skopeo copy --dest-tls-verify=false "$(ref_prefix "${src}")" "$(ref_prefix "${dst}")" # XXX for demo only
|
|
|
|
#skopeo copy "$(ref_prefix "${src}")" "$(ref_prefix "${dst}")"
|
2019-09-06 02:30:38 +00:00
|
|
|
ret=$?
|
|
|
|
return $ret
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# sets up a basic new OCI layout, for an image with the provided (or default 'latest') tag
|
|
|
|
#
|
|
|
|
layout_new() {
|
|
|
|
local out_dir="${1}"
|
|
|
|
local image_tag="${2:-latest}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local config
|
|
|
|
local mnfst
|
|
|
|
local config_sum
|
|
|
|
local mnfst_sum
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${out_dir}/blobs/sha256"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo '{"imageLayoutVersion":"1.0.0"}' > "${out_dir}/oci-layout"
|
2019-09-06 20:23:02 +00:00
|
|
|
config='
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
{
|
|
|
|
"created": "'$(_date_ns)'",
|
|
|
|
"architecture": "amd64",
|
|
|
|
"os": "linux",
|
|
|
|
"config": {},
|
|
|
|
"rootfs": {
|
|
|
|
"type": "layers",
|
|
|
|
"diff_ids": []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
2019-09-06 20:23:02 +00:00
|
|
|
config_sum=$(echo "${config}" | jq -c | tr -d '\n' | sha256sum | awk '{ ORS=""; print $1 }')
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo "${config}" | jq -c | tr -d '\n' > "${out_dir}/blobs/sha256/${config_sum}"
|
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
mnfst='
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
{
|
|
|
|
"schemaVersion": 2,
|
|
|
|
"config": {
|
|
|
|
"mediaType": "application/vnd.oci.image.config.v1+json",
|
|
|
|
"digest": "sha256:'"${config_sum}"'",
|
2019-09-06 20:23:02 +00:00
|
|
|
"size": '"$(_size "${out_dir}"/blobs/sha256/"${config_sum}")"'
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
},
|
|
|
|
"layers": []
|
|
|
|
}
|
|
|
|
'
|
2019-09-06 20:23:02 +00:00
|
|
|
mnfst_sum=$(echo "${mnfst}" | jq -c | tr -d '\n' | sha256sum | awk '{ ORS=""; print $1 }')
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
echo "${mnfst}" | jq -c | tr -d '\n' > "${out_dir}/blobs/sha256/${mnfst_sum}"
|
|
|
|
|
|
|
|
echo '
|
|
|
|
{
|
|
|
|
"schemaVersion": 2,
|
|
|
|
"manifests": [
|
|
|
|
{
|
|
|
|
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
|
|
|
"digest": "sha256:'"${mnfst_sum}"'",
|
2019-09-06 20:23:02 +00:00
|
|
|
"size": '"$(_size "${out_dir}"/blobs/sha256/"${mnfst_sum}")"',
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
"annotations": {
|
|
|
|
"org.opencontainers.image.ref.name": "'"${image_tag}"'"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
' | jq -c | tr -d '\n' > "${out_dir}/index.json"
|
|
|
|
}
|
|
|
|
|
|
|
|
# call this for every artifact, to insert it into an OCI layout
|
|
|
|
# args:
|
|
|
|
# * a path to the layout
|
|
|
|
# * a path to the artifact
|
|
|
|
# * the path inside the tar
|
2019-09-05 21:10:39 +00:00
|
|
|
# * json file to slurp in as annotations for this layer's OCI descriptor
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# * tag used in the layout (default is 'latest')
|
|
|
|
#
|
|
|
|
layout_insert() {
|
|
|
|
local out_dir="${1}"
|
|
|
|
local artifact_path="${2}"
|
|
|
|
local tar_path="${3}"
|
2019-09-05 21:10:39 +00:00
|
|
|
local annotations_file="${4}"
|
|
|
|
local image_tag="${5:-latest}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local mnfst_list
|
|
|
|
local mnfst_dgst
|
|
|
|
local mnfst
|
|
|
|
local tmpdir
|
|
|
|
local sum
|
|
|
|
local tmptar
|
|
|
|
local tmptar_sum
|
|
|
|
local tmptar_size
|
|
|
|
local config_sum
|
|
|
|
local tmpconfig
|
|
|
|
local tmpconfig_sum
|
|
|
|
local tmpconfig_size
|
|
|
|
local tmpmnfst
|
|
|
|
local tmpmnfst_sum
|
|
|
|
local tmpmnfst_size
|
|
|
|
local tmpmnfst_list
|
|
|
|
|
|
|
|
mnfst_list="${out_dir}/index.json"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# get the digest to the manifest
|
|
|
|
test -f "${mnfst_list}" || return 1
|
2019-09-06 20:23:02 +00:00
|
|
|
mnfst_dgst="$(jq --arg tag "${image_tag}" '
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
.manifests[]
|
2019-09-04 20:48:52 +00:00
|
|
|
| select(.annotations."org.opencontainers.image.ref.name" == $tag )
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
| .digest
|
2019-09-06 20:23:02 +00:00
|
|
|
' "${mnfst_list}" | tr -d \" | tr -d '\n' )"
|
|
|
|
mnfst="${out_dir}/blobs/${mnfst_dgst/:/\/}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
test -f "${mnfst}" || return 1
|
|
|
|
|
|
|
|
# make tar of new object
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpdir="$(_mktemp_d)"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# TODO account for "artifact_path" being a directory?
|
2019-09-06 20:23:02 +00:00
|
|
|
sum="$(sha256sum "${artifact_path}" | awk '{ print $1 }')"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# making a blob store in the layer
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${tmpdir}/blobs/sha256"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
cp "${artifact_path}" "${tmpdir}/blobs/sha256/${sum}"
|
2019-09-06 20:23:02 +00:00
|
|
|
if [ "$(basename "${tar_path}")" == "$(basename "${artifact_path}")" ] ; then
|
|
|
|
_mkdir_p "${tmpdir}/$(dirname "${tar_path}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# TODO this symlink need to be relative path, not to `/blobs/...`
|
|
|
|
ln -s "/blobs/sha256/${sum}" "${tmpdir}/${tar_path}"
|
|
|
|
else
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${tmpdir}/${tar_path}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# TODO this symlink need to be relative path, not to `/blobs/...`
|
2019-09-06 20:23:02 +00:00
|
|
|
ln -s "/blobs/sha256/${sum}" "${tmpdir}/${tar_path}/$(basename "${artifact_path}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
2019-09-06 20:23:02 +00:00
|
|
|
tmptar="$(_mktemp)"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# zero all the things for as consistent blobs as possible
|
|
|
|
_tar -C "${tmpdir}" --mtime=@0 --owner=0 --group=0 --mode='a+rw' --no-xattrs --no-selinux --no-acls -cf "${tmptar}" .
|
|
|
|
_rm_rf "${tmpdir}"
|
|
|
|
|
|
|
|
# checksum tar and move to blobs/sha256/$checksum
|
2019-09-06 20:23:02 +00:00
|
|
|
tmptar_sum="$(sha256sum "${tmptar}" | awk '{ ORS=""; print $1 }')"
|
|
|
|
tmptar_size="$(_size "${tmptar}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
mv "${tmptar}" "${out_dir}/blobs/sha256/${tmptar_sum}"
|
|
|
|
|
|
|
|
# find and read the prior config, mapped from the manifest
|
2019-09-06 20:23:02 +00:00
|
|
|
config_sum="$(jq '.config.digest' "${mnfst}" | tr -d \")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# use `jq` to append to prior config
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpconfig="$(_mktemp)"
|
|
|
|
jq -c \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg date "$(_date_ns)" \
|
2019-09-04 20:48:52 +00:00
|
|
|
--arg tmptar_sum "sha256:${tmptar_sum}" \
|
|
|
|
--arg comment "#(nop) BuildSourceImage adding artifact: ${sum}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
'
|
2019-09-04 20:48:52 +00:00
|
|
|
.created = $date
|
2019-09-05 21:10:39 +00:00
|
|
|
| .rootfs.diff_ids += [ $tmptar_sum ]
|
|
|
|
| .history += [
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
{
|
2019-09-04 20:48:52 +00:00
|
|
|
"created": $date,
|
|
|
|
"created_by": $comment
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
]
|
2019-09-06 20:23:02 +00:00
|
|
|
' "${out_dir}/blobs/${config_sum/:/\/}" > "${tmpconfig}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_rm_rf "${out_dir}/blobs/${config_sum/:/\/}"
|
|
|
|
|
|
|
|
# rename the config blob to its new checksum
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpconfig_sum="$(sha256sum "${tmpconfig}" | awk '{ ORS=""; print $1 }')"
|
|
|
|
tmpconfig_size="$(_size "${tmpconfig}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
mv "${tmpconfig}" "${out_dir}/blobs/sha256/${tmpconfig_sum}"
|
|
|
|
|
|
|
|
# append layers list in the manifest, and its new config mapping
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpmnfst="$(_mktemp)"
|
|
|
|
jq -c \
|
2019-09-04 20:48:52 +00:00
|
|
|
--arg tmpconfig_sum "sha256:${tmpconfig_sum}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg tmpconfig_size "${tmpconfig_size}" \
|
2019-09-04 20:48:52 +00:00
|
|
|
--arg tmptar_sum "sha256:${tmptar_sum}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg tmptar_size "${tmptar_size}" \
|
2019-09-06 20:23:02 +00:00
|
|
|
--arg artifact "$(basename "${artifact_path}")" \
|
2019-09-04 20:48:52 +00:00
|
|
|
--arg sum "sha256:${sum}" \
|
2019-09-05 21:10:39 +00:00
|
|
|
--slurpfile annotations_slup "${annotations_file}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
'
|
2019-09-05 21:10:39 +00:00
|
|
|
.config.digest = $tmpconfig_sum
|
|
|
|
| .config.size = ($tmpconfig_size|tonumber)
|
|
|
|
| {
|
|
|
|
"com.redhat.layer.type": "source",
|
|
|
|
"com.redhat.layer.content": $artifact,
|
|
|
|
"com.redhat.layer.content.checksum": $sum
|
|
|
|
} + $annotations_slup[0] as $annotations_merge
|
|
|
|
| .layers += [
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
{
|
|
|
|
"mediaType": "application/vnd.oci.image.layer.v1.tar",
|
2019-09-05 21:10:39 +00:00
|
|
|
"size": ($tmptar_size|tonumber),
|
2019-09-04 20:48:52 +00:00
|
|
|
"digest": $tmptar_sum,
|
2019-09-05 21:10:39 +00:00
|
|
|
"annotations": $annotations_merge
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
]
|
2019-09-06 20:23:02 +00:00
|
|
|
' "${mnfst}" > "${tmpmnfst}"
|
2019-09-05 21:10:39 +00:00
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
_rm_rf "${mnfst}"
|
|
|
|
|
|
|
|
# rename the manifest blob to its new checksum
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpmnfst_sum="$(sha256sum "${tmpmnfst}" | awk '{ ORS=""; print $1 }')"
|
|
|
|
tmpmnfst_size="$(_size "${tmpmnfst}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
mv "${tmpmnfst}" "${out_dir}/blobs/sha256/${tmpmnfst_sum}"
|
|
|
|
|
|
|
|
# map the mnfst_list to the new mnfst checksum
|
2019-09-06 20:23:02 +00:00
|
|
|
tmpmnfst_list="$(_mktemp)"
|
|
|
|
jq -c \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg tag "${image_tag}" \
|
2019-09-05 21:10:39 +00:00
|
|
|
--arg tmpmnfst_sum "sha256:${tmpmnfst_sum}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg tmpmnfst_size "${tmpmnfst_size}" \
|
|
|
|
'
|
2019-09-05 21:10:39 +00:00
|
|
|
[(.manifests[] | select(.annotations."org.opencontainers.image.ref.name" != $tag) )] as $manifests_reduced
|
|
|
|
| [
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
{
|
|
|
|
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
2019-09-05 21:10:39 +00:00
|
|
|
"digest": $tmpmnfst_sum,
|
|
|
|
"size": ($tmpmnfst_size|tonumber),
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
"annotations": {
|
2019-09-05 21:10:39 +00:00
|
|
|
"com.redhat.image.type": "source",
|
|
|
|
"org.opencontainers.image.ref.name": $tag
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 21:10:39 +00:00
|
|
|
] as $manifests_new
|
|
|
|
| .manifests = $manifests_reduced + $manifests_new
|
2019-09-06 20:23:02 +00:00
|
|
|
' "${mnfst_list}" > "${tmpmnfst_list}"
|
2019-09-05 21:10:39 +00:00
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
mv "${tmpmnfst_list}" "${mnfst_list}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Source Collection Drivers
|
|
|
|
#
|
|
|
|
# presently just bash functions. *notice* prefix the function name as `sourcedriver_`
|
|
|
|
# May become a ${ABV_NAME}/drivers.d/
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# * image ref
|
|
|
|
# * path to inspect
|
|
|
|
# * output path for source (specifc to this driver)
|
2019-09-05 21:10:39 +00:00
|
|
|
# * output path for JSON file of source's annotations
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
#
|
2019-09-05 21:10:39 +00:00
|
|
|
# The JSON of source annotations is the key to discovering the source artifact
|
|
|
|
# to be added and including rich metadata about that archive into the final
|
|
|
|
# image.
|
|
|
|
# The name of each JSON file is appending '.json' to the artifact's name. So if
|
|
|
|
# you have `foo-1.0.src.rpm` then there MUST be a corresponding
|
|
|
|
# `foo-1.0.src.rpm.json`.
|
|
|
|
# The data structure in this annotation is just a dict/hashmap, with key/val
|
|
|
|
# according to
|
|
|
|
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# driver to determine and fetch source rpms, based on the rootfs
|
|
|
|
#
|
|
|
|
sourcedriver_rpm_fetch() {
|
2019-09-04 20:48:52 +00:00
|
|
|
local self="${0#sourcedriver_*}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
local ref="${1}"
|
|
|
|
local rootfs="${2}"
|
|
|
|
local out_dir="${3}"
|
|
|
|
local manifest_dir="${4}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local release
|
|
|
|
local rpm
|
|
|
|
local srcrpm_buildtime
|
|
|
|
local srcrpm_pkgid
|
|
|
|
local srcrpm_name
|
|
|
|
local srcrpm_version
|
|
|
|
local srcrpm_epoch
|
|
|
|
local srcrpm_release
|
|
|
|
local mimetype
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# Get the RELEASEVER from the image
|
2019-09-06 20:23:02 +00:00
|
|
|
release=$(rpm -q --queryformat "%{VERSION}\n" --root "${rootfs}" -f /etc/os-release)
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# From the rootfs of the works image, build out the src rpms to operate over
|
2019-09-06 20:23:02 +00:00
|
|
|
for srcrpm in $(rpm -qa --root "${rootfs}" --queryformat '%{SOURCERPM}\n' | grep -v '^gpg-pubkey' | sort -u) ; do
|
2019-09-05 21:10:39 +00:00
|
|
|
if [ "${srcrpm}" == "(none)" ] ; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
rpm=${srcrpm%*.src.rpm}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
if [ ! -f "${out_dir}/${srcrpm}" ] ; then
|
2019-09-06 02:30:38 +00:00
|
|
|
_debug "--> fetching ${srcrpm}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
dnf download \
|
|
|
|
--quiet \
|
|
|
|
--installroot "${rootfs}" \
|
|
|
|
--release "${release}" \
|
|
|
|
--destdir "${out_dir}" \
|
|
|
|
--source \
|
2019-09-05 21:10:39 +00:00
|
|
|
"${rpm}"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
_warn "failed to fetch ${srcrpm}"
|
|
|
|
continue
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
2019-09-06 02:30:38 +00:00
|
|
|
_debug "--> using cached ${srcrpm}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
# TODO one day, check and confirm with %{sourcepkgid}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1741715
|
2019-09-06 20:23:02 +00:00
|
|
|
#rpm_sourcepkgid=$(rpm -q --root ${rootfs} --queryformat '%{sourcepkgid}' "${rpm}")
|
|
|
|
srcrpm_buildtime=$(rpm -qp --qf '%{buildtime}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_pkgid=$(rpm -qp --qf '%{pkgid}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_name=$(rpm -qp --qf '%{name}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_version=$(rpm -qp --qf '%{version}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_epoch=$(rpm -qp --qf '%{epoch}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_release=$(rpm -qp --qf '%{release}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
mimetype="$(file --brief --mime-type "${out_dir}"/"${srcrpm}")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
jq \
|
|
|
|
-n \
|
2019-09-05 21:10:39 +00:00
|
|
|
--arg filename "${srcrpm}" \
|
|
|
|
--arg name "${srcrpm_name}" \
|
|
|
|
--arg version "${srcrpm_version}" \
|
|
|
|
--arg epoch "${srcrpm_epoch}" \
|
|
|
|
--arg release "${srcrpm_release}" \
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
--arg buildtime "${srcrpm_buildtime}" \
|
|
|
|
--arg mimetype "${mimetype}" \
|
|
|
|
'
|
2019-09-04 20:48:52 +00:00
|
|
|
{
|
2019-09-05 21:10:39 +00:00
|
|
|
"source.artifact.filename": $filename,
|
2019-09-04 20:48:52 +00:00
|
|
|
"source.artifact.name": $name,
|
2019-09-05 21:10:39 +00:00
|
|
|
"source.artifact.version": $version,
|
|
|
|
"source.artifact.epoch": $epoch,
|
|
|
|
"source.artifact.release": $release,
|
2019-09-04 20:48:52 +00:00
|
|
|
"source.artifact.mimetype": $mimetype,
|
|
|
|
"source.artifact.buildtime": $buildtime
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
' \
|
2019-09-05 21:10:39 +00:00
|
|
|
> "${manifest_dir}/${srcrpm}.json"
|
2019-09-04 20:48:52 +00:00
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-09-04 20:48:52 +00:00
|
|
|
#
|
|
|
|
# driver to only package rpms from a provided rpm directory
|
2019-09-05 21:10:39 +00:00
|
|
|
# (koji use-case)
|
2019-09-04 20:48:52 +00:00
|
|
|
#
|
|
|
|
sourcedriver_rpm_dir() {
|
|
|
|
local self="${0#sourcedriver_*}"
|
|
|
|
local ref="${1}"
|
|
|
|
local rootfs="${2}"
|
|
|
|
local out_dir="${3}"
|
|
|
|
local manifest_dir="${4}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local srcrpm_buildtime
|
|
|
|
local srcrpm_pkgid
|
|
|
|
local srcrpm_name
|
|
|
|
local srcrpm_version
|
|
|
|
local srcrpm_epoch
|
|
|
|
local srcrpm_release
|
|
|
|
local mimetype
|
2019-09-04 20:48:52 +00:00
|
|
|
|
2019-09-09 18:32:13 +00:00
|
|
|
if [ -n "${SRPM_DIR}" ]; then
|
2019-09-06 02:09:06 +00:00
|
|
|
_debug "[$self] writing to $out_dir and $manifest_dir"
|
2019-09-09 18:32:13 +00:00
|
|
|
find "${SRPM_DIR}" -type f -name '*src.rpm' | while read -r srcrpm ; do
|
2019-09-05 21:10:39 +00:00
|
|
|
cp "${srcrpm}" "${out_dir}"
|
2019-09-06 20:23:02 +00:00
|
|
|
srcrpm="$(basename "${srcrpm}")"
|
2019-09-06 02:09:06 +00:00
|
|
|
_debug "[$self] --> ${srcrpm}"
|
2019-09-06 20:23:02 +00:00
|
|
|
srcrpm_buildtime=$(rpm -qp --qf '%{buildtime}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_pkgid=$(rpm -qp --qf '%{pkgid}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_name=$(rpm -qp --qf '%{name}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_version=$(rpm -qp --qf '%{version}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_epoch=$(rpm -qp --qf '%{epoch}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
srcrpm_release=$(rpm -qp --qf '%{release}' "${out_dir}"/"${srcrpm}" )
|
|
|
|
mimetype="$(file --brief --mime-type "${out_dir}"/"${srcrpm}")"
|
2019-09-05 21:10:39 +00:00
|
|
|
jq \
|
|
|
|
-n \
|
|
|
|
--arg filename "${srcrpm}" \
|
|
|
|
--arg name "${srcrpm_name}" \
|
|
|
|
--arg version "${srcrpm_version}" \
|
|
|
|
--arg epoch "${srcrpm_epoch}" \
|
|
|
|
--arg release "${srcrpm_release}" \
|
|
|
|
--arg buildtime "${srcrpm_buildtime}" \
|
|
|
|
--arg mimetype "${mimetype}" \
|
2019-09-06 20:23:02 +00:00
|
|
|
--arg pkgid "${srcrpm_pkgid}" \
|
2019-09-05 21:10:39 +00:00
|
|
|
'
|
|
|
|
{
|
|
|
|
"source.artifact.filename": $filename,
|
|
|
|
"source.artifact.name": $name,
|
|
|
|
"source.artifact.version": $version,
|
|
|
|
"source.artifact.epoch": $version,
|
|
|
|
"source.artifact.release": $release,
|
|
|
|
"source.artifact.mimetype": $mimetype,
|
2019-09-06 20:23:02 +00:00
|
|
|
"source.artifact.pkgid": $pkgid,
|
2019-09-05 21:10:39 +00:00
|
|
|
"source.artifact.buildtime": $buildtime
|
|
|
|
}
|
|
|
|
' \
|
|
|
|
> "${manifest_dir}/${srcrpm}.json"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
2019-09-04 20:48:52 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-07-12 18:44:41 +00:00
|
|
|
#
|
|
|
|
# If the caller specified a context directory,
|
|
|
|
#
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# slightly special driver, as it has a flag/env passed in, that it uses
|
|
|
|
#
|
|
|
|
sourcedriver_context_dir() {
|
2019-09-04 20:48:52 +00:00
|
|
|
local self="${0#sourcedriver_*}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
local ref="${1}"
|
|
|
|
local rootfs="${2}"
|
|
|
|
local out_dir="${3}"
|
|
|
|
local manifest_dir="${4}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local tarname
|
|
|
|
local mimetype
|
|
|
|
local source_info
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-04 20:48:52 +00:00
|
|
|
if [ -n "${CONTEXT_DIR}" ]; then
|
|
|
|
_debug "$self: writing to $out_dir and $manifest_dir"
|
2019-09-06 20:23:02 +00:00
|
|
|
tarname="context.tar"
|
2019-09-04 20:48:52 +00:00
|
|
|
_tar -C "${CONTEXT_DIR}" \
|
|
|
|
--mtime=@0 --owner=0 --group=0 --mode='a+rw' --no-xattrs --no-selinux --no-acls \
|
|
|
|
-cf "${out_dir}/${tarname}" .
|
2019-09-06 20:23:02 +00:00
|
|
|
mimetype="$(file --brief --mime-type "${out_dir}"/"${tarname}")"
|
|
|
|
source_info="${manifest_dir}/${tarname}.json"
|
2019-09-04 20:48:52 +00:00
|
|
|
jq \
|
|
|
|
-n \
|
|
|
|
--arg name "${tarname}" \
|
|
|
|
--arg mimetype "${mimetype}" \
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"source.artifact.name": $name,
|
|
|
|
"source.artifact.mimetype": $mimetype
|
|
|
|
}
|
|
|
|
' \
|
|
|
|
> "${source_info}"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
2019-07-12 18:44:41 +00:00
|
|
|
|
|
|
|
#
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# If the caller specified a extra directory
|
2019-07-12 18:44:41 +00:00
|
|
|
#
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# slightly special driver, as it has a flag/env passed in, that it uses
|
|
|
|
#
|
|
|
|
sourcedriver_extra_src_dir() {
|
2019-09-04 20:48:52 +00:00
|
|
|
local self="${0#sourcedriver_*}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
local ref="${1}"
|
|
|
|
local rootfs="${2}"
|
|
|
|
local out_dir="${3}"
|
|
|
|
local manifest_dir="${4}"
|
2019-09-06 20:23:02 +00:00
|
|
|
local tarname
|
|
|
|
local mimetype
|
|
|
|
local source_info
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
if [ -n "${EXTRA_SRC_DIR}" ]; then
|
2019-09-04 20:48:52 +00:00
|
|
|
_debug "$self: writing to $out_dir and $manifest_dir"
|
2019-09-06 20:23:02 +00:00
|
|
|
tarname="extra-src.tar"
|
2019-09-04 20:48:52 +00:00
|
|
|
_tar -C "${EXTRA_SRC_DIR}" \
|
|
|
|
--mtime=@0 --owner=0 --group=0 --mode='a+rw' --no-xattrs --no-selinux --no-acls \
|
|
|
|
-cf "${out_dir}/${tarname}" .
|
2019-09-06 20:23:02 +00:00
|
|
|
mimetype="$(file --brief --mime-type "${out_dir}"/"${tarname}")"
|
|
|
|
source_info="${manifest_dir}/${tarname}.json"
|
2019-09-04 20:48:52 +00:00
|
|
|
jq \
|
|
|
|
-n \
|
|
|
|
--arg name "${tarname}" \
|
|
|
|
--arg mimetype "${mimetype}" \
|
|
|
|
'
|
|
|
|
{
|
|
|
|
"source.artifact.name": $name,
|
|
|
|
"source.artifact.mimetype": $mimetype
|
|
|
|
}
|
|
|
|
' \
|
|
|
|
> "${source_info}"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main() {
|
2019-09-06 20:23:02 +00:00
|
|
|
local base_dir
|
|
|
|
local context_dir
|
|
|
|
local drivers
|
|
|
|
local extra_src_dir
|
|
|
|
local image_ref
|
|
|
|
local img_layout
|
|
|
|
local inspect_image_ref
|
|
|
|
local list_drivers
|
|
|
|
local output_dir
|
|
|
|
local push_image_ref
|
|
|
|
local ret
|
|
|
|
local rootfs
|
2019-09-09 18:32:13 +00:00
|
|
|
local srpm_dir
|
2019-09-06 20:23:02 +00:00
|
|
|
local src_dir
|
|
|
|
local src_img_dir
|
|
|
|
local src_img_tag
|
|
|
|
local src_name
|
|
|
|
local unpack_dir
|
|
|
|
local work_dir
|
|
|
|
|
|
|
|
_init "${@}"
|
|
|
|
|
|
|
|
base_dir="$(pwd)/${ABV_NAME}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# using the bash builtin to parse
|
2019-09-10 13:17:24 +00:00
|
|
|
while getopts ":hlvDi:c:s:e:o:b:d:p:" opts; do
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
case "${opts}" in
|
|
|
|
b)
|
|
|
|
base_dir="${OPTARG}"
|
|
|
|
;;
|
|
|
|
c)
|
2019-09-06 20:23:02 +00:00
|
|
|
context_dir=${OPTARG}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
|
|
|
e)
|
2019-09-06 20:23:02 +00:00
|
|
|
extra_src_dir=${OPTARG}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
2019-09-05 21:10:39 +00:00
|
|
|
d)
|
2019-09-06 20:23:02 +00:00
|
|
|
drivers=${OPTARG}
|
2019-09-04 20:48:52 +00:00
|
|
|
;;
|
2019-09-05 21:10:39 +00:00
|
|
|
h)
|
|
|
|
_usage
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
2019-09-05 21:10:39 +00:00
|
|
|
i)
|
2019-09-06 20:23:02 +00:00
|
|
|
inspect_image_ref=${OPTARG}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
|
|
|
l)
|
2019-09-06 20:23:02 +00:00
|
|
|
list_drivers=1
|
2019-09-05 21:10:39 +00:00
|
|
|
;;
|
|
|
|
o)
|
2019-09-06 20:23:02 +00:00
|
|
|
output_dir=${OPTARG}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
|
|
|
p)
|
2019-09-06 20:23:02 +00:00
|
|
|
push_image_ref=${OPTARG}
|
2019-09-05 21:10:39 +00:00
|
|
|
;;
|
2019-09-10 13:10:56 +00:00
|
|
|
s)
|
2019-09-09 18:32:13 +00:00
|
|
|
srpm_dir=${OPTARG}
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
;;
|
2019-09-10 13:17:24 +00:00
|
|
|
v)
|
|
|
|
_version
|
|
|
|
exit 0
|
|
|
|
;;
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
D)
|
|
|
|
export DEBUG=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
if [ -n "${list_drivers}" ] ; then
|
|
|
|
set | grep '^sourcedriver_.* () ' | tr -d ' ()'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# These three variables are slightly special, in that they're globals that
|
|
|
|
# specific drivers will expect.
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
export CONTEXT_DIR="${CONTEXT_DIR:-$context_dir}"
|
|
|
|
export EXTRA_SRC_DIR="${EXTRA_SRC_DIR:-$extra_src_dir}"
|
2019-09-09 18:32:13 +00:00
|
|
|
export SRPM_DIR="${SRPM_DIR:-$srpm_dir}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
output_dir="${OUTPUT_DIR:-$output_dir}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
export TMPDIR="${base_dir}/tmp"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
if [ -d "${TMPDIR}" ] ; then
|
|
|
|
_rm_rf "${TMPDIR}"
|
|
|
|
fi
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${TMPDIR}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# setup rootfs to be inspected (if any)
|
2019-09-06 20:23:02 +00:00
|
|
|
rootfs=""
|
|
|
|
image_ref=""
|
|
|
|
src_dir=""
|
|
|
|
work_dir="${base_dir}/work"
|
2019-09-05 21:10:39 +00:00
|
|
|
if [ -n "${inspect_image_ref}" ] ; then
|
|
|
|
_debug "Image Reference provided: ${inspect_image_ref}"
|
2019-09-06 20:23:02 +00:00
|
|
|
_debug "Image Reference base: $(parse_img_base "${inspect_image_ref}")"
|
|
|
|
_debug "Image Reference tag: $(parse_img_tag "${inspect_image_ref}")"
|
2019-09-05 21:10:39 +00:00
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
inspect_image_digest="$(parse_img_digest "${inspect_image_ref}")"
|
2019-09-05 21:10:39 +00:00
|
|
|
# determine missing digest before fetch, so that we fetch the precise image
|
|
|
|
# including its digest.
|
|
|
|
if [ -z "${inspect_image_digest}" ] ; then
|
2019-09-06 20:23:02 +00:00
|
|
|
inspect_image_digest="$(fetch_img_digest "$(parse_img_base "${inspect_image_ref}"):$(parse_img_tag "${inspect_image_ref}")")"
|
2019-09-05 21:10:39 +00:00
|
|
|
fi
|
|
|
|
_debug "inspect_image_digest: ${inspect_image_digest}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
img_layout=""
|
2019-09-05 21:10:39 +00:00
|
|
|
# if inspect and fetch image, then to an OCI layout dir
|
|
|
|
if [ ! -d "${work_dir}/layouts/${inspect_image_digest/:/\/}" ] ; then
|
|
|
|
# we'll store the image to a path based on its digest, that it can be reused
|
2019-09-06 20:23:02 +00:00
|
|
|
img_layout="$(fetch_img "$(parse_img_base "${inspect_image_ref}")":"$(parse_img_tag "${inspect_image_ref}")"@"${inspect_image_digest}" "${work_dir}"/layouts/"${inspect_image_digest/:/\/}" )"
|
2019-09-09 18:32:13 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
_error "failed to copy image: $(parse_img_base "${inspect_image_ref}"):$(parse_img_tag "${inspect_image_ref}")@${inspect_image_digest}"
|
|
|
|
fi
|
2019-09-05 21:10:39 +00:00
|
|
|
else
|
2019-09-06 20:23:02 +00:00
|
|
|
img_layout="${work_dir}/layouts/${inspect_image_digest/:/\/}:$(parse_img_tag "${inspect_image_ref}")"
|
2019-09-05 21:10:39 +00:00
|
|
|
fi
|
|
|
|
_debug "image layout: ${img_layout}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# unpack or reuse fetched image
|
2019-09-06 20:23:02 +00:00
|
|
|
unpack_dir="${work_dir}/unpacked/${inspect_image_digest/:/\/}"
|
2019-09-05 21:10:39 +00:00
|
|
|
if [ -d "${unpack_dir}" ] ; then
|
|
|
|
_rm_rf "${unpack_dir}"
|
|
|
|
fi
|
2019-09-06 20:23:02 +00:00
|
|
|
unpack_img "${img_layout}" "${unpack_dir}"
|
2019-09-06 20:42:59 +00:00
|
|
|
ret=$?
|
|
|
|
if [ ${ret} -ne 0 ] ; then
|
|
|
|
return ${ret}
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
rootfs="${unpack_dir}/rootfs"
|
2019-09-06 20:23:02 +00:00
|
|
|
image_ref="$(parse_img_base "${inspect_image_ref}"):$(parse_img_tag "${inspect_image_ref}")@${inspect_image_digest}"
|
2019-09-05 21:10:39 +00:00
|
|
|
src_dir="${base_dir}/src/${inspect_image_digest/:/\/}"
|
|
|
|
work_dir="${base_dir}/work/${inspect_image_digest/:/\/}"
|
|
|
|
_info "inspecting image reference ${image_ref}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
2019-09-05 21:10:39 +00:00
|
|
|
# if we're not fething an image, then this is basically a nop
|
|
|
|
rootfs="$(_mktemp_d)"
|
|
|
|
image_ref="scratch"
|
|
|
|
src_dir="$(_mktemp_d)"
|
|
|
|
work_dir="$(_mktemp_d)"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
2019-09-04 20:48:52 +00:00
|
|
|
_debug "image layout: ${img_layout}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# setup rootfs, from that OCI layout
|
|
|
|
local unpack_dir="${work_dir}/unpacked/${IMAGE_DIGEST/:/\/}"
|
|
|
|
if [ ! -d "${unpack_dir}" ] ; then
|
2019-09-09 18:32:13 +00:00
|
|
|
unpack_img "${img_layout}" "${unpack_dir}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
2019-09-04 20:48:52 +00:00
|
|
|
_debug "unpacked dir: ${unpack_dir}"
|
2019-09-05 21:10:39 +00:00
|
|
|
_debug "rootfs dir: ${rootfs}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
# clear prior driver's info about source to insert into Source Image
|
2019-09-05 21:10:39 +00:00
|
|
|
_rm_rf "${work_dir}/driver"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
|
|
|
if [ -n "${drivers}" ] ; then
|
|
|
|
# clean up the args passed by the caller ...
|
2019-09-06 20:23:02 +00:00
|
|
|
drivers="$(echo "${drivers}" | tr ',' ' '| tr '\n' ' ')"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
else
|
|
|
|
drivers="$(set | grep '^sourcedriver_.* () ' | tr -d ' ()' | tr '\n' ' ')"
|
|
|
|
fi
|
2019-09-05 21:10:39 +00:00
|
|
|
|
|
|
|
# Prep the OCI layout for the source image
|
2019-09-06 20:23:02 +00:00
|
|
|
src_img_dir="$(_mktemp_d)"
|
|
|
|
src_img_tag="latest-source" # XXX this tag needs to be a reference to the image built from
|
2019-09-05 21:10:39 +00:00
|
|
|
layout_new "${src_img_dir}" "${src_img_tag}"
|
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
# iterate on the drivers
|
|
|
|
#for driver in sourcedriver_rpm_fetch ; do
|
|
|
|
for driver in ${drivers} ; do
|
2019-09-04 20:48:52 +00:00
|
|
|
_info "calling $driver"
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${src_dir}/${driver#sourcedriver_*}"
|
|
|
|
_mkdir_p "${work_dir}/driver/${driver#sourcedriver_*}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
$driver \
|
2019-09-05 21:10:39 +00:00
|
|
|
"${image_ref}" \
|
|
|
|
"${rootfs}" \
|
|
|
|
"${src_dir}/${driver#sourcedriver_*}" \
|
|
|
|
"${work_dir}/driver/${driver#sourcedriver_*}"
|
2019-09-06 20:23:02 +00:00
|
|
|
ret=$?
|
2019-09-05 21:10:39 +00:00
|
|
|
if [ $ret -ne 0 ] ; then
|
2019-09-04 20:48:52 +00:00
|
|
|
_error "$driver failed"
|
|
|
|
fi
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# walk the driver output to determine layers to be added
|
2019-09-06 20:23:02 +00:00
|
|
|
find "${work_dir}/driver/${driver#sourcedriver_*}" -type f -name '*.json' | while read -r src_json ; do
|
|
|
|
src_name=$(basename "${src_json}" .json)
|
2019-09-05 21:10:39 +00:00
|
|
|
layout_insert \
|
|
|
|
"${src_img_dir}" \
|
|
|
|
"${src_dir}/${driver#sourcedriver_*}/${src_name}" \
|
|
|
|
"/${driver#sourcedriver_*}/${src_name}" \
|
|
|
|
"${src_json}" \
|
|
|
|
"${src_img_tag}"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ] ; then
|
|
|
|
# TODO probably just _error here to exit
|
|
|
|
_warn "failed to insert layout layer for ${src_name}"
|
|
|
|
fi
|
|
|
|
done
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
done
|
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
_info "packed 'oci:$src_img_dir:${src_img_tag}'"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
# TODO maybe look to a directory like /usr/libexec/BuildSourceImage/drivers/ for drop-ins to run
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
|
2019-09-06 20:23:02 +00:00
|
|
|
_info "succesfully packed 'oci:${src_img_dir}:${src_img_tag}'"
|
|
|
|
_debug "$(skopeo inspect oci:"${src_img_dir}":"${src_img_tag}")"
|
2019-09-06 02:02:02 +00:00
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
## if an output directory is provided then save a copy to it
|
|
|
|
if [ -n "${output_dir}" ] ; then
|
2019-09-05 21:10:39 +00:00
|
|
|
_mkdir_p "${output_dir}"
|
2019-09-06 02:30:38 +00:00
|
|
|
# XXX this $inspect_image_ref currently relies on the user passing in the `-i` flag
|
2019-09-06 20:23:02 +00:00
|
|
|
push_img "oci:$src_img_dir:${src_img_tag}" "oci:$output_dir:$(ref_src_img_tag "$(parse_img_tag "${inspect_image_ref}")")"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
2019-07-12 18:44:41 +00:00
|
|
|
|
2019-09-05 21:10:39 +00:00
|
|
|
if [ -n "${push_image_ref}" ] ; then
|
|
|
|
# XXX may have to parse this reference to ensure it is valid, and that it has a `-source` tag
|
|
|
|
push_img "oci:$src_img_dir:${src_img_tag}" "${push_image_ref}"
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
fi
|
2019-08-14 15:15:46 +00:00
|
|
|
|
*: big rewrite
_(this is a WIP)_
for the requirements to not be so bound to RPM only, breaking collection
of sources out into "plugins". Currently not much more sophisticated
than just iterating through bash functions that expect 3 argugments.
rootfs of the inspectee; output path for the sources collected; manifest
path.
The idea for the manifest is still loose, but how best to follow up the
plugin which collected source, to then have the rich metadata available
to attach to the individual "layers" that are produced for each source
component.
for the requirement of most contrained non-root container running this
script as non-root, we'll switch away from buildah for now. This ought
to just be skopeo copy, unpacking, inspecting, json, and skopeo copy. No
mounting, no namespacing, etc.
for the sake of writing unit tests (i.e. `bats`), break the script into
a way that it can be sourced and run the functions individually. Only
act like the whole script when run directly.
If `umoci` is available it will get used for some functions (like
unpacking), but it is not required and will be attempted with jq and
bash otherwise.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2019-08-19 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# only exec main if this is being called (this way we can source and test the functions)
|
2019-09-06 20:23:02 +00:00
|
|
|
_is_sourced || main "${@}"
|
2019-08-14 15:15:46 +00:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|