Skip to content

Commit

Permalink
feat: docker-compose artifact delta generation
Browse files Browse the repository at this point in the history
Changelog: Title
Ticket: None
Signed-off-by: Robbe Goethals <[email protected]>
  • Loading branch information
GoethalsRobbe committed Apr 17, 2024
1 parent f73f24e commit ac28b09
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions gen/app-gen
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Usage: $0 [options] [-- [options-for-mender-artifact] ]
--output-path - Path to output artifact file. Default: reboot-artifact.mender
--image [current-url,]new-url - Path to output artifact file. Default: reboot-artifact.mender
--deep-delta - Calculate delta by parsing the image
--manifests-dir - Directory containing orchestrator-specific manifests describing the deployment
--manifests-dir [current-dir,]new-dir - Directory containing orchestrator-specific manifests describing the deployment
--platform - Platform of the images, e.g.: linux/arm/v7
--orchestrator - Name of the orchestrator, and name of the sub-module, e.g.: docker-compose
--k8s-ctr-address - k8s orchestrator specific: containerd address, e.g.: /run/k3s/containerd/containerd.sock
Expand Down Expand Up @@ -74,7 +74,8 @@ orchestrator=""
k8s_ctr_address=""
k8s_namespace=""
platform=""
manifests_dir=""
manifests_current_dir=""
manifests_new_dir=""
declare -a images=()
declare -a images_shas=()
deep_delta=false
Expand All @@ -98,7 +99,8 @@ while test $# -gt 0; do
if [ -z "$2" ]; then
show_help_and_exit_error
fi
manifests_dir="$2"
manifests_current_dir=$( echo "$2" | cut -f1 -d,)
manifests_new_dir=$( echo "$2" | cut -f2 -d,)
shift 2
;;
--orchestrator | -o)
Expand Down Expand Up @@ -203,7 +205,7 @@ if [ -z "${platform}" ]; then
show_help_and_exit_error
fi

if [ -z "${manifests_dir}" ]; then
if [ -z "${manifests_current_dir}" ]; then
echo "Directory containing manifests not specified. Aborting." >&2
show_help_and_exit_error
fi
Expand All @@ -212,10 +214,49 @@ if [ ${#images[@]} -lt 1 ]; then
if [[ "${orchestrator}" == "${DOCKER_COMPOSE_ORCHESTRATOR}" ]]; then
echo "No specific images specified. Will try to extract from docker-compose.yaml file." >&2

while read -r img; do
images+=("$img")
images+=("$img")
done < <( docker compose --project-directory "$manifests_dir" config --images)
if [[ "$manifests_current_dir" == "$manifests_new_dir" ]]; then
while read -r img; do
images+=("$img")
images+=("$img")
done < <( docker compose --project-directory "$manifests_current_dir" config --images)
else
declare -a current_images=()
declare -a new_images=()

while read -r img; do
current_images+=("$img")
done < <( docker compose --project-directory "$manifests_current_dir" config --images)

while read -r img; do
new_images+=("$img")
done < <( docker compose --project-directory "$manifests_new_dir" config --images)

for i in "${!current_images[@]}"; do
for j in "${!new_images[@]}"; do
# if it's a full match, don't include because it was already included in previous docker-compose
if [ "${current_images[i]}" == "${new_images[j]}" ]; then
unset 'current_images[i]'
unset 'new_images[j]'
continue 2
# if it's a match up until the tag, include for update
elif [ "${current_images[i]%%:*}" == "${new_images[j]%%:*}" ]; then
images+=("${current_images[i]}")
images+=("${new_images[j]}")
unset 'current_images[i]'
unset 'new_images[j]'
continue 2
fi
done
# if it isn't a match, don't include because it's removed from docker-compose
unset 'current_images[i]'
done

for i in "${!new_images[@]}"; do
images+=("${new_images[i]}")
images+=("${new_images[i]}")
unset 'new_images[i]'
done
fi

if [ ${#images[@]} -lt 1 ]; then
echo "Image extraction from docker-compose.yaml failed. Aborting." >&2
Expand Down Expand Up @@ -565,7 +606,7 @@ generate_metadata() {

prepare_images "${temp_dir}/images"
( cd "${temp_dir}" && tar czvf images.tar.gz images )
cp -a "${manifests_dir}" "${temp_dir}/manifests"
cp -a "${manifests_current_dir}" "${temp_dir}/manifests"
( cd "${temp_dir}" && tar czvf "manifests.tar.gz" manifests )
generate_metadata "${temp_dir}/metadata.json"

Expand Down

0 comments on commit ac28b09

Please sign in to comment.