Skip to content

Commit 2f2aba6

Browse files
committed
optimizing dockerfile, preparing better dev env
1 parent 7127aa2 commit 2f2aba6

File tree

6 files changed

+247
-186
lines changed

6 files changed

+247
-186
lines changed

Dockerfile

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:24.04 AS builder
1+
FROM ubuntu:24.04 AS builder_env
22

33
# Env variables
44
ENV DEBIAN_FRONTEND=noninteractive \
@@ -8,20 +8,28 @@ ENV DEBIAN_FRONTEND=noninteractive \
88
# Prepare directories
99
WORKDIR /code
1010

11-
# Copy everything
12-
COPY . ./
11+
# Copy necessary files
12+
COPY scripts/linux/base.sh scripts/linux/base.sh
13+
COPY scripts/linux/prepare_develop.sh scripts/linux/prepare_develop.sh
14+
COPY requirements.txt requirements.txt
15+
COPY snap/ snap/
1316

14-
# Run the build
15-
RUN bash configure.sh install
17+
# Install develop dependencies
18+
RUN bash scripts/linux/prepare_develop.sh
1619

17-
# Run the tests
18-
ENV PATH="/code/venv/bin:$PATH"
19-
RUN bash test.sh
20+
# END builder_env
21+
22+
FROM builder_env AS builder
23+
24+
COPY docker docker
25+
COPY SuperBuild SuperBuild
26+
COPY scripts/linux/build.sh scripts/linux/build.sh
2027

21-
# Clean Superbuild
22-
RUN bash configure.sh clean
28+
# Install and compile then clean
29+
RUN bash scripts/linux/build.sh
2330

24-
### END Builder
31+
32+
# ### END Builder
2533

2634
### Use a second image for the final asset to reduce the number and
2735
# size of the layers.
@@ -35,18 +43,25 @@ ENV DEBIAN_FRONTEND=noninteractive \
3543

3644
WORKDIR /code
3745

46+
COPY scripts/linux/base.sh scripts/linux/base.sh
47+
COPY scripts/linux/prepare_runtime.sh scripts/linux/prepare_runtime.sh
48+
COPY snap/ snap/
49+
50+
# Install shared libraries that we depend on via APT, but *not*
51+
# the -dev packages to save space!
52+
RUN bash scripts/linux/prepare_runtime.sh \
53+
&& apt-get clean \
54+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
55+
3856
# Copy everything we built from the builder
3957
COPY --from=builder /code /code
4058

59+
COPY . ./
60+
4161
ENV PATH="/code/venv/bin:$PATH"
4262

43-
# Install shared libraries that we depend on via APT, but *not*
44-
# the -dev packages to save space!
45-
# Also run a smoke test on ODM and OpenSfM
46-
RUN bash configure.sh installruntimedepsonly \
47-
&& apt-get clean \
48-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
49-
&& bash run.sh --help \
63+
# Run a smoke test on ODM and OpenSfM
64+
RUN bash run.sh --help \
5065
&& bash -c "eval $(python3 /code/opendm/context.py) && python3 -c 'from opensfm import io, pymap'"
5166

5267
# Entry point

configure.sh

Lines changed: 10 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,13 @@
11
#!/bin/bash
2-
3-
# Ensure the DEBIAN_FRONTEND environment variable is set for apt-get calls
4-
APT_GET="env DEBIAN_FRONTEND=noninteractive $(command -v apt-get)"
5-
6-
check_version(){
7-
UBUNTU_VERSION=$(lsb_release -r)
8-
case "$UBUNTU_VERSION" in
9-
*"20.04"*|*"21.04"*|*"24.04"*)
10-
echo "Ubuntu: $UBUNTU_VERSION, good!"
11-
;;
12-
*"18.04"*|*"16.04"*)
13-
echo "ODM 2.1 has upgraded to Ubuntu 21.04, but you're on $UBUNTU_VERSION"
14-
echo "* The last version of ODM that supports Ubuntu 16.04 is v1.0.2."
15-
echo "* The last version of ODM that supports Ubuntu 18.04 is v2.0.0."
16-
echo "We recommend you to upgrade, or better yet, use docker."
17-
exit 1
18-
;;
19-
*)
20-
echo "You are not on Ubuntu 21.04 (detected: $UBUNTU_VERSION)"
21-
echo "It might be possible to run ODM on a newer version of Ubuntu, however, you cannot rely on this script."
22-
exit 1
23-
;;
24-
esac
25-
}
26-
27-
if [[ $2 =~ ^[0-9]+$ ]] ; then
28-
processes=$2
29-
else
30-
processes=$(nproc)
31-
fi
32-
33-
ensure_prereqs() {
34-
export DEBIAN_FRONTEND=noninteractive
35-
36-
if ! command -v sudo &> /dev/null; then
37-
echo "Installing sudo"
38-
$APT_GET update
39-
$APT_GET install -y -qq --no-install-recommends sudo
40-
else
41-
sudo $APT_GET update
42-
fi
43-
44-
if ! command -v lsb_release &> /dev/null; then
45-
echo "Installing lsb_release"
46-
sudo $APT_GET install -y -qq --no-install-recommends lsb-release
47-
fi
48-
49-
if ! command -v pkg-config &> /dev/null; then
50-
echo "Installing pkg-config"
51-
sudo $APT_GET install -y -qq --no-install-recommends pkg-config
52-
fi
53-
54-
echo "Installing tzdata"
55-
sudo $APT_GET install -y -qq tzdata
56-
57-
UBUNTU_VERSION=$(lsb_release -r)
58-
if [[ "$UBUNTU_VERSION" == *"20.04"* ]]; then
59-
echo "Enabling PPA for Ubuntu GIS"
60-
sudo $APT_GET install -y -qq --no-install-recommends software-properties-common
61-
sudo add-apt-repository ppa:ubuntugis/ppa
62-
sudo $APT_GET update
63-
elif [[ "$UBUNTU_VERSION" == *"24.04"* ]]; then
64-
echo "Enabling ubuntugis-unstable PPA for Ubuntu 24.04"
65-
sudo $APT_GET install -y -qq --no-install-recommends software-properties-common
66-
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
67-
sudo $APT_GET update
68-
fi
69-
70-
echo "Installing Python PIP"
71-
sudo $APT_GET install -y -qq --no-install-recommends \
72-
python3-pip \
73-
python3-setuptools \
74-
python3-venv
75-
python3 -m venv venv --system-site-packages
76-
venv/bin/pip3 install -U pip
77-
venv/bin/pip3 install -U shyaml
78-
}
79-
80-
# Save all dependencies in snapcraft.yaml to maintain a single source of truth.
81-
# Maintaining multiple lists will otherwise be painful.
82-
installdepsfromsnapcraft() {
83-
section="$2"
84-
case "$1" in
85-
build) key=build-packages; ;;
86-
runtime) key=stage-packages; ;;
87-
*) key=build-packages; ;; # shouldn't be needed, but it's here just in case
88-
esac
89-
90-
UBUNTU_VERSION=$(lsb_release -r)
91-
SNAPCRAFT_FILE="snapcraft.yaml"
92-
if [[ "$UBUNTU_VERSION" == *"21.04"* ]]; then
93-
SNAPCRAFT_FILE="snapcraft21.yaml"
94-
elif [[ "$UBUNTU_VERSION" == *"24.04"* ]]; then
95-
SNAPCRAFT_FILE="snapcraft24.yaml"
96-
fi
97-
98-
cat snap/$SNAPCRAFT_FILE | \
99-
venv/bin/shyaml get-values-0 parts.$section.$key | \
100-
xargs -0 sudo $APT_GET install -y -qq --no-install-recommends
101-
}
102-
103-
installruntimedepsonly() {
104-
echo "Installing runtime dependencies"
105-
ensure_prereqs
106-
check_version
107-
108-
echo "Installing Required Requisites"
109-
installdepsfromsnapcraft runtime prereqs
110-
echo "Installing OpenCV Dependencies"
111-
installdepsfromsnapcraft runtime opencv
112-
echo "Installing OpenSfM Dependencies"
113-
installdepsfromsnapcraft runtime opensfm
114-
echo "Installing OpenMVS Dependencies"
115-
installdepsfromsnapcraft runtime openmvs
116-
}
117-
118-
installreqs() {
119-
cd /code
120-
121-
## Set up library paths
122-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$RUNPATH/SuperBuild/install/lib
123-
124-
## Before installing
125-
echo "Updating the system"
126-
ensure_prereqs
127-
check_version
128-
129-
echo "Installing Required Requisites"
130-
installdepsfromsnapcraft build prereqs
131-
echo "Installing OpenCV Dependencies"
132-
installdepsfromsnapcraft build opencv
133-
echo "Installing OpenSfM Dependencies"
134-
installdepsfromsnapcraft build opensfm
135-
echo "Installing OpenMVS Dependencies"
136-
installdepsfromsnapcraft build openmvs
137-
138-
set -e
139-
140-
# edt requires numpy to build
141-
venv/bin/pip install numpy==2.3.2
142-
venv/bin/pip install -r requirements.txt --ignore-installed
143-
#if [ ! -z "$GPU_INSTALL" ]; then
144-
#fi
145-
set +e
146-
}
2+
ROOT_SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
3+
source "${ROOT_SCRIPT_DIR}/scripts/linux/build.sh"
4+
source "${ROOT_SCRIPT_DIR}/scripts/linux/prepare_develop.sh"
5+
source "${ROOT_SCRIPT_DIR}/scripts/linux/prepare_runtime.sh"
1476

1487
install() {
1498
installreqs
150-
151-
if [ ! -z "$PORTABLE_INSTALL" ]; then
152-
echo "Replacing g++ and gcc with our scripts for portability..."
153-
if [ ! -e /usr/bin/gcc_real ]; then
154-
sudo mv -v /usr/bin/gcc /usr/bin/gcc_real
155-
sudo cp -v ./docker/gcc /usr/bin/gcc
156-
fi
157-
if [ ! -e /usr/bin/g++_real ]; then
158-
sudo mv -v /usr/bin/g++ /usr/bin/g++_real
159-
sudo cp -v ./docker/g++ /usr/bin/g++
160-
fi
161-
fi
162-
163-
set -eo pipefail
164-
165-
echo "Compiling SuperBuild"
166-
cd ${RUNPATH}/SuperBuild
167-
mkdir -p build && cd build
168-
cmake .. && make -j$processes
169-
170-
echo "Configuration Finished"
9+
build
10+
echo "Configuration Finished"
17111
}
17212

17313
uninstall() {
@@ -200,7 +40,7 @@ clean() {
20040

20141
usage() {
20242
echo "Usage:"
203-
echo "bash configure.sh <install|update|uninstall|installreqs|help> [nproc]"
43+
echo "bash configure.sh <install|installruntimedepsonly|reinstall|uninstall|installreqs|clean|build> [nproc]"
20444
echo "Subcommands:"
20545
echo " install"
20646
echo " Installs all dependencies and modules for running OpenDroneMap"
@@ -214,12 +54,14 @@ usage() {
21454
echo " Only installs the requirements (does not build SuperBuild)"
21555
echo " clean"
21656
echo " Cleans the SuperBuild directory by removing temporary files. "
57+
echo " build"
58+
echo " Builds the SuperBuild modules (assumes requirements are already installed)"
21759
echo " help"
21860
echo " Displays this message"
21961
echo "[nproc] is an optional argument that can set the number of processes for the make -j tag. By default it uses $(nproc)"
22062
}
22163

222-
if [[ $1 =~ ^(install|installruntimedepsonly|reinstall|uninstall|installreqs|clean)$ ]]; then
64+
if [[ $1 =~ ^(install|installruntimedepsonly|reinstall|uninstall|installreqs|clean|build)$ ]]; then
22365
RUNPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22466
"$1"
22567
else

scripts/linux/base.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
3+
RUNPATH=$(dirname $(dirname "$SCRIPT_DIR"))
4+
# Ensure the DEBIAN_FRONTEND environment variable is set for apt-get calls
5+
APT_GET="env DEBIAN_FRONTEND=noninteractive $(command -v apt-get)"
6+
7+
check_version(){
8+
UBUNTU_VERSION=$(lsb_release -r)
9+
case "$UBUNTU_VERSION" in
10+
*"20.04"*|*"21.04"*|*"24.04"*)
11+
echo "Ubuntu: $UBUNTU_VERSION, good!"
12+
;;
13+
*"18.04"*|*"16.04"*)
14+
echo "ODM 2.1 has upgraded to Ubuntu 21.04, but you're on $UBUNTU_VERSION"
15+
echo "* The last version of ODM that supports Ubuntu 16.04 is v1.0.2."
16+
echo "* The last version of ODM that supports Ubuntu 18.04 is v2.0.0."
17+
echo "We recommend you to upgrade, or better yet, use docker."
18+
exit 1
19+
;;
20+
*)
21+
echo "You are not on Ubuntu 21.04 (detected: $UBUNTU_VERSION)"
22+
echo "It might be possible to run ODM on a newer version of Ubuntu, however, you cannot rely on this script."
23+
exit 1
24+
;;
25+
esac
26+
}
27+
28+
if [[ $2 =~ ^[0-9]+$ ]] ; then
29+
processes=$2
30+
else
31+
processes=$(nproc)
32+
fi
33+
34+
ensure_prereqs() {
35+
export DEBIAN_FRONTEND=noninteractive
36+
37+
if ! command -v sudo &> /dev/null; then
38+
echo "Installing sudo"
39+
$APT_GET update
40+
$APT_GET install -y -qq --no-install-recommends sudo
41+
else
42+
sudo $APT_GET update
43+
fi
44+
45+
if ! command -v lsb_release &> /dev/null; then
46+
echo "Installing lsb_release"
47+
sudo $APT_GET install -y -qq --no-install-recommends lsb-release
48+
fi
49+
50+
if ! command -v pkg-config &> /dev/null; then
51+
echo "Installing pkg-config"
52+
sudo $APT_GET install -y -qq --no-install-recommends pkg-config
53+
fi
54+
55+
echo "Installing tzdata"
56+
sudo $APT_GET install -y -qq tzdata
57+
58+
UBUNTU_VERSION=$(lsb_release -r)
59+
if [[ "$UBUNTU_VERSION" == *"20.04"* ]]; then
60+
echo "Enabling PPA for Ubuntu GIS"
61+
sudo $APT_GET install -y -qq --no-install-recommends software-properties-common
62+
sudo add-apt-repository ppa:ubuntugis/ppa
63+
sudo $APT_GET update
64+
elif [[ "$UBUNTU_VERSION" == *"24.04"* ]]; then
65+
echo "Enabling ubuntugis-unstable PPA for Ubuntu 24.04"
66+
sudo $APT_GET install -y -qq --no-install-recommends software-properties-common
67+
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
68+
sudo $APT_GET update
69+
fi
70+
71+
echo "Installing Python PIP"
72+
sudo $APT_GET install -y -qq --no-install-recommends \
73+
python3-pip \
74+
python3-setuptools \
75+
python3-venv
76+
python3 -m venv venv --system-site-packages
77+
venv/bin/pip3 install -U pip
78+
venv/bin/pip3 install -U shyaml
79+
}
80+
81+
# Save all dependencies in snapcraft.yaml to maintain a single source of truth.
82+
# Maintaining multiple lists will otherwise be painful.
83+
installdepsfromsnapcraft() {
84+
section="$2"
85+
case "$1" in
86+
build) key=build-packages; ;;
87+
runtime) key=stage-packages; ;;
88+
*) key=build-packages; ;; # shouldn't be needed, but it's here just in case
89+
esac
90+
91+
UBUNTU_VERSION=$(lsb_release -r)
92+
SNAPCRAFT_FILE="snapcraft.yaml"
93+
if [[ "$UBUNTU_VERSION" == *"21.04"* ]]; then
94+
SNAPCRAFT_FILE="snapcraft21.yaml"
95+
elif [[ "$UBUNTU_VERSION" == *"24.04"* ]]; then
96+
SNAPCRAFT_FILE="snapcraft24.yaml"
97+
fi
98+
99+
cat snap/$SNAPCRAFT_FILE | \
100+
venv/bin/shyaml get-values-0 parts.$section.$key | \
101+
xargs -0 sudo $APT_GET install -y -qq --no-install-recommends
102+
}

0 commit comments

Comments
 (0)