Next: , Previous: , Up: Stages   [Contents]


5.2.4 Package

At this point, we have the software tested and analyzed, so it has a minimum required quality to be packed in an OCI (Open Container Initiative) container image. To do so, there are several options available, from using Docker or Podman, to using something more advanced and specialized such as Buildah, which is an open-source command-line (CLI) tool that handles building container images without the need of a full container runtime or any daemon installed nor any socket listening, so being perfect for continuous integration and delivery (CI). Also, it is able to create container images without an specific Containerfile or Dockerfile; instead, we can use an scripted approach to make this process as fancy and complicated as we possibly want.

This is a basic standard Containerfile (or Dockerfile) where there are written all steps needed to be performed in order for the image to be built; in this case, we base it off the latest version of Alpine Linux, install Git, print its version, and also print an arbitrary message.

FROM alpine:latest
RUN apk update && apk add git
RUN git --version
RUN echo "Hello world from the container!"
RUN uname -m

We build the image performing buildah build -t example:1.0-amd64 . (it defaults building for the host’s architecture; if wanted to also build it for a different architecture, it can be specified with the ‘--arch’ argument [it requires setting qemu-user-static emulation layers as binfmt interpreters to enable an execution of different multi-architecture containers using QEMU and binfmt_misc], e.g. buildah build --arch arm64 -t example:1.0-arm64 .). Also, this can be compacted and coded using shell scripting, as follows.

This is a shell script that does the same as the previous example, but using a different approach. Also, we enable the option to pass both the version and the architecture through the script’s arguments, instead of editing the contents of the file.

#!/bin/sh

APP="example"
VERSION="1.0"
ARCH="amd64"

if [ ! -z "$1" ]; then
  VERSION="$1"
fi
if [ ! -z "$2" ]; then
  ARCH="$2"
fi

container=$(buildah from --arch "$ARCH" alpine:latest)

buildah run $container /bin/sh -c \
  "apk update && apk add git"
buildah run $container /bin/sh -c \
  "git --version"
buildah run $container /bin/sh -c \
  "echo 'Hello world from the container!'"
buildah run $container /bin/sh -c \
  "uname -m"

buildah commit --squash $container "$APP:$VERSION-$ARCH"
buildah rm "$container" && buildah rmi --prune && unset $container

As seen, this is a much powerful approach, with the ability to be integrated in a build system, such as GNU Make.


Next: Storage, Previous: Analysis, Up: Stages   [Contents]