Skip to content

Commit 930d513

Browse files
committed
Fixes Building in Docker
build.sh: fixed errors and added parameters valid_targets, release_targets to get a shortened list of available targets. cmake/docker.sh: avoid initializing cmake on every run of ./build.sh. Dockerfile: fixed syntax and removed unnecessary checks and instructions.
1 parent 9f0fb42 commit 930d513

3 files changed

Lines changed: 42 additions & 17 deletions

File tree

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ FROM ubuntu:jammy
22

33
ARG USER_ID
44
ARG GROUP_ID
5-
ENV DEBIAN_FRONTEND noninteractive
5+
ARG GDB
6+
7+
ENV DEBIAN_FRONTEND=noninteractive
68

79
RUN apt-get update && apt-get install -y git cmake make ruby gcc python3 python3-pip gcc-arm-none-eabi ninja-build
810

911
RUN if [ "$GDB" = "yes" ]; then apt-get install -y gdb; fi
1012

1113
RUN pip install pyyaml
1214

13-
# if either of these are already set the same as the user's machine, leave them be and ignore the error
14-
RUN addgroup --gid $GROUP_ID inav; exit 0;
15-
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID inav; exit 0;
15+
# add inav user and group
16+
RUN addgroup --gid $GROUP_ID inav
17+
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID inav
1618

1719
USER inav
1820

1921
RUN git config --global --add safe.directory /src
2022

21-
VOLUME /src
22-
2323
WORKDIR /src/build
24+
2425
ENTRYPOINT ["/src/cmake/docker.sh"]

build.sh

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

44
if [[ $# == 0 ]]; then
55
echo -e "\
@@ -8,6 +8,10 @@ Usage syntax: ./build.sh <TARGET>
88
Notes:
99
* You can specify multiple targets.
1010
./build.sh <TARGET_1> <TARGET_2> <TARGET_N>
11+
* To get a list of release targets use \"release_targets\"
12+
./build.sh release_targets
13+
* To get a list of valid targets use \"valid_targets\"
14+
./build.sh valid_targets
1115
* To get a list of all targets use \"help\". Hint: pipe the output through a pager.
1216
./build.sh help | less
1317
* To build all targets use \"all\"
@@ -19,10 +23,20 @@ Notes:
1923
exit 1
2024
fi
2125

26+
run_docker() {
27+
docker run --rm -it -v "$(pwd)":/src inav-build "$@"
28+
}
29+
2230
if [ -z "$(docker images -q inav-build)" ]; then
23-
echo -e "*** Building image\n"
24-
docker build -t inav-build --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" .
25-
echo -ne "\n"
31+
echo "*** Building Docker image"
32+
docker build -t inav-build \
33+
--build-arg USER_ID="$(id -u)" \
34+
--build-arg GROUP_ID="$(id -g)" .
35+
else
36+
docker build -q -t inav-build \
37+
--build-arg USER_ID="$(id -u)" \
38+
--build-arg GROUP_ID="$(id -g)" . >/dev/null ||
39+
{ echo "*** Building Docker image: ERROR"; exit 1; }
2640
fi
2741

2842
if [ ! -d ./build ]; then
@@ -40,10 +54,20 @@ if [ ! -d ./tools ]; then
4054
mkdir ./tools && chmod 777 ./tools
4155
fi
4256

43-
echo -e "*** Building targets [$@]\n"
44-
docker run --rm -it -v "$(pwd)":/src inav-build $@
57+
case "$1" in
58+
release_targets)
59+
run_docker targets | sed -n 's/^Release targets: \(.*\)/\1/p'|tr ' ' '\n'
60+
;;
61+
valid_targets)
62+
run_docker targets | sed -n 's/^Valid targets: \(.*\)/\1/p'|tr ' ' '\n'
63+
;;
64+
*)
65+
echo -e "*** Building targets [$@]\n"
66+
run_docker "$@"
67+
if ls ./build/*.hex &> /dev/null; then
68+
echo -e "\n*** Built targets in ./build:"
69+
stat -c "%n (%.19y)" ./build/*.hex
70+
fi
71+
;;
72+
esac
4573

46-
if [ -z "$(ls ./build/*.hex &> /dev/null)" ]; then
47-
echo -e "\n*** Built targets in ./build:"
48-
stat -c "%n (%.19y)" ./build/*.hex
49-
fi

cmake/docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ initialize_cmake() {
1111
}
1212

1313
# Check if CMake has never been initialized
14-
if [ ! -f Makefile ]; then
14+
if [ ! -f build.ninja ]; then
1515
initialize_cmake
1616
fi
1717

0 commit comments

Comments
 (0)