Skip to content

Commit

Permalink
clean up and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecamel committed Oct 5, 2021
1 parent b00d568 commit 5205d3c
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 129 deletions.
12 changes: 1 addition & 11 deletions docker-compose.nodeodm.gpu.intel.yml
Expand Up @@ -8,7 +8,7 @@ services:
depends_on:
- node-odm
environment:
- PYOPENCL_COMPILER_OUTPUT=1
- WO_DEFAULT_NODES
node-odm:
image: opendronemap/nodeodm:gpu.intel
devices:
Expand All @@ -17,13 +17,3 @@ services:
- "3000"
restart: unless-stopped
oom_score_adj: 500
environment:
- PYOPENCL_COMPILER_OUTPUT=1
deploy:
resources:
limits:
cpus: 3
memory: 6144M
reservations:
cpus: 2
memory: 4096M
53 changes: 53 additions & 0 deletions dpkg/README.md
@@ -0,0 +1,53 @@
# WebODM Debian Package
This directory contains scripts to build a Debian package which, in turn, will install WebODM and its dependencies.

## OS Support
It has been tested on Ubuntu 18.04 and 20.04, but should work on other Debian-based systems.

## GPU Support
NIVIDA and Intel hardware are detected and installation/configuration is customized accordingly. AMD is not currently supported, but could be added with help from someone with hardware and/or experience.

## Building the Debian Package
### To build the package, run:
```
./build.sh
```

This script will collect the necessary components and put them in a directory unique to the package version (e.g. `/path/to/WebODM/dpkg/build/webodm_1.9.7-1`). If that directory already exists, then it will be deleted first.

This directory will then be used to build the Debian package, and bundles it together with an install script (e.g. `/path/to/WebODM/dpkg/deb/webodm_1.9.7-1`).

## Installing the Debian Package
### To install the package, run:
```
./install.sh
```

This script will first attempt to detect GPU hardware and install the appropriate drivers. It will then use `dpkg` to install the package. You will be prompted before anything is installed.

If all goes well, then this will leave you with a `systemd` service, named `webodm-docker.service`.

### View the status of the service:
```
sudo systemctl status webodm-docker
```

### Stop the service:
```
sudo systemctl stop webodm-docker
```

### Start the service:
```
sudo systemctl start webodm-docker
```

### Restart the service:
```
sudo systemctl restart webodm-docker
```

### View service logs:
```
journalctl -u webodm-docker.service
```
54 changes: 29 additions & 25 deletions dpkg/build.sh
Expand Up @@ -5,21 +5,42 @@ set -euxo
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

WEBODM_VERSION=1.9.7
WEBODM_DPKG_VERSION=3
WEBODM_DPKG_VERSION=1
WEBODM_DPKG_NAME="webodm_${WEBODM_VERSION}-${WEBODM_DPKG_VERSION}"

BUILD_DIR="${HERE}/build"
DEB_DIR="${HERE}/deb"
WEBODM_DIR="${HERE}/${WEBODM_DPKG_NAME}/opt/WebODM"
NODEODM_DIR="${HERE}/${WEBODM_DPKG_NAME}/opt/nodeodm"

function build() {
prepareBuildDir
prepareDebDir
prepareNodeODMDir
prepareWebODMDir
moveToBuildDir
buildDeb
bundle
}

function buildDeb() {
dpkg-deb --build "${WEBODM_DPKG_NAME}"
}

function bundle() {
mkdir -p "${DEB_DIR}/${WEBODM_DPKG_NAME}"
cp "${HERE}/install.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/WebODM/detect_gpus.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${WEBODM_DPKG_NAME}.deb" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
}

function moveToBuildDir() {
cd "${BUILD_DIR}/${WEBODM_DPKG_NAME}"
}

function prepareBuildDir() {
if [ -d "${BUILD_DIR}" ]; then
rm -Rf "${BUILD_DIR}"
if [ -d "${BUILD_DIR}/${WEBODM_DPKG_NAME}" ]; then
rm -Rf "${BUILD_DIR}/${WEBODM_DPKG_NAME}"
fi

mkdir -p "${BUILD_DIR}/${WEBODM_DPKG_NAME}"
Expand All @@ -34,6 +55,11 @@ function prepareDebDir() {
mkdir -p "${DEB_DIR}"
}

function prepareNodeODMDir() {
# This can go away when we can pull the image from Docker Hub.
git clone -b bkd/gpu https://github.com/airmap/nodeodm.git "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/nodeodm"
}

function prepareWebODMDir() {
TMP_DIR="/tmp/WebODM"
if [ -d "${BUILD_DIR}" ]; then
Expand All @@ -44,26 +70,4 @@ function prepareWebODMDir() {
mv "${TMP_DIR}" "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/"
}

function prepareNodeODMDir() {
# This can go away when we can pull the image from Docker Hub.
git clone -b bkd/gpu https://github.com/airmap/nodeodm.git "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/nodeodm"
}

function build() {
dpkg-deb --build "${WEBODM_DPKG_NAME}"
}

function bundle() {
mkdir -p "${DEB_DIR}/${WEBODM_DPKG_NAME}"
cp "${HERE}/install.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${BUILD_DIR}/${WEBODM_DPKG_NAME}/${WEBODM_DPKG_NAME}/opt/WebODM/detect_gpus.sh" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
cp "${WEBODM_DPKG_NAME}.deb" "${DEB_DIR}/${WEBODM_DPKG_NAME}/"
}

prepareBuildDir
prepareDebDir
prepareNodeODMDir
prepareWebODMDir
moveToBuildDir
build
bundle
17 changes: 5 additions & 12 deletions dpkg/install.sh
Expand Up @@ -5,7 +5,7 @@ set -ux
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

WEBODM_VERSION=1.9.7
WEBODM_DPKG_VERSION=3
WEBODM_DPKG_VERSION=1
WEBODM_DPKG_NAME="webodm_${WEBODM_VERSION}-${WEBODM_DPKG_VERSION}"

function aptFixInstall() {
Expand All @@ -20,12 +20,6 @@ function ensureDocker() {
fi
}

function ensureDockerCompose() {
if ! command -v docker-compose &> /dev/null; then
sudo apt install docker-compose
fi
}

function ensureIntelOpenCL() {
if [ "${GPU_INTEL}" = false ]; then
return
Expand Down Expand Up @@ -114,19 +108,18 @@ function ensureNVIDIAOpenCL() {
function ensureOpenCL() {
source "${HERE}/detect_gpus.sh"

if [ "${GPU_NVIDIA}" = true ]; then
ensureNVIDIAOpenCL
fi

if [ "${GPU_INTEL}" = true ]; then
ensureIntelOpenCL
fi

# if [ "${GPU_NVIDIA}" = true ]; then
# ensureNVIDIAOpenCL
# fi
}

function install() {
ensureOpenCL
ensureDocker
ensureDockerCompose
sudo dpkg -i "${HERE}/${WEBODM_DPKG_NAME}.deb"
}

Expand Down
3 changes: 1 addition & 2 deletions dpkg/webodm/DEBIAN/control
@@ -1,10 +1,9 @@
Package: WebODM
Version: 1.9.7-3
Version: 1.9.7-1
Section: base
Priority: optional
Architecture: all
Depends: docker.io | docker-ce,
docker-compose,
ocl-icd-libopencl1,
clinfo,
python3,
Expand Down
54 changes: 24 additions & 30 deletions dpkg/webodm/DEBIAN/postinst
Expand Up @@ -9,17 +9,17 @@ export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
export NODEODM_DIR=/opt/nodeodm

function abortRemove() {
echo "Unable to remove webodm."
}

function addNodeODMGPUIntelDockerGroups() {
DOCKER_COMPOSE_FILE="${WEBODM_DIR}/docker-compose.nodeodm.gpu.intel.yml"
for gid in $(id -G "${WEBODM_USER}"); do
echo "Checking gid ${gid}."
SED_SEARCH="/^\s\{4\}group_add/{:start /${gid}$/!"
SED_SEARCH="${SED_SEARCH}{N;b start};/${gid}$/p}"
# SED_OUT=$(sed -n '/^\s\{4\}group_add/{:start /$gid$/!{N;b start};/10/p}' "${DOCKER_COMPOSE_FILE}")
SED_OUT=$(sed -n "${SED_SEARCH}" "${DOCKER_COMPOSE_FILE}")
if [ -z "${SED_OUT}" ]; then
echo "Adding gid ${gid}."
echo "SED_OUT: ${SED_OUT}"
sed -i "/^\s\{4\}image/a \ \ \ \ group_add:\n\ \ \ \ \ \ - ${gid}" "${DOCKER_COMPOSE_FILE}"
fi
done
Expand All @@ -37,6 +37,24 @@ function buildNodeODMGPUIntelDockerImage() {
docker build -f Dockerfile.gpu.intel -t opendronemap/nodeodm:gpu.intel --build-arg RENDER_GROUP_ID="${RENDER_GROUP_ID}" .
}

function configure() {
detectGPUs
createGroup
createUser

if [ "${GPU_INTEL}" = true ]; then
buildNodeODMGPUIntelDockerImage
addNodeODMGPUIntelDockerGroups
fi

createVenv
setFilePermissions
upgradePythonPip
installPythonDockerCompose
enableService
startService
}

function createGroup() {
if [ "${GPU_INTEL}" = true ]; then
if ! grep -q "^render:" /etc/group; then
Expand Down Expand Up @@ -90,37 +108,13 @@ function setFilePermissions() {
chown -R "${WEBODM_USER}:${WEBODM_USER}" "${WEBODM_DIR}"
}

function upgradePythonPip() {
su "${WEBODM_USER}" -c "python3 -m pip install --upgrade pip"
}

####

function startService() {
systemctl daemon-reload
systemctl restart webodm-docker.service
}

function abortRemove() {
echo "Unable to remove webodm."
}

function configure() {
detectGPUs
createGroup
createUser

if [ "${GPU_INTEL}" = true ]; then
buildNodeODMGPUIntelDockerImage
addNodeODMGPUIntelDockerGroups
fi

createVenv
setFilePermissions
upgradePythonPip
installPythonDockerCompose
enableService
startService
function upgradePythonPip() {
su "${WEBODM_USER}" -c "python3 -m pip install --upgrade pip"
}

case $1 in
Expand Down
30 changes: 4 additions & 26 deletions dpkg/webodm/DEBIAN/postrm
Expand Up @@ -9,6 +9,10 @@ export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
export NODEODM_DIR=/opt/nodeodm

function abortInstall() {
purge
}

function deleteUser() {
if grep -q "^${WEBODM_USER}:" /etc/passwd; then
userdel "${WEBODM_USER}"
Expand All @@ -21,38 +25,12 @@ function deleteUserHome() {
fi
}

function deleteVenv() {
if [ -d "${WEBODM_VENV_DIR}" ]; then
rm -Rf "${WEBODM_VENV_DIR}"
fi
}

function stopService() {
UNIT_NAME="webodm-docker.service"
set +e
systemctl is-active -q "${UNIT_NAME}"
if [ "${?}" -eq 0 ]; then
set -e
systemctl stop "${UNIT_NAME}"
else
set -e
fi
systemctl disable "${UNIT_NAME}"
systemctl daemon-reload

/opt/WebODM/webodm.sh down
}

function purge() {
stopService
deleteUser
deleteVenv
deleteUserHome
}

function abortInstall() {
purge
}

case $1 in
abort-install)
Expand Down
23 changes: 0 additions & 23 deletions dpkg/webodm/DEBIAN/preinst

This file was deleted.

0 comments on commit 5205d3c

Please sign in to comment.