Skip to content

Commit 7ae9e35

Browse files
kasperdoktersebheger
authored andcommitted
Update install.rst
I added an installation guide that uses Docker to compile on a Raspberry Pi running Alpine Linux. Since the Alpine package manager is slightly different, I had te figure out which packages were missing in a default installation (namely, bash, make, and patch) and how some of the libraries have different names. I decided to share my (generic) dockerfile with the public, as it may be of help for others (and future me).
1 parent 2a1a5d7 commit 7ae9e35

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/install.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,62 @@ Please note that CBC uses multiple libraries which are installed in the same dir
7676
export LD_LIBRARY_PATH="/home/haroldo/prog/lib/":$LD_LIBRARY_PATH
7777
7878
In Linux, to make these changes persistent, you may also want to add the :code:`export` lines to your :code:`.bashrc`.
79+
80+
Docker installation (optional)
81+
------------------------------
82+
83+
It is also possible to containerize the above build process using Docker. The following dockerfile shows how to build CBC for Python-MIP for an linux/arm/v6 platform (i.e., a Raspberry Pi 2 B). The dockerfile starts from Alpine Linux, which requires slightly different libraries than the Debian libraries above. Depending on your :code:`requirements.txt`, you may need to install additional libraries in the :code:`apk add` command. The dockerfile does not include the optional dependencies of CBC (:code:`libamd2 libcholmod3 libmetis-dev libsuitesparse-dev libnauty2-dev`).
84+
85+
.. code-block:: sh
86+
87+
# syntax=docker/dockerfile:1
88+
FROM arm32v6/python:3.7-alpine3.15 AS builder
89+
RUN apk add --no-cache \
90+
bash \
91+
gcc \
92+
gfortran \
93+
git \
94+
g++ \
95+
libffi-dev \
96+
libgfortran \
97+
lapack-dev \
98+
make \
99+
patch
100+
RUN wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
101+
RUN chmod u+x coinbrew
102+
RUN ./coinbrew fetch Cbc@master
103+
RUN ./coinbrew build Cbc@master --prefix=/home/haroldo/prog/ --tests=none --enable-cbc-parallel --enable-relocatable
104+
COPY requirements.txt requirements.txt
105+
RUN mkdir /pip-install && pip3 install --prefix=/pip-install -r requirements.txt
106+
107+
FROM arm32v6/python:3.7-alpine3.15
108+
RUN apk add --no-cache \
109+
libffi-dev \
110+
libgfortran \
111+
lapack-dev \
112+
libstdc++6
113+
COPY --from=builder /home/haroldo/prog /home/haroldo/prog/
114+
COPY --from=builder /pip-install /usr/local
115+
COPY . .
116+
ENV PMIP_CBC_LIBRARY="/home/haroldo/prog/lib/libCbc.so"
117+
ENV PATH=$PATH:/home/haroldo/prog/bin
118+
RUN chmod u+x ./entrypoint.sh
119+
ENTRYPOINT ["./entrypoint.sh"]
120+
121+
There are two ways to build this dockerfile. The first option is to build on the same device as where your run the code. In case of the Raspberry Pi, you need a lot of patience (more than 12 hours) to build using the following command:
122+
123+
.. code-block:: sh
124+
125+
docker build -t <tag> .
126+
127+
The second option is to build on a fast device and deploy on another. Most likely, your development machine does not have the linux/arm/v6 architecture, and you require cross-compilation with :code:`buildx`. This option requires an account at `Docker Hub <https://hub.docker.com/>`_. You can run the following to build the code:
128+
129+
.. code-block:: sh
130+
131+
docker buildx create --name mybuilder
132+
docker buildx use mybuilder
133+
docker buildx inspect --bootstrap
134+
docker login
135+
docker buildx build --platform linux/arm/v6 -t <your-docker-hub-username>/<reponame> . --push
136+
137+

0 commit comments

Comments
 (0)