1

I'm currently using the fabric8io - docker maven plugin to build container images.

I need to specify further container image labels - especially the opencontainer image labels documented here.

The label org.opencontainers.image.base.digest has a special meaning for me, because the image I build will be used as base image for further applications and I want to create a pedigree recursively for the complete container infrastructure.

Now the digest of the base container image is needed here. But I don't know how to query the digest in maven to specify it.

The plugin is currently configured as follows:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <configuration>
        <images>
            <image>
                <name>my/app</name>
                <build>
                    <dockerFile>${project.basedir}/Dockerfile</dockerFile>
                    <contextDir>${project.basedir}</contextDir>
                    <args>
                        <APP_NAME>app</APP_NAME>
                        <BASE_IMAGE_DIGEST>HOW TO DETERMINE?</BASE_IMAGE_DIGEST>
                        <BASE_IMAGE_NAME>docker.io/library/rockylinux:8.6</BASE_IMAGE_NAME>
                        <BUILD_DATE>${docker.app.image.created}</BUILD_DATE>
                        <GIT_TAG>${docker.app.image.version}</GIT_TAG>
                        <PROJECT_DOC>${docker.app.image.scm.url}#README</PROJECT_DOC>
                        <PROJECT_SCM>${docker.app.image.scm.url}.git</PROJECT_SCM>
                        <PROJECT_URL>${docker.app.image.scm.url}</PROJECT_URL>
                    </args>
                </build>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <id>build</id>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
        <execution>
            <id>push</id>
            <phase>deploy</phase>
            <goals>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The Dockerfile:

ARG BASE_IMAGE_NAME

FROM ${BASE_IMAGE_NAME}

ARG APP_NAME
ARG BASE_IMAGE_DIGEST
ARG BASE_IMAGE_NAME
ARG BUILD_DATE
ARG GIT_TAG
ARG PROJECT_DOC
ARG PROJECT_SCM
ARG PROJECT_URL

# Open specifications from the Open Container Initative (OCI)
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.base.name=${BASE_IMAGE_NAME} \
      org.opencontainers.image.base.ref=${BASE_IMAGE_DIGEST} \
      org.opencontainers.image.created=${BUILD_DATE} \
      org.opencontainers.image.description="My App" \
      org.opencontainers.image.documentation=${PROJECT_DOC} \
      org.opencontainers.image.source=${PROJECT_SCM} \
      org.opencontainers.image.title="My App Base image" \
      org.opencontainers.image.url=${PROJECT_URL} \
      org.opencontainers.image.version=${GIT_TAG}

Volker

Volker Raschek
  • 545
  • 1
  • 6
  • 21

0 Answers0