DevOP 101


Development is not something that one finishes learning. As it is with most academia, learning in general is not something we ever finish. We just keep building onto our knowledge base and sometimes refactoring our knowledge to meet new ideologies and principles. With that said there are many great books that teach us valuable skills though they where written 5 to 10 years ago and their tool chains are outdated by today's standard. Sometimes the changes are mild enough for us to still work with the book despite the older tool chains. Sometimes the changes are so radical that it is more work to try to adapt the source to our modern tool chains then to just get a different resource. Though, not all books are of the same quality. So when you find a good one it is nice to use that book. Learn the techniques and then worry about adapting those techniques to a modern tool chain once they are fully understood.

In this day and age this challenge has never been easier for a developer to overcome. I am a Fedora user so I use podman in these examples though you could just as easily use docker if you feel it necessary to do so. Okay, so we are looking at the Packt book 'C++ Programming for Linux Systems: Create robust enterprise software for Linux and Unix-based operating systems' Upon examining the introduction we realize that the book is showing its age and the authors used Mint 21 with the gcc 12.x tool chain. Yeah, that is a bit old for today's standards though still completely usable. There is nothing taught in the book that will not be valuable by today's standards. Yet trying to work with the books source on a modern system could be a challenge one does not wish to accept while learning the material. Our solution? Build an OCI container with the author's suggested tool chain installed so that we know the book source should build without issues.

It is a good DevOP practice to setup containers for development in any case. So we can effectively reduce the 'It worked on my machine' phenomenon. So let us setup a Container for our book. First you should navigate to the books source code, in this case it is on GitHub, and clone it to a directory on your system. We are going to reference this directly in our Container so we will want it prepared before we begin. For our book in this example the source is here.

Okay, we have the source ready in a directory so let us build a container for working with the book source code! The following is a Containerfile (which can also be named Dockerfile as podman will accept either).
Containerfile

# Use the official standalone Linux Mint 21 base runtime image
FROM docker.io/linuxmintd/mint21-amd64:latest

# Prevent interactive prompts during package installations
ENV DEBIAN_FRONTEND=noninteractive

# Update repository lists and install the explicit GCC 12 toolchain and utilities
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
    gcc-12 \
    g++-12 \
    make \
    git \
    gdb \
    valgrind \
    sudo \
    && echo "developer ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
    && rm -rf /var/lib/apt/lists/*

# Link system compiler targets explicitly to the version 12 toolchain
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 \
    && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100

# Create a non-root development user matching standard Linux host UID 1000
RUN useradd -m -u 1000 -s /bin/bash developer

# Establish the persistent volume target folder 
WORKDIR /workspace
RUN chown developer:developer /workspace

# Relinquish root execution and switch permanently to the non-root profile
USER developer

# Set the default shell behavior
CMD ["/bin/bash"]

Okay so let us build that container. Be sure you are in the same directory that the Containerfile is in.
podman build -t mint21-gcc12-env .
Now when we run the container we need to attach (bind mount) the WORKDIR to our book source directory.
podman run -it --name mint21-book-dev \
  -v /path/to/your/local/book-code:/workspace:Z \
  mint21-gcc12-env

This will setup a bind mount to our book source to the WORKDIR in the container. Be sure to edit this line to replace /path/to/your/local/book-code with the path to the directory that you cloned the repository to. The :Z in the bind mount line is used by SELinux, if your system does not use SELinux or you do not have it in enforcing mode then you can skip that attribute.

We now have a fully provisioned OCI container that can be used with either podman or docker to provide the tool chain our book uses. This will allow us to focus on the content of the book rather than adapting code examples to our tool chain. That is a project we can work on after the concepts in the book are properly understood. If you would like to learn more about building your own containers for your development needs then I highly recommend the book Podman for DevOps


Unus Nemo


Tips & Donations


#DevOPS #Containers #podman