-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild-docker.sh
More file actions
executable file
·72 lines (59 loc) · 2.29 KB
/
build-docker.sh
File metadata and controls
executable file
·72 lines (59 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash -e
# SPDX-License-Identifier: BSD-3-Clause
#
# kuiper2.0 - Embedded Linux for Analog Devices Products
#
# Copyright (c) 2024 Analog Devices, Inc.
# Author: Larisa Radu <larisa.radu@analog.com>
source config
DEBIAN_VERSION=${DEBIAN_VERSION:-bookworm}
BASE_IMAGE="debian:${DEBIAN_VERSION}"
IMAGE_NAME="debian_${DEBIAN_VERSION}_rootfs"
CONTAINER_NAME=${CONTAINER_NAME:-"${IMAGE_NAME}_container"}
PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-n}
cleanup() {
docker rm -fv ${CONTAINER_NAME}
exit 1
}
# Remove container if build was interrupted or cancelled
trap cleanup SIGINT SIGTERM
# Check if the script is run as root
if [ "$(id -u)" != "0" ] ; then
echo "This script must be run as root"
exit 1
fi
# Check if Debian version is supported
if [[ ! ${DEBIAN_VERSION} = bookworm && ! ${DEBIAN_VERSION} = bullseye ]]; then
echo "Unsupported Debian version ${DEBIAN_VERSION}"
exit 1
fi
# Build docker image
docker build --build-arg BASE_IMAGE="${BASE_IMAGE}" -t ${IMAGE_NAME} .
# Run docker container
# -t: pseudo-TTY allowing interaction with container's shell
# --privileged: elevanted privileges required by the chroot command
# -v: mounts volumes allowing the container to access files on the host or work with kernel modules
# -e: sets environment variables
# Inside the container kuiper-stages.sh will run building the Kuiper image
docker run -t --privileged \
-v /dev:/dev \
-v /lib/modules:/lib/modules \
-v ./kuiper-volume:/kuiper-volume \
-e "DEBIAN_VERSION="${DEBIAN_VERSION}"" \
--name ${CONTAINER_NAME} ${IMAGE_NAME} \
/bin/bash -o pipefail -c "bash kuiper-stages.sh"
if [ $PRESERVE_CONTAINER = n ]; then
# Remove image, container and corresponding volume
docker rm -v ${CONTAINER_NAME}
fi
docker image rm -f ${IMAGE_NAME}
# Detach loops
LOOP_DEVICES=$(losetup --list | grep "$(basename "ADI-Kuiper-Linux.*.img")" | cut -f1 -d' ')
for LOOP_DEV in ${LOOP_DEVICES}; do
losetup -d ${LOOP_DEV}
done
# Save info about adi-kuiper-gen repository in log file
echo -e "\nADI Kuiper Linux:" >> "kuiper-volume/ADI_repos_git_info.txt"
echo "Repo : $(git remote get-url origin)" >> "kuiper-volume/ADI_repos_git_info.txt"
echo "Branch : $(git branch | cut -d' ' -f2)" >> "kuiper-volume/ADI_repos_git_info.txt"
echo -e "Git_sha: $(git rev-parse --short HEAD)\n\n" >> "kuiper-volume/ADI_repos_git_info.txt"