pratikpc/cpp-builder-docker
Use CMake, Ninja & VCPKG to build Docker images
C++ Docker Builder
Uses
What you need to install?
- Docker alone
Using Docker, the rest of the process is handled by the image.
I know it works on Linux. But does it work on Windows?
Yes it does work on Windows
All you need to do is install Docker Desktop
The generated items are Linux based.
So for quite a few projects, this could replace your need for VMs.
Simplest usage sample
- For this, we recommend using a docker-compose file.
- Using Docker Compose, we can create a volume
- To store
- build data
- VCPKG
- Run commands easily
- Share data easily
Docker-Compose usage
Downloading VCPKG/Updating it
By default, our images don't ship with VCPKG
This is because by the time you use it, you might want newer, more updated vcpkg
Hence, run this very simple command.
This command installs VCPKG if absent, or updates it.
Run docker compose run --rm vcpkg
Run CMake
If you just want to run CMake and find out the version
Run docker compose run --rm cmake --version
Generate CMake
To generate CMake Ninja build,
Run docker compose run gen
To pass commands to CMake Generator,
(Like variables)
Run docker compose run gen -DENABLE_TEST=""
You can add configuration options to select C++ Compilers etc.
``
Build
To build,
Run docker compose run build
VCPKG
To run VCPKG,
And view the version
Run docker compose run --rm run-vcpkg version
Run tests
To run CTests,
Run docker compose run --rm ctest
Run generated Code
To run your generated code
You can
Run docker compose run --rm execute /build/sample/sample
To make it even easier,
You can make a small configuration in your Docker Compose
run-sample:
image: fedora
entrypoint: /build/sample/sample
volumes:
- vcpkg:/vcpkg
- build:/buildAfter adding this configuration,
You can run it simply with
Run docker compose run --rm run-sample-parser
Docker-Compose file
version: "3.7"
services:
cmake:
image: ghcr.io/pratikpc/cpp-builder-docker/cmake:latest
vcpkg:
image: ghcr.io/pratikpc/cpp-builder-docker/vcpkg:latest
volumes:
- vcpkg:/vcpkg
gen:
image: ghcr.io/pratikpc/cpp-builder-docker/gen:latest
volumes:
- vcpkg:/vcpkg
- build:/build
- ./:/source
build:
image: ghcr.io/pratikpc/cpp-builder-docker/build:latest
volumes:
- vcpkg:/vcpkg
- build:/build
- ./:/source
ctest:
image: ghcr.io/pratikpc/cpp-builder-docker/ctest:latest
volumes:
- build:/build
execute:
image: fedora
volumes:
- vcpkg:/vcpkg
- build:/build
run-vcpkg:
image: fedora
entrypoint: vcpkg/vcpkg
volumes:
- vcpkg:/vcpkg
volumes:
vcpkg: {}
build: {}Why Fedora?
- We have quite a few dependencies
- They are fairly popular
- Ubuntu packages are usually not up to date.
- Installing without Package Manager might require manual intervention.
- So it was noticed that it would be far easier to
- Rely on a distro known to update their packages
- The newer compilers come with newer features, newer updates etc.
Deployment
- The images are deployed on GitHub Container Registry
- The deployment process is automated using GitHub Actions and runs every month
- If you seek an update more quickly, you can always create a PR or contact me
Recommended usage
- We would recommend you to
- Follow Modern CMake Practices
- Use VCPKG.json to manage your packages.
- As we already set the project to use VCPKG toolchain file
- Using vcpkg.json would allow vcpkg to
- Respect your configuration settings
- Make it easy for you to set your own configuration
- Make distribution easy
- Make project versioning easy
- For further details, check VCPKG website
I want to install additional packages to the base (CMake) image
- I expect the need would not be felt when it comes to VCPKG based packages
- In such a scenario as this when you wish to modify the CMake package,
Use Dockerfile to attain that
FROM ghcr.io/pratikpc/cpp-builder-docker/cmake:latest
RUN dnf install <package-names>And then update the rest of the packages in your fork because all images except VCPKG ones depend on the CMake base image
I want to install additional packages to the Build image
Use Dockerfile to attain that
FROM ghcr.io/pratikpc/cpp-builder-docker/build:latest
RUN dnf install <package-names>And then in your Docker Compose file, replace our build image with yours
Contact me
You can contact me via LinkedIn
Or you can create a GitHub Issue!
Sample C++ Library with implementation
I have created a simple C++ RSS Parser header only library.
The library contains a sample file and a CTest Unit test sample.
I have added a Docker Compose file there
You can check it out