From 73c2b1ea7b9f1744b7188d46fd1a8d0eac92a4d5 Mon Sep 17 00:00:00 2001 From: Ivan Gulakov Date: Wed, 15 Jan 2025 10:48:41 +0000 Subject: tools: add platform to create_ec2_image.sh If we pass a platform argument to docker the script could also create us a rootfs image for arm64. (and maybe more in the future, who knows) Set it to linux/amd64 by default. While there, remove some confirmations by automating them. --- tools/create-ec2-rootfs.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tools/create-ec2-rootfs.sh') diff --git a/tools/create-ec2-rootfs.sh b/tools/create-ec2-rootfs.sh index 6f5dd2798..1756b569e 100755 --- a/tools/create-ec2-rootfs.sh +++ b/tools/create-ec2-rootfs.sh @@ -35,6 +35,7 @@ FORMAT="ext4" RESIZER="resize2fs" SIZE="1G" IMAGE="amazonlinux:2023" +PLATFORM="linux/amd64" # Display help function display_help() { @@ -43,6 +44,7 @@ display_help() { echo " -f, --format rootfs format (ext4 or xfs), default ext4" echo " -h, --help Display help message" echo " -n, --name rootfs name, default rootfs.ext4" + echo " -p, --platform linux platform type, default linux/amd64" echo " -s, --size rootfs size, default 1G" echo } @@ -77,6 +79,10 @@ while true; do NAME=$2 shift 2 ;; + -p | --platform) + PLATFORM=$2 + shift 2 + ;; -s | --size) SIZE=$2 shift 2 @@ -103,20 +109,20 @@ if [ -f "${NAME}" ]; then fi truncate -s ${SIZE} ${NAME} -mkfs.${FORMAT} ${NAME} +yes | mkfs.${FORMAT} ${NAME} sudo mount -o loop ${NAME} ${MOUNT_DIR} REMOVE_IMAGE=false -if [[ "$(sudo docker images -q ${IMAGE} 2>/dev/null)" == "" ]]; then +if [[ "$(sudo docker images --platform ${PLATFORM} -q ${IMAGE} 2>/dev/null)" == "" ]]; then REMOVE_IMAGE=true fi -CONTAINER=$(sudo docker create ${IMAGE}) +CONTAINER=$(sudo docker create --platform ${PLATFORM} ${IMAGE}) sudo docker export ${CONTAINER} | sudo tar -xC ${MOUNT_DIR} sudo docker rm ${CONTAINER} if "${REMOVE_IMAGE}" ; then - sudo docker rmi ${IMAGE} + sudo docker rmi -f ${IMAGE} fi sudo cp /etc/resolv.conf ${MOUNT_DIR}/etc/resolv.conf -- cgit mrf-deployment