Shell script to automatically convert x86 image to armbuild


#1

Here is a small shell script to convert image from x86 base to ARM base using the ubuntu-debootstrap image.
This script is intended to be used in a docker-compose environment, to switch from images in your PC to image used on C1 server.

Please feel free to comment and improve it.

#!/bin/bash

# return as array
DOCKERFILE_LIST=( $(find . -name Dockerfile) )

function from_x86_to_arm {
  echo "Convert $1 from X86 to ARM"
  sed -i -e "s/FROM ubuntu-debootstrap/FROM armbuild\/ubuntu-debootstrap/g" $1
}

function from_arm_to_x86 {
  echo "Convert $1 from ARM to X86"
  sed -i -e "s/FROM armbuild\/ubuntu-debootstrap/FROM ubuntu-debootstrap/g" $1
}

# process all array items : [@]
for LINE in ${DOCKERFILE_LIST[@]}
do
  FIRST_LINE=$(head -n 1 ${LINE})
  case ${FIRST_LINE} in
    "FROM armbuild"* )
      from_arm_to_x86 ${LINE}
      ;;

    "FROM ubuntu"* )
      from_x86_to_arm ${LINE}
      ;;

  esac
done

#2

Nice :slight_smile: only too bad many docker images use pre-compiled code.