Docker Image for OpenCascade Development

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Docker Image for OpenCascade Development

Post by ezzieyguywuf »

Hi. I'm working on creating a docker container with opencascade. My intent is to use this with CI that requires opencascade, so that I don't have to rely on ubuntu's out-date OCE.

For now, you can see my docker image here. This contains opencascade version 7.3.0. I'm working on shrinking this file size a bit (it's over a gigabyte right now!) but thought I'd post this in case anyone else is interested.

If there is a desire/need, I can make one for opencascade 7.2.0 (or any version really...)

Uhm, here's an example use-case (locally):

Code: Select all

myComp -> docker run -it ezzieyguywuf/opencascade:7.3.0    # start the docker container
myDocker -> apk add --no-cache make cmake git \
            gcc g++ python3 python3-dev                    # add packages needed for build
myDocker -> git clone --recurse-submodules \
            https://www.gitlab.com/ezzieyguywuf/OccWrapper # get code that uses occ
myDocker -> cd OccWrapper                                  # build and test code
myDocker -> mkdir build
myDocker -> cd build
myDocker -> cmake ..
myDocker -> make -j2 test
myDocker -> exit                                           # exit docker container
myComp-> docker rm $(docker ps -a -q)                      # clean up disk space
Here, OccWrapper depends on opencascade, but you can see that I didn't have to worry about installing it because it is already provided by this docker image.

This can also be used in travis-ci by specifying "ezzieyguywuf/opencascade:7.3.0" instead of, say, "ubuntu:14.04"
User avatar
Kunda1
Veteran
Posts: 13350
Joined: Thu Jan 05, 2017 9:03 pm

Re: Docker Image for OpenCascade Development

Post by Kunda1 »

Relevant but off topic, can you make a FreeCAD 0.18dev docker as well ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Docker Image for OpenCascade Development

Post by ezzieyguywuf »

Kunda1 wrote: Thu Jul 12, 2018 7:40 pm Relevant but off topic, can you make a FreeCAD 0.18dev docker as well ?
Yes.

My focus right now is to build up, piece-by-piece, a toolchain that lets me use some of the CI (i.e. travis-ci) tools to build/test/deploy the two libraries I'm working on for TopoNaming. The last step in that process will be to use these deployed libraries (appimage? docker? deb?) to build a standalone freecad instance (appimage?) that anyone can run and test.

I could work on building freecad-dev directly on top of this opencascade docker instance as well, but again currently my focus (and interest) is elsewhere. I'll see when I can get to it though.

FYI, to use docker you need to have it installed on your system. The nice thing about AppImage in that that it works completely standalone. However, docker appears to be better suited for development as it provides a full environment in which you can add packages, build, etc.

All that to say: the final freecad payload may still be best suited for an AppImage, but that's not to say it couldn't be built inside a docker container.

In fact, I think I'll
  1. create a new docker container, using the ezzieyguywuf/opencascade:7.3.0 image
  2. download freecad
  3. install freecad dependencies (using apt-get since this image is based on ubuntu)
  4. create a freecad deb using dpkg
  5. finally, create an AppImage from the dpkg
*shrug* that's the plan at least.
User avatar
Kunda1
Veteran
Posts: 13350
Joined: Thu Jan 05, 2017 9:03 pm

Re: Docker Image for OpenCascade Development

Post by Kunda1 »

Can you describe how one would go about building FC 0.18dev via docker ? What are the steps. I'd play with it since I have docker installed but don't know too much about it.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Docker Image for OpenCascade Development

Post by ezzieyguywuf »

The docker documentation is actually quite good. this and this are the main references I used.

In short, though: docker runs as a daemon on your computer. You talk to it using the "docker" command in your terminal. unless you want to run everything as root, I would add your user to the "docker" group (you'll have to log out then back in after you do this...I actually had to pull a Windoze and reboot...)

The bases for docker is what is called an "image". It's essentially a configuration that docker manages that, for lack of a better term, describes a sandboxed "chroot" that you can access using the "docker" command. There are tons of different images available, mostly on the docker hub.

To access any of these image's, you simply issue "docker run -it <image name>[:version]". The "-it" makes the access interactive, i.e. it drops you into a shell.

The "hello world" for docker is esentially "docker run -it busybox /bin/sh".

Anywho, the other core aspect of the dockerverse is create new images. It appears (based on my limited knowledge) that the vast majority of new images are created using another image as a base. It seems popular to use "alpine" as a base, because it is a super small variant of linux. Unfortunately, alpine uses a weird glibc alternative called musl that opencascade does not compile against, so instead I used ubuntu as a basis.

In order to create a new docker, there are essentially two steps:
  1. create a Dockerfile
  2. run the command "docker build"
The docker file's syntax is pretty basic, but essentially what you need to know is:

Code: Select all

FROM ezzieyguywuf/opencascade:7.3.0
RUN apt-get update \
    && apt-get install git cmake make <other freecad dependencies...> \
    && git clone <wherever freecad is nowadays> \
    && cd FreeCAD \
    && mkdir build \
    && cd build \
    && cmake .. \
    && make -j2 install \
    && cd .. \
    && rm -rf FreeCAD
    && rm -rf /var/lib/apt/lists/* \
    && apt-get --auto-remove purge git cmake make <any -dev packages>
The key points here:
  • the "FROM" designates the docker image to use as a basis. The smaller the base, the smaller the final image
  • notice I put my entire build in one 'RUN' command. This is to keep the final file size smaller because of "layers" or something. it's a docker thing...
  • notice I clean up after myself. Again, this is to keep the final file size small
I'll usually do "docker run -it ezzieyguywuf/opencascade:7.3.0" to drop into an interactive shell and figure out all the commands/dependencies I need to make something build. once I work it out there, I'll just translate that to the docker file, and issue "docker build -t myuser/myimage:myversion" to create the new image. Now I'll have locally available "docker run -it myuser/myimage" (defaults to latest version) to run. If I want to make publically available, I create a docker hub account and "docker login" then "docker push myuser/myimage:myversion".

If it sounds pretty simple it's because it is. It's been quite the treat working with docker.

Do spend some time reading some of the docs though: it's not overly technical or cumbersome and will likely make your life easier.
User avatar
NormandC
Veteran
Posts: 18574
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Docker Image for OpenCascade Development

Post by NormandC »

ezzieyguywuf wrote: Thu Jul 12, 2018 6:13 pm so that I don't have to rely on ubuntu's out-date OCE.
You do know that the FreeCAD PPA has been providing OCC >=7 for quite some time? (for at least 18 months) They include dev packages.

kkremitzki just upgraded them to OCC 7.3.0.

https://launchpad.net/~freecad-maintain ... t-releases
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Docker Image for OpenCascade Development

Post by ezzieyguywuf »

NormandC wrote: Fri Jul 13, 2018 4:09 am
ezzieyguywuf wrote: Thu Jul 12, 2018 6:13 pm so that I don't have to rely on ubuntu's out-date OCE.
You do know that the FreeCAD PPA has been providing OCC >=7 for quite some time? (for at least 18 months) They include dev packages.

kkremitzki just upgraded them to OCC 7.3.0.

https://launchpad.net/~freecad-maintain ... t-releases
no.

I also dont know what a PPA is (is that an ubuntu package repository?)

either way this docker thing has been fun and educational for me, so it was not time wasted.

also, I though I checked this (like 6 or so months ago) and saw that freecad used the Ubuntu oce packages in its yaml config file - maybe I just looked in the wrong place.
User avatar
Kunda1
Veteran
Posts: 13350
Joined: Thu Jan 05, 2017 9:03 pm

Re: Docker Image for OpenCascade Development

Post by Kunda1 »

ezzieyguywuf wrote: Thu Jul 12, 2018 8:35 pm In short...
@ezzieyguywuf thank you for the mini tut! I plan to experiment with this.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
NormandC
Veteran
Posts: 18574
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Docker Image for OpenCascade Development

Post by NormandC »

ezzieyguywuf wrote: Fri Jul 13, 2018 10:49 am I also dont know what a PPA is (is that an ubuntu package repository?)
How long have you been using Ubuntu? I'm puzzled that an experienced Ubuntu user would ask this question.

PPA stands for Personal Package Archive and is a service provided freely by Canonical (the company that publishes Ubuntu) on launchpad.net. It allows open source projects and individuals to offer their own newer versions of software and libraries than those found on Ubuntu repositories.

Also, PPAs have been the preferred installation method for FreeCAD on Ubuntu since 2011. We have a freecad-stable PPA and a freecad-daily PPA (plus a few more PPAs). There have been numerous topics about its use or about packaging for it in the Install/Compile forum over the years. The Install on Unix wiki page details its use. You have never heard of it?!? :?

I managed the FreeCAD maintainers PPAs from 2011 to 2015. sgrogan has been its manager since 2015, and kkremitzki started to contribute this year. He's the one who updated our OCCT packages to OCC 7.3.
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Docker Image for OpenCascade Development

Post by ezzieyguywuf »

I actually don't use ubuntu so I'm not terribly familiar with it. thanks for the explanation.
Post Reply