diff --git a/README.md b/README.md index dcb055d2..5f385076 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ For use cases where having container images already available in Docker is neede 1. Create a file named `images.txt` in the [images/hook-embedded/](images/hook-embedded/) directory. 1. Populate this `images.txt` file with the list of images to be embedded. See [images/hook-embedded/images.txt.example](images/hook-embedded/images.txt.example) for details on the required file format. -1. Change directories to [images/hook-embedded/](images/hook-embedded/) and run the [pull-images.sh](images/hook-embedded/pull-images.sh) script. Read the comments at the top of the script for more details. +1. Change directories to [images/hook-embedded/](images/hook-embedded/) and run [`pull-images.sh`](images/hook-embedded/pull-images.sh) script when building amd64 images and run [`pull-images.sh arm64`](images/hook-embedded/pull-images.sh) when building arm64 images. Read the comments at the top of the script for more details. 1. Change directories to the root of the HookOS repository and run `sudo ./build.sh build ...` to build the HookOS kernel and ramdisk. FYI, `sudo` is needed as DIND changes file ownerships to root. ### Build system TO-DO list diff --git a/images/hook-embedded/pull-images.sh b/images/hook-embedded/pull-images.sh index a225176c..88df51df 100755 --- a/images/hook-embedded/pull-images.sh +++ b/images/hook-embedded/pull-images.sh @@ -17,10 +17,11 @@ set -euo pipefail function main() { local dind_container="$1" local images_file="$2" + local arch="$3" # as this function maybe called multiple times, we need to ensure the container is removed - trap "docker rm -f ${dind_container} &> /dev/null" RETURN + trap "docker rm -f "${dind_container}" &> /dev/null" RETURN # we're using set -e so the trap on RETURN will not be executed when a command fails - trap "docker rm -f ${dind_container} &> /dev/null" EXIT + trap "docker rm -f "${dind_container}" &> /dev/null" EXIT # start DinD container # In order to avoid the src bind mount directory (./images/) ownership from changing to root # we don't bind mount to /var/lib/docker in the container because the DinD container is running as root and @@ -34,26 +35,27 @@ function main() { sleep 1 done + # remove the contents of /var/lib/docker-embedded so that any previous images are removed. Without this it seems to cause boot issues. + docker exec "${dind_container}" sh -c "rm -rf /var/lib/docker-embedded/*" + # pull images from list # this expects a file named images.txt in the same directory as this script # the format of this file is line separated: # # the || [ -n "$first_image" ] is to handle the last line of the file that doesn't have a newline. - while IFS=" " read -r first_image image_tag || [ -n "$first_image" ] ; do + while IFS=" " read -r first_image image_tag || [ -n "${first_image}" ] ; do echo -e "----------------------- $first_image -----------------------" - docker exec "${dind_container}" docker pull $first_image - if [[ $image_tag != "" ]]; then - docker exec "${dind_container}" docker tag $first_image $image_tag + docker exec "${dind_container}" docker pull --platform=linux/"${arch}" "${first_image}" + if [[ "${image_tag}" != "" ]]; then + docker exec "${dind_container}" docker tag "${first_image}" "${image_tag}" fi done < "${images_file}" - # remove the contents of /var/lib/docker-embedded so that any previous images are removed. Without this it seems to cause boot issues. - docker exec "${dind_container}" sh -c "rm -rf /var/lib/docker-embedded/*" # We need to copy /var/lib/docker to /var/lib/docker-embedded in order for HookOS to use the Docker images in its build. docker exec "${dind_container}" sh -c "cp -a /var/lib/docker/* /var/lib/docker-embedded/" } -arch="amd64" +arch="${1-amd64}" dind_container_name="hookos-dind-${arch}" images_file="images.txt" -main "${dind_container_name}" "${images_file}" "${arch}" \ No newline at end of file +main "${dind_container_name}" "${images_file}" "${arch}"