Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions utils/dind/install-dind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ install_dockerd_amazon() {
yes | amazon-linux-extras install docker
;;

2023*)
dnf -y install docker
;;

*) # Amazon Linux 1 uses versions like "2018.3" here, so dont bother enumerating
yum -y install docker
;;
Expand All @@ -130,7 +134,7 @@ install_jq() {
;;

amzn)
yum -y install jq
install_jq_amazon
;;

*)
Expand All @@ -141,6 +145,19 @@ install_jq() {
esac
}

install_jq_amazon() {
version=$(sed -n -e 's/^VERSION="\?\([^\"]*\)"\?/\1/p' /etc/os-release)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The command to get the Amazon Linux version is duplicated in install_dockerd_amazon, install_jq_amazon, and clean_after_install_amazon. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a helper function. This new function can then be called from all three places.

For example, you could add a helper function:

get_amazon_version() {
    sed -n -e 's/^VERSION=\"\?([^\"]*)\"\?/\1/p' /etc/os-release
}

And then call it like this:

version=$(get_amazon_version)

This change should also be applied to install_dockerd_amazon and clean_after_install_amazon.

case "$version" in
2023*)
dnf -y install jq
;;

*)
yum -y install jq
;;
esac
}

clean_after_install_debian_like() {
if [ "$apt_update_done" = "true" ]; then
echo "Cleaning apt after installs"
Expand All @@ -149,11 +166,27 @@ clean_after_install_debian_like() {
fi
}

clean_after_install_amazon() {
version=$(sed -n -e 's/^VERSION="\?\([^\"]*\)"\?/\1/p' /etc/os-release)
case "$version" in
2023*)
dnf clean all
;;

*)
# nothing to clean
;;
esac
}

clean_after_install() {
case "$distro" in
alpine | amzn)
alpine)
# nothing to clean
;;
amzn)
clean_after_install_amazon
;;
*)
clean_after_install_debian_like
;;
Expand Down
3 changes: 2 additions & 1 deletion utils/dind/tests/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ all:
--base_image=ubuntu:latest \
--base_image=amazonlinux:1 \
--base_image=amazonlinux:2 \
--base_image=amazonlinux:2023 \
--base_image=earthly/dind:alpine \
--base_image=earthly/dind:ubuntu

test-install-dind-for-image:
ARG --required base_image
FROM alpine
ARG TARGETPLATFORM
IF [ "${base_image%:*}" = "amazonlinux" ] && [ "$TARGETPLATFORM" = "linux/arm64" ] # no amazonlinux:1 for arm64/function not supported atm for amazonlinux:2 on arm - skipping
IF [ "${base_image}" = "amazonlinux:1" -o "${base_image}" = "amazonlinux:2" ] && [ "$TARGETPLATFORM" = "linux/arm64" ] # no amazonlinux:1 for arm64/function not supported atm for amazonlinux:2 on arm - skipping
RUN echo skipping $base_image with platform $TARGETPLATFORM
ELSE
FROM "$base_image"
Expand Down
Loading