Compile and test a C++ application
Using Codefresh pipelines
Codefresh can work with any C/C++ application very easily as both gcc
and g++
are already offered in Dockerhub. There is also another example available with C and make.
The example C++ project
You can see the example project at https://github.com/codefresh-contrib/cpp-sample-app. The repository contains a C++ starter project with a CMakeLists.txt
file:
cmake .
creates the makefiles.make test
runs unit testsmake
compiles the code
The project is also using the boost testing libraries.
Cmake, g++ and Docker
Creating a CI/CD pipeline for C is very easy, because Codefresh can run any gcc image that you wish. Gcc docker images already contain the make
utility but not the the cmake
one. Therefore we will first create a Dockerfile that has g++
, cmake and the boost libraries. You can follow the same pattern for other development tools that you use.
Here is the Dockerfile:
Dockerfile
This docker build does the following:
- Starts from the GCC image
- Installs cmake and boost
- Sets cmake as the default command
Create a CI pipeline for C++ applications
We can now use the custom Docker image in order to compile/test the C++ application:
Here is the full pipeline that compiles the application after checking out the code.
codefresh.yml
This pipeline:
- clones the source code
- Creates a development docker image that has g++, cmake and boost
- Runs cmake on the source code to create the make files
- Compiles the source code
- Runs unit tests
You can add additional tools in the pipeline by extending the Dockerfile mentioned in the previous section. You can also change the version of Gcc/g++ by starting from a different public or private Docker image.
Related articles
C example
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work