juanmanzanero / fastest-lap

Fastest-lap is a vehicle dynamics simulator. It can be used to understand vehicle dynamics, to learn about driving techniques, to design car prototypes, or just for fun!
MIT License
575 stars 43 forks source link

Dockerize the build environment for Linux compilation #2

Closed kktse closed 2 years ago

kktse commented 2 years ago

Provide a Dockerized build environment for Linux compilation. The dockerfile will pull ubuntu:latest, install the required build dependencies and drop the user into a bash shell. The compilation instructions can be followed from within the docker container.

I had difficulty building and running the library locally on my arch linux machine, either having difficulty compiling or having missing references to other packages. To avoid interference with any local machine configuration, this was the solution I came up with to build the project.

Changes

Tested

I can run the example Python notebooks

image

Problems / Feedback

The package builds as the docker user and in the directory of the docker container. Some of the cmake steps generate files like examples/fastest_lap.py with absolute file paths referenced from the docker container, not the host machine. Files created within the docker container inherit root permissions.

The docker script will drop the user into a docker container and will not automatically build the project.

juanmanzanero commented 2 years ago

Hello Kevin. First, thank you for your interest in Fastest-lap. About your request, sorry I am no expert in this matter. Can you please give me more details about what a docker file does and why it is needed? Thank you!

kktse commented 2 years ago

The motivation for this change is to provide a standardized build environment for fastest-lap for Linux users. This change reduces the build requirements for Linux users to simply having Docker installed.

Given the minimal documentation regarding the build environment for this project, a Docker image provides standardization and removes individual variables due to differences between computers (ex. compiling on Ubuntu vs compiling on Arch) from the compilation process.

Note: because this change is Linux specific, I placed my changes in scripts/linux.

What is a Dockerfile?

Docker is a type of virtualization technology. The Dockerfile introduced in this change defines the steps to create a Docker image, a pre-built template for the build environment. This image is built locally on the users machine.

https://github.com/juanmanzanero/fastest-lap/blob/10b68f04005f0d3fb359e8afb8b1e99f57caf925/scripts/linux/Dockerfile#L1-L15

The Docker image for this project is based on the latest Ubuntu image on Docker Hub. This corresponds to Ubuntu 20.04 at the time of writing. I chose Ubuntu since this is what your CI uses for Linux builds. Some environment variables are set to facilitate installing packages and then the requisite packages are installed in the image.

https://github.com/juanmanzanero/fastest-lap/blob/10b68f04005f0d3fb359e8afb8b1e99f57caf925/scripts/linux/run_docker.sh#L1-L2

The helper script first builds the Docker image using the instructions from the Dockerfile. The second line runs the image as a Docker container, mounting the source code of the project inside the container and dropping the user into an interactive shell. At this point, the user can follow the compile instructions.

Screenshot from 2022-04-10 20-42-49

In short, I define a "virtual machine" with all the build tools installed in order to compile the project.

Why do you need a Dockerfile?

The compilation requirements of this project are non-trivial. It took me 2+ hours to get this project to build unsuccessfully either due to problems linking IPOPT or METIS. This limits the usefulness of the project since it is very difficult to build.

The Docker build environment provides a consistent Linux build platform that is agnostic to the host machine configuration.

Counterpoint - Why do you not need a Dockerfile?

Please let me know if there's any more context I can provide!

juanmanzanero commented 2 years ago

Hello! Thank you very much for this detailed explanation! in my mind, installation should've been straightforward, as in ubuntu and macOS it is prepared to just hit 'CMake ..' and 'make'. However, I have never tried on arch. So thank you.

Two questions to remain (sorry about being so pesky): 1) What can be done about the fastest_lap.py file? Absolute paths were preferred because the user can put the build directory in a completely different location than the source code directory. If the docker thingy always builds the build in the same folder, we could use a relative path for it, right? Maybe we can pass a flag to cmake saying PYTHON_API_ABSOLUTE_PATH:bool and switch between both absolute (default) and relative (only for docker builds) there? 2) Does it need to be in the ./scripts folders? I already have a ./src/scripts folder, and I prefer those to be there. Can it be there, or for some requisite the folder where docker will look for its files is always ./scripts?

juanmanzanero commented 2 years ago

I just have added the PYTHON_API_ABSOLUTE_PATH option to CMakeLists. By default it is ON, the docker file should call cmake with -DPYTHON_API_ABSOLUTE_PATH=Off

GinoMartens commented 2 years ago

On Windows I keep having problems while compiling, both with MinGW and with MSVS compilers. So I support this docker approach! Tempted to try and make a dockerfile for a windows config, but not so confident yet.

juanmanzanero commented 2 years ago

On Windows I keep having problems while compiling, both with MinGW and with MSVS compilers. So I support this docker approach! Tempted to try and make a dockerfile for a windows config, but not so confident yet.

Yes, I fully agree with you. I just want to clarify some points with @kktse about some changes I did regarding the python library path handling. Thank you!

juanmanzanero commented 2 years ago

Great work, Kevin. Thank you for your time! Cheers.

kktse commented 2 years ago

Glad to help. Really awesome project, looking forward to using it!

juanmanzanero commented 2 years ago

Nice dog btw!!!