Skip to content
Snippets Groups Projects
Commit cd099099 authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
build/
log/
\ No newline at end of file
FROM ubuntu:18.04
ARG src_path=/src
# Timezone configuration, bypass interactive prompt
ENV TZ=Europe/Zurich
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && \
apt-get install -y \
lsb-core software-properties-common
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE \
&& add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u
# CPP packages for lib sandbox
RUN apt-get update && \
apt-get install -y \
g++ build-essential \
libopencv-dev \
libyaml-cpp-dev \
cmake
# Libyaml cpp dev causing problem ?
RUN apt-get install -y librealsense2=2.35.2-0~realsense0.3083 librealsense2-dev=2.35.2-0~realsense0.3083
# Python for wrapper
RUN apt-get install -y python3 python3-pip
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install cython numpy opencv-python pybind11 build
# Venv for python-build
RUN apt-get install -y python3-venv
# Create paths
RUN mkdir -p /build && mkdir -p /opt/scripts/
RUN mkdir -p $src_path
WORKDIR $src_path
# Copy the necessary scripts in
COPY ./Scripts/* /opt/scripts/
ENTRYPOINT [ "/opt/scripts/entrypoint.sh" ]
# ENTRYPOINT [ "./sandbox_docker-builder/entrypoint.sh" ]
\ No newline at end of file
Makefile 0 → 100644
CONTAINER_NAME=sandbox_builder
DC=docker-compose
DCR=$(DC) run
default: build
create: docker-compose.yml Dockerfile
$(DC) build
build: docker-compose.yml
$(DCR) $(CONTAINER_NAME) build
clean: docker-compose.yml
$(DCR) $(CONTAINER_NAME) clean
\ No newline at end of file
# Docker builder for Sandbox lib
Doesn't support App yet
# How to use
Create a directory, then clone ar_sandbox_lib, ar_sandbox_python and this repository in it, then cd into sandbox_docker-builder
```tree
sandbox/
|── ar_sandbox_lib/
| ├── build/
| └── ...
|── ar_sandbox_python/
| ├── build/
| └── ...
└── sandbox_docker-builder/
├── Dockerfile
├── docker-compose.yml
└── ...
```
The docker container will bind the parent folder (`sandbox`) as a volume mounted on /src inside the container.
Build the Docker container :
```
$ docker-compose build
```
You may then use the provided `Makefile`, or use the docker directly to build the lib.
### Build Output
The build artifacts will be available inside the ./build/ directory.
```
sandbox_docker-builder/
├── build/
| ├── lib/
| | └── libsandbox.so.A.B.C
| └── wrapper/
| ├── shared_lib/
| | └── python_wrapper.[...].so
| ├── ar_sandbox-X.Y.Z-py3-none-any.whl
| └── ar_sandbox-X.Y.Z.tar.gz
└── ...
```
libsandbox.so and libsandbox.so.A should be symlinked to libsandbox.so.A.B.C and made available to LD to correctly use the python wheel.
## Makefile
The provided makefile allow simple manipulation of the docker to build, clean and create the container.
#### Available targets :
| Target | Command | What it does |
|-|-|-|
| create | `make create` | Build the docker container |
| build (default) | `make` or `make build` | Build everything |
| clean | `make clean` | Cleanup |
## Docker container
To use the docker container, use the following command :
```
$ docker-compose run sandbox_builder [ARGS]
```
If `[ARGS]` is omitted, the container will build everything.
The following arguments are available :
| Arg | Description |
|-- |--|
| `build [lib] [wrapper]` | Will build the indicated component. `wrapper` should be built after `lib`. If none provided, build everything. |
| `clean [lib] [wrapper]` | Will cleanup the build directories. If no component provided, clean everything. |
| `bash` or `s` | Execute a bash terminal inside the docker. May or may not be useful. |
| `exec CMD [ARGS]` or `c [CMD] [ARGS]` | Execute the command `CMD` with the arguments `ARGS` inside the docker. May or may not be useful. |
\ No newline at end of file
#!/bin/bash
cd /build/ &&
tar -zcvf release.tgz ./wrapper ./lib
#!/bin/bash
BLU='\033[1;34m'
YLW='\033[1;33m'
GRN='\033[0;32m'
NC='\033[0m'
BASEPATH=/src/
SBOX_LIB=${BASEPATH}ar_sandbox_lib
SBOX_PYWR=${BASEPATH}ar_sandbox_python
SBOX_APPS=${BASEPATH}ar_sandbox_app
LOGS_BASE=/var/log/docker-builder/
LOGS_LIB=${LOGS_BASE}sandbox-lib.log
LOGS_PYWR=${LOGS_BASE}sandbox-wrapper.log
PY_EXTRACT_VERSION_SCRIPT=/opt/scripts/read_version.py
## CD into $1, and run the make target $2 inside the directory
function make_target() {
cd $1
mkdir -p $1/build
make $2
}
## Return the right env variable for a given component ($1)
function get_target_path() {
if [ $1 = "lib" ]; then
echo $SBOX_LIB
return 0
elif [ $1 = "wrapper" ]; then
echo $SBOX_PYWR
return 0
elif [ $1 = "apps" ]; then
echo $SBOX_APPS
return 0
else
echo "Unknown target $1"
exit 1
fi
}
function echo_links() {
local LIBNAME=`python3 ${PY_EXTRACT_VERSION_SCRIPT} libfull`
local LIBMAJ=`python3 ${PY_EXTRACT_VERSION_SCRIPT} libmajor`
local LIB=`python3 ${PY_EXTRACT_VERSION_SCRIPT} lib`
echo -e "\n${BLU}Generation done. You may want to symlink your library with the following command :${NC}\n"
echo -e "cd ./build/lib && ln -s ${LIBNAME} ${LIBMAJ} && ln -s ${LIBMAJ} ${LIB}"
echo -e "\n${BLU}To install the python wrapper :${NC}\n"
echo -e "python3 -m pip install ./build/wrapper/ar_sandbox*.whl"
echo ""
}
## Copy the result of the building process into an easily accessible place
## for the user.
function copy_artifacts() {
local LIBNAME=`python3 ${PY_EXTRACT_VERSION_SCRIPT} libfull`
echo "Copying build artifacts "
mkdir -p /build/lib
mkdir -p /build/wrapper/shared_lib
cp -f $SBOX_LIB/build/${LIBNAME} /build/lib/
cp -f $SBOX_PYWR/build/*.so /build/wrapper/shared_lib/
cp -f $SBOX_PYWR/dist/* /build/wrapper/
echo -e "${YLW}=== Lib (${GRN}./build/lib${YLW}): ===${NC}"
echo "`find /build/lib/ -type f | sed 's/\/build\/lib\///g'`"
echo -e "${YLW}=== Python Wrapper (${GRN}./build/wrapper${YLW}): ===${NC}"
echo "`find /build/wrapper/ -type f | sed 's/\/build\/wrapper\///g'`"
echo_links
}
## Build all. Yes. Really.
function build_all() {
# Export the libsandbox.so path in advance. Shouldn't
# impact the building process
export LD_LIBRARY_PATH=$SBOX_LIB/build/
echo -e "${YLW}Building ar_sandbox_lib${NC}"
make_target $SBOX_LIB
echo -e "${YLW}Building ar_sandbox_python${NC}"
make_target $SBOX_PYWR
}
## Main entry of script. Check for arguments
if [ $# -gt 0 ]; then
if [ $1 = "exec" ] || [ $1 = "c" ]; then
shift # Remove "exec" or "c", we don't need it.
RUN_CMD=$1 # First argument is the command.
shift # Remove the command from the given args
# Pass the remaining args to the command
$RUN_CMD $@
exit $? # Exit with the last return code.
elif [ $1 = "bash" ] || [ $1 = "s" ]; then
# Just execute a bash (optionnally passing commands)
shift
/bin/bash $@
exit $?
elif [ $1 = "build" ] || [ $1 = "b" ]; then
shift
export LD_LIBRARY_PATH=$SBOX_LIB/build/
if [ $# -lt 1 ]; then
# We don't have any components
# Build everything
build_all
else
for i in "$@"; do
if [ $i = "apps" ]; then
for app in `ls -d ${SBOX_APPS}/*/`; do
cd $app
make
done
else
# Build every component passed in parameters
pth=$(get_target_path "$i")
make_target $pth
fi
done
fi
copy_artifacts
exit 0
elif [ $1 = "clean" ]; then
shift
if [ $# -lt 1 ]; then
# Clean everything if there isn't any provided component
make_target $SBOX_LIB clean
make_target $SBOX_PYWR clean
else
for i in "$@"; do
# Clean every component passed in parameters
if [ $i = "apps" ]; then
for app in `ls -d ${SBOX_APPS}/*/`; do
cd $app
make clean
done
else
pth=$(get_target_path "$i")
make_target $pth clean
fi
done
fi
exit 0
elif [ $1 = "test" ]; then
shift
/opt/scripts/test-pypackage.sh
elif [ $1 = "bt" ]; then
shift
build_all
copy_artifacts
/opt/scripts/test-pypackage.sh
fi
exit 1
fi
# If we're here, there wasn't any argument provided, so we just build
# everything and copy the output.
build_all
copy_artifacts
exit 0
\ No newline at end of file
import os
import sys
MAKEFILE = "build/Makefile"
DEFAULT="/src/ar_sandbox_lib/"
def get_makefile_vars(makefile):
for l in makefile:
print(l)
def build_lib_name(makefile):
extract = lambda x: x[x.find("=") + 1:]
fullname = [extract(line) for line in makefile[:3]]
# print(".".join(fullname))
return fullname
def get_lib_name(makefile, typ="lib"):
name, minor, major = build_lib_name(makefile)
name = name + ".so"
construct = lambda namelist: ".".join(namelist)
if typ == "lib":
return construct([name])
elif typ == "min":
return construct([name, major, minor])
elif typ == "maj":
return construct([name, major])
def get_lib_full(makefile):
print(get_lib_name(makefile, typ="min"))
def get_lib_major(makefile):
print(get_lib_name(makefile, typ="maj"))
def get_lib(makefile):
print(get_lib_name(makefile, typ="lib"))
def main(args):
_operations = {
'mk': get_makefile_vars,
'libfull': get_lib_full,
'libmajor': get_lib_major,
'lib': get_lib
}
if len(args) == 1:
op = "mk"
path=DEFAULT
elif len(args) == 2:
# Op only, set default path
op = args[1]
path = DEFAULT
else:
op = args[1]
path=args[2]
file = os.path.join(path, MAKEFILE)
if os.path.exists(file) and os.path.isfile(file):
# print("Found")
makefile = read_makefile(file)
_operations.get(op, get_makefile_vars)(makefile)
else:
print("# Not found")
exit(1)
def read_makefile(path_to_makefile):
content = []
with open(path_to_makefile, 'r') as f:
content = f.readlines()
res = []
for line in content:
if line[:3] == "LIB":
res.append(line.rstrip())
return res
if __name__=="__main__":
main(sys.argv)
\ No newline at end of file
#!/usr/bin/python3
# print("Importing classes")
from ar_sandbox import Sandbox, DummySandbox
# print("Importing wrapper")
from ar_sandbox.wrapper import sandbox_wrapper as sw
import numpy as np
import cv2
print("Import done.")
# Lambda helpers
p = lambda d: print(repr(d))
n = lambda m: np.array(m)
pn = lambda m: p(n(m))
tric = lambda a: np.dstack((a, a, a))
arr = lambda x, y, d=np.float32: np.linspace(0, (x*y)-1, (x*y), dtype=d).reshape(x, y)
assert_equal = lambda ary1,ary2: np.testing.assert_array_equal(ary1, ary2)
uint8=np.uint8
result_arr = [[7, 8, 9], [13, 14, 15], [19, 20, 21]]
result_arr_float = np.array(result_arr, dtype=np.float32)
result_arr_int = np.dstack((result_arr, result_arr, result_arr))
# Floats
print("Testing 1 channel float32")
print("\t Testing numpy to cv to numpy conversion... ", end="")
array_float = arr(3,4)
matf = sw.cvMatf(array_float)
assert_equal(array_float, n(matf))
print("passed")
print("\t Testing cropped matrix conversion... ", end="")
cropped_float = sw.newf()
assert_equal(result_arr_float, n(cropped_float))
print("passed")
# Ints
print("Testing 3 channels uint8")
print("\t Testing numpy to cv to numpy conversion... ", end="")
array_int = tric(arr(3, 4, uint8))
mati = sw.cvMat3b(array_int)
assert_equal(array_int, n(mati))
print("passed")
print("\t Testing cropped matrix conversion... ", end="")
cropped_int = sw.new()
assert_equal(result_arr_int, n(cropped_int))
print("passed")
#!/bin/bash
export LD_LIBRARY_PATH=/build/lib/
cd /src/
python3 -m pip install /build/wrapper/*.whl
python3 /src/sandbox_docker-builder/Scripts/test-pypackage.py
\ No newline at end of file
version: '2.3'
services:
sandbox_builder:
container_name: "sandbox_builder"
image: sandbox_builder
build:
dockerfile: ./Dockerfile
context: ./
args:
src_path: /src
volumes:
- .././:/src:rw
- ./build/:/build:rw
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment