Skip to content

Commit

Permalink
feat: add two more helper function for docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiola committed Oct 12, 2023
1 parent 3488039 commit 7ba7089
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions containers/docker/docker_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ docker_login() {
echo "${password}" | docker login --username "${username}" --password-stdin "${server}"
}

docker_retag_image() {
local image_to_retag="${1}"
local retagged_image="${2}"
local manifest_path=/tmp/manifest.json

oras manifest fetch --pretty "${image_to_retag}" --output "${manifest_path}"
oras manifest delete --force "${image_to_retag}"
oras manifest push --verbose "${retagged_image}" "${manifest_path}"
rm -fr "${manifest_path}"
}

docker_create_sbom_and_sign_image() {
local image="${1}"

syft packages "${image}" -o spdx-json > docker-image-sbom.spdx.json
cosign attach sbom --sbom docker-image-sbom.spdx.json "${image}"
image_digest=$(oras manifest fetch --descriptor "${image}" --pretty | jq -r '.digest')

if [[ -n "${COSIGN_PRIVATE_KEY}" ]]; then
cosign sign --key "${COSIGN_PRIVATE_KEY}" --recursive --yes "${image}"@"${image_digest}"
elif [[ -n "${SIGSTORE_ID_TOKEN}" ]]; then
cosign sign --recursive --yes "${image}"@"${image_digest}"
else
echo "no key found: skipping image signing"
fi
}

docker_clean_tag() {
echo "${1}" | perl -pe 's/^v(?P<semver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?:[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/$+{semver}/'
}
Expand Down

0 comments on commit 7ba7089

Please sign in to comment.