Skip to content

Commit f68dc4b

Browse files
Add platform option to pull-images.sh:
This makes it so that the correct architecture for the embedded images are pulled. Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 9318be6 commit f68dc4b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ For use cases where having container images already available in Docker is neede
168168
169169
1. Create a file named `images.txt` in the [images/hook-embedded/](images/hook-embedded/) directory.
170170
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.
171-
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.
171+
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.
172172
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.
173173

174174
### Build system TO-DO list

images/hook-embedded/pull-images.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ set -euo pipefail
1717
function main() {
1818
local dind_container="$1"
1919
local images_file="$2"
20+
local arch="$3"
2021
# as this function maybe called multiple times, we need to ensure the container is removed
21-
trap "docker rm -f ${dind_container} &> /dev/null" RETURN
22+
trap "docker rm -f "${dind_container}" &> /dev/null" RETURN
2223
# we're using set -e so the trap on RETURN will not be executed when a command fails
23-
trap "docker rm -f ${dind_container} &> /dev/null" EXIT
24+
trap "docker rm -f "${dind_container}" &> /dev/null" EXIT
2425
# start DinD container
2526
# In order to avoid the src bind mount directory (./images/) ownership from changing to root
2627
# 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() {
3435
sleep 1
3536
done
3637

38+
# remove the contents of /var/lib/docker-embedded so that any previous images are removed. Without this it seems to cause boot issues.
39+
docker exec "${dind_container}" sh -c "rm -rf /var/lib/docker-embedded/*"
40+
3741
# pull images from list
3842
# this expects a file named images.txt in the same directory as this script
3943
# the format of this file is line separated: <image> <optional tag>
4044
#
4145
# the || [ -n "$first_image" ] is to handle the last line of the file that doesn't have a newline.
42-
while IFS=" " read -r first_image image_tag || [ -n "$first_image" ] ; do
46+
while IFS=" " read -r first_image image_tag || [ -n "${first_image}" ] ; do
4347
echo -e "----------------------- $first_image -----------------------"
44-
docker exec "${dind_container}" docker pull $first_image
45-
if [[ $image_tag != "" ]]; then
46-
docker exec "${dind_container}" docker tag $first_image $image_tag
48+
docker exec "${dind_container}" docker pull --platform=linux/"${arch}" "${first_image}"
49+
if [[ "${image_tag}" != "" ]]; then
50+
docker exec "${dind_container}" docker tag "${first_image}" "${image_tag}"
4751
fi
4852
done < "${images_file}"
4953

50-
# remove the contents of /var/lib/docker-embedded so that any previous images are removed. Without this it seems to cause boot issues.
51-
docker exec "${dind_container}" sh -c "rm -rf /var/lib/docker-embedded/*"
5254
# We need to copy /var/lib/docker to /var/lib/docker-embedded in order for HookOS to use the Docker images in its build.
5355
docker exec "${dind_container}" sh -c "cp -a /var/lib/docker/* /var/lib/docker-embedded/"
5456
}
5557

56-
arch="amd64"
58+
arch="${1-amd64}"
5759
dind_container_name="hookos-dind-${arch}"
5860
images_file="images.txt"
59-
main "${dind_container_name}" "${images_file}" "${arch}"
61+
main "${dind_container_name}" "${images_file}" "${arch}"

0 commit comments

Comments
 (0)