Skip to content

Commit d5bbb1f

Browse files
committed
modernize containers
use compose spec, use single image repo with tags for various configs, create a docker hub push script, clean up/slim down container files
1 parent 5550537 commit d5bbb1f

File tree

17 files changed

+249
-186
lines changed

17 files changed

+249
-186
lines changed

containers/Containerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# base image off ubuntu image
2+
ARG UBUNTU_TAG=22.04
3+
FROM docker.io/ubuntu:${UBUNTU_TAG}
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
# dependencies
7+
libboost-all-dev \
8+
# optional dependencies
9+
libtbb-dev \
10+
python3-dev \
11+
python3-pip \
12+
python3-pyparsing \
13+
python3-numpy \
14+
# build dependencies
15+
build-essential \
16+
cmake \
17+
# download dependencies
18+
git \
19+
ca-certificates && \
20+
rm -rf /var/lib/apt/lists/*
21+
22+
# build flags
23+
ARG GTSAM_GIT_TAG=4.2.0
24+
ARG GTSAM_WITH_TBB=ON
25+
ARG GTSAM_BUILD_PYTHON=ON
26+
ARG CORES=4
27+
28+
# build and install gtsam
29+
RUN mkdir -p /src/github/borglab && cd /src/github/borglab && \
30+
git clone https://github.com/borglab/gtsam --depth 1 --branch ${GTSAM_GIT_TAG} && \
31+
cd gtsam && \
32+
mkdir build && \
33+
cd build && \
34+
cmake \
35+
-DCMAKE_BUILD_TYPE=Release \
36+
-DGTSAM_BUILD_TESTS=OFF \
37+
-DGTSAM_WITH_TBB=${GTSAM_WITH_TBB} \
38+
-DGTSAM_BUILD_PYTHON=${GTSAM_BUILD_PYTHON} \
39+
.. && \
40+
make -j${CORES} install && \
41+
if [ "${GTSAM_BUILD_PYTHON}" = "ON" ] ; then \
42+
make python-install; \
43+
fi
44+
45+
CMD ["/bin/bash"]

containers/README.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# GTSAM Containers
2+
3+
- container files to build images
4+
- script to push images to a registry
5+
- instructions to pull images and run containers
6+
7+
## Dependencies
8+
9+
- a container engine
10+
11+
Below we use [podman](https://podman.io), but you should be able to replace any `podman` calls to a Docker-compatible CLI such as [`docker`](https://www.docker.com/) or [`nerdctl`](https://github.com/containerd/nerdctl).
12+
13+
## Pull from Docker Hub
14+
15+
Various GTSAM image configurations are available at [`docker.io/borglab/gtsam`](https://hub.docker.com/r/borglab/gtsam). Determine which [tag](https://hub.docker.com/r/borglab/gtsam/tags) you want and pull the image.
16+
17+
Example for pulling an image with GTSAM compiled with TBB and Python support on top of a base Ubuntu 22.04 image.
18+
19+
```bash
20+
podman pull docker.io/borglab/gtsam:4.2.0-tbb-ON-python-ON_22.04
21+
```
22+
23+
[`docker.io/borglab/gtsam-vnc`](https://hub.docker.com/r/borglab/gtsam-vnc) is also provided as an image with GTSAM that will run a VNC server to connect to.
24+
25+
## Using the images
26+
27+
### Just GTSAM
28+
29+
To start the image, execute
30+
31+
```bash
32+
podman run -it borglab/gtsam:4.2.0-tbb-ON-python-OFF_22.04
33+
```
34+
35+
after you will find yourself in a bash shell.
36+
37+
### GTSAM with Python wrapper
38+
39+
To use GTSAM via the python wrapper, similarly execute
40+
41+
```bash
42+
podman run -it borglab/gtsam:4.2.0-tbb-ON-python-ON_22.04
43+
```
44+
45+
and then launch `python3`:
46+
47+
```bash
48+
python3
49+
>>> import gtsam
50+
>>> gtsam.Pose2(1,2,3)
51+
(1, 2, 3)
52+
```
53+
54+
### GTSAM with Python wrapper and VNC
55+
56+
First, start the image, which will run a VNC server on port 5900:
57+
58+
```bash
59+
podman run -p 5900:5900 borglab/gtsam-vnc:4.2.0-tbb-ON-python-ON_22.04
60+
```
61+
62+
Then open a remote VNC X client, for example:
63+
64+
#### Linux
65+
66+
```bash
67+
sudo apt-get install tigervnc-viewer
68+
xtigervncviewer :5900
69+
```
70+
71+
#### Mac
72+
73+
The Finder's "Connect to Server..." with `vnc://127.0.0.1` does not work, for some reason. Using the free [VNC Viewer](https://www.realvnc.com/en/connect/download/viewer/), enter `0.0.0.0:5900` as the server.
74+
75+
## Build images locally
76+
77+
### Build Dependencies
78+
79+
- a [Compose Spec](https://compose-spec.io/) implementation such as [podman-compose](https://github.com/containers/podman-compose) or [docker-compose](https://docs.docker.com/compose/)
80+
81+
### `gtsam` image
82+
83+
#### `.env` file
84+
85+
- `GTSAM_GIT_TAG`: [git tag from the gtsam repo](https://github.com/borglab/gtsam/tags)
86+
- `UBUNTU_TAG`: image tag provided by [ubuntu](https://hub.docker.com/_/ubuntu/tags) to base the image off of
87+
- `GTSAM_WITH_TBB`: to build GTSAM with TBB, set to `ON`
88+
- `GTSAM_BUILD_PYTHON`: to build python bindings, set to `ON`
89+
- `CORES`: number of cores to compile with
90+
91+
#### Build `gtsam` image
92+
93+
```bash
94+
podman-compose build
95+
```
96+
97+
### `gtsam-vnc` image
98+
99+
#### `gtsam-vnc/.env` file
100+
101+
- `GTSAM_TAG`: image tag provided by [gtsam](https://hub.docker.com/r/borglab/gtsam/tags)
102+
103+
#### Build `gtsam-vnc` image
104+
105+
```bash
106+
podman-compose --file gtsam-vnc/compose.yaml build
107+
```
108+
109+
## Push to Docker Hub
110+
111+
Make sure you are logged in via: `podman login docker.io`.
112+
113+
### `gtsam` images
114+
115+
Specify the variables described in the `.env` file in the `hub_push.sh` script.
116+
To push images to Docker Hub, run as follows:
117+
118+
```bash
119+
sh hub_push.sh
120+
```
121+
122+
### `gtsam-vnc` images
123+
124+
Specify the variables described in the `gtsam-vnc/.env` file in the `gtsam-vnc/hub_push.sh` script.
125+
To push images to Docker Hub, run as follows:
126+
127+
```bash
128+
sh gtsam-vnc/hub_push.sh
129+
```

containers/compose.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
gtsam:
3+
build:
4+
args:
5+
UBUNTU_TAG: ${UBUNTU_TAG}
6+
GTSAM_GIT_TAG: ${GTSAM_GIT_TAG}
7+
GTSAM_WITH_TBB: ${GTSAM_WITH_TBB}
8+
GTSAM_BUILD_PYTHON: ${GTSAM_BUILD_PYTHON}
9+
CORES: ${CORES}
10+
context: .
11+
dockerfile: Containerfile
12+
env_file:
13+
- .env
14+
image: gtsam:${GTSAM_GIT_TAG}-tbb-${GTSAM_WITH_TBB}-python-${GTSAM_BUILD_PYTHON}_${UBUNTU_TAG}

containers/gtsam-vnc/Containerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This image connects to the host X-server via VNC to provide a Graphical User Interface for interaction.
2+
3+
# base image off gtsam image
4+
ARG GTSAM_TAG=4.2.0-tbb-ON-python-ON_22.04
5+
FROM docker.io/borglab/gtsam:${GTSAM_TAG}
6+
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
# Things needed to get a python GUI
9+
python3-tk \
10+
python3-matplotlib \
11+
# Install a VNC X-server, Frame buffer, and windows manager
12+
x11vnc \
13+
xvfb \
14+
fluxbox \
15+
# Finally, install wmctrl needed for bootstrap script
16+
wmctrl \
17+
rm -rf /var/lib/apt/lists/*
18+
19+
COPY bootstrap.sh /
20+
CMD ["/bootstrap.sh"]

docker/ubuntu-gtsam-python-vnc/bootstrap.sh containers/gtsam-vnc/bootstrap.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ trap control_c SIGINT SIGTERM SIGHUP
108108

109109
main
110110

111-
exit
111+
exit

containers/gtsam-vnc/compose.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
gtsam_vnc:
3+
build:
4+
args:
5+
GTSAM_TAG: ${GTSAM_TAG}
6+
context: .
7+
dockerfile: Containerfile
8+
env_file:
9+
- .env
10+
image: gtsam-vnc:${GTSAM_TAG}

containers/hub_push.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# A script to push images to Docker Hub
2+
3+
declare -a ubuntu_tags=("22.04")
4+
declare -a gtsam_git_tags=("4.2.0")
5+
declare -a gtsam_with_tbb_options=("ON", "OFF")
6+
declare -a gtsam_build_python_options=("ON", "OFF")
7+
8+
for ubuntu_tag in "${ubuntu_tags[@]}"; do
9+
for gtsam_git_tag in "${gtsam_git_tags[@]}"; do
10+
for gtsam_with_tbb in "${gtsam_with_tbb_options[@]}"; do
11+
for gtsam_build_python in "${gtsam_build_python_options[@]}"; do
12+
13+
touch .env
14+
echo "UBUNTU_TAG=${ubuntu_tag}" > .env
15+
echo "GTSAM_GIT_TAG=${gtsam_git_tag}" >> .env
16+
echo "GTSAM_WITH_TBB=${gtsam_with_tbb}" >> .env
17+
echo "GTSAM_BUILD_PYTHON=${gtsam_build_python}" >> .env
18+
echo "CORES=4" >> .env
19+
20+
podman-compose build
21+
22+
podman tag gtsam:"${gtsam_git_tag}-tbb-${gtsam_with_tbb}-python-${gtsam_build_python}_${ubuntu_tag}" \
23+
docker.io/borglab/gtsam:"${gtsam_git_tag}-tbb-${gtsam_with_tbb}-python-${gtsam_build_python}_${ubuntu_tag}"
24+
25+
podman push docker.io/borglab/gtsam:"${gtsam_git_tag}-tbb-${gtsam_with_tbb}-python-${gtsam_build_python}_${ubuntu_tag}"
26+
27+
done
28+
done
29+
done
30+
done

docker/README.md

-63
This file was deleted.

docker/ubuntu-boost-tbb/Dockerfile

-19
This file was deleted.

docker/ubuntu-boost-tbb/build.sh

-3
This file was deleted.

docker/ubuntu-gtsam-python-vnc/Dockerfile

-20
This file was deleted.

docker/ubuntu-gtsam-python-vnc/build.sh

-4
This file was deleted.

docker/ubuntu-gtsam-python-vnc/vnc.sh

-5
This file was deleted.

0 commit comments

Comments
 (0)