Skip to content

Commit

Permalink
Add platform option to pull-images.sh:
Browse files Browse the repository at this point in the history
This makes it so that the correct architecture for
the embedded images are pulled.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Aug 21, 2024
1 parent 24b74a0 commit 62f650a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions images/hook-embedded/pull-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: <image> <optional tag>
#
# 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}"
main "${dind_container_name}" "${images_file}" "${arch}"

0 comments on commit 62f650a

Please sign in to comment.