Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ If you are using Copilot/AI to modify this repo, follow the **How Copilot Should
- Keep the multi-stage + flattened final stage pattern (`COPY --from=builder / /`).
- UBI-repo (microdnf) installs belong in the `platform` stage of the deps Dockerfiles; non-UBI content (libnsl, MarkLogic rpm, tini, scripts) goes after it. The `marklogic-platform-<type>` image must stay an exact layer prefix of the server image (used for the Black Duck NOTICE scan), and `sudo` must never be installed in rootless images.
- Keep ownership/permissions correct for rootless (`marklogic_user:users`, UID 1000).
- Home-directory init files (for example `.gdbinit`) must match other home files: mode 0740 or less permissive (CIS `file_permission_user_init_files`).
- If you add/remove files, update `test/structure-test.yaml` accordingly.
- **External RPM pinning**: When pinning external RPMs (e.g., libnsl from AlmaLinux), avoid broad `microdnf -y update` in the same RUN layer, as it can advance glibc and break version compatibility. Use targeted upgrades instead (e.g., `microdnf -y upgrade tzdata`). Test both the dependency image build AND downstream MarkLogic RPM installation.
- **Env vars / secrets**
Expand Down Expand Up @@ -146,7 +147,7 @@ Container Structure Tests validate:
- Command availability
- Environment variables

Template: `test/structure-test.yaml` (placeholders replaced during `make structure-test`)
Template: `test/structure-test.yaml` (placeholders replaced during `make structure-test`). Rootless-only checks, such as the `.gdbinit` mode, live in `test/structure-test-rootless.yaml` and are added for rootless image types.

## Clustering Patterns

Expand Down
99 changes: 39 additions & 60 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,27 @@ void scapScan() {
"""
}

/**
* Makes this build's server and platform images available in the local Docker daemon.
* A same-tag image can be left on an agent by an earlier build, so a local tag is reused only
* when its image ID matches the ID recorded at build time. Otherwise the archive is unstashed
* and loaded, which replaces the stale tag.
*/
void ensureBuiltImagesLoaded() {
unstash 'built-image-ids'
def idsMatch = sh(returnStatus: true, script: '''
while read -r tag id; do
[ "$(docker image inspect --format '{{.Id}}' "$tag" 2>/dev/null)" = "$id" ] || exit 1
done < built-image-ids.txt
''') == 0
if (idsMatch) {
echo 'Built images already present locally with matching IDs, skipping archive load'
} else {
unstash 'built-image-archive'
sh "docker image load -i ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}"
}
}

pipeline {
// No pipeline-wide agent: stages that need a different label (graviton) must not
// overlap with a persistently-held top-level agent, or two nodes of the same scarce
Expand Down Expand Up @@ -735,11 +756,21 @@ pipeline {
buildDockerImage()
script {
// Always save image for cases where agents might differ
def imageId = { String tag -> sh(script: "docker image inspect --format '{{.Id}}' ${tag}", returnStdout: true).trim() }
def serverIdBefore = imageId(builtImage)
def platformIdBefore = imageId(platformBuiltImage)
sh """
echo "Saving ${builtImage} and ${platformBuiltImage} to ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}..."
docker image save ${builtImage} ${platformBuiltImage} -o ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}
ls -lh ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}
"""
// The tags must not have moved while the archive was written, or the recorded IDs would describe a different image.
if (imageId(builtImage) != serverIdBefore || imageId(platformBuiltImage) != platformIdBefore) {
error "Image tags changed while saving ${GRAVITON3_IMAGE_ARCHIVE}; rerun the build."
}
// Record each image's ID so later stages can confirm a same-tag image on their agent is this build's.
writeFile file: 'built-image-ids.txt', text: "${builtImage} ${serverIdBefore}\n${platformBuiltImage} ${platformIdBefore}\n"
stash name: 'built-image-ids', includes: 'built-image-ids.txt', allowEmpty: false
stash name: 'built-image-archive', includes: "${GRAVITON3_IMAGE_ARCHIVE}", allowEmpty: false
}
}
Expand Down Expand Up @@ -781,19 +812,7 @@ pipeline {
expression { return params.SCAP_SCAN }
}
steps {
script {
unstash 'built-image-archive'
// Load image from tar if not already available (applies to all build types)
def imageSource = "${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}"
sh """
if ! docker image inspect ${builtImage} &>/dev/null; then
echo "Loading image from ${imageSource} for SCAP scan..."
docker image load -i ${imageSource}
else
echo "Image ${builtImage} already available locally"
fi
"""
}
ensureBuiltImagesLoaded()
scapScan()
stash name: 'scap-results', includes: 'scap/**', allowEmpty: true
}
Expand All @@ -807,18 +826,8 @@ pipeline {
expression { return isArmImage() && params.GRAVITON3_AGENT }
}
steps {
script {
unstash 'built-image-archive'
sh """
if ! docker image inspect ${builtImage} &>/dev/null; then
echo "Loading image from ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}..."
docker image load -i ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}
else
echo "Image ${builtImage} already loaded (likely by SCAP-Scan stage)"
fi
docker images | head -5
"""
}
ensureBuiltImagesLoaded()
sh 'docker images | head -5'
}
}

Expand All @@ -834,19 +843,7 @@ pipeline {
expression { return params.TEST_STRUCTURE }
}
steps {
script {
unstash 'built-image-archive'
// Load image from tar if not already available (applies to all build types)
def imageSource = "${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}"
sh """
if ! docker image inspect ${builtImage} &>/dev/null; then
echo "Loading image from ${imageSource} for Structure-Tests..."
docker image load -i ${imageSource}
else
echo "Image ${builtImage} already available locally"
fi
"""
}
ensureBuiltImagesLoaded()
structureTests()
stash name: 'structure-test-results', includes: 'container-structure-test.xml', allowEmpty: true
}
Expand All @@ -864,18 +861,8 @@ pipeline {
expression { return params.DOCKER_TESTS }
}
steps {
ensureBuiltImagesLoaded()
script {
unstash 'built-image-archive'
// Load image from tar if not already available (applies to all build types)
def imageSource = "${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}"
sh """
if ! docker image inspect ${builtImage} &>/dev/null; then
echo "Loading image from ${imageSource} for Docker-Run-Tests..."
docker image load -i ${imageSource}
else
echo "Image ${builtImage} already available locally"
fi
"""
unstash 'upgrade-image-archive'
// Always load from the archive: upgradeDockerImage defaults to the
// mutable 'latest-<majorVersion>' tag, which a shared agent may already
Expand Down Expand Up @@ -908,18 +895,10 @@ pipeline {
}
steps {
script {
unstash 'built-image-archive'
// Load image from tar if not already available (applies to all build types)
// Node's Docker daemon is shared with other concurrent builds, so only ever
// trust the exact, fully-qualified tag - never a loose repo/type match, which
// could resolve to a different build's image (e.g. a different marklogicVersion).
ensureBuiltImagesLoaded()
// Images are matched by ID, so this build's images are published even when an earlier
// build left the same tag on this node. The exact-tag inspects below confirm both are present.
sh """
if ! docker image inspect ${builtImage} &>/dev/null || ! docker image inspect ${platformBuiltImage} &>/dev/null; then
echo "Image not found locally, loading from ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}..."
docker image load -i ${WORKSPACE}/${GRAVITON3_IMAGE_ARCHIVE}
else
echo "Images ${builtImage} and ${platformBuiltImage} already available locally"
fi
docker image inspect ${builtImage} >/dev/null
docker image inspect ${platformBuiltImage} >/dev/null
"""
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ endif
sed -i -e 's^ML_VERSION_PLACEHOLDER^${marklogicVersion}^g' ./test/structure-test.yaml
sed -i -e 's^ML_DOCKER_VERSION_PLACEHOLDER^${dockerVersion}^g' ./test/structure-test.yaml
sed -i -e 's^BRANCH_PLACEHOLDER^${build_branch}^g' ./test/structure-test.yaml
container-structure-test test --config ./test/structure-test.yaml --image ${current_image} \
container-structure-test test --config ./test/structure-test.yaml $(if $(findstring rootless,$(docker_image_type)),--config ./test/structure-test-rootless.yaml) --image ${current_image} \
$(if $(Jenkins), --output junit | tee container-structure-test.xml,)

#***************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion dockerFiles/marklogic-server-ubi-rootless:base
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ RUN if [ -s /tmp/converters.rpm ]; then chown ${ML_USER}:users /tmp/converters.r
###############################################################
# Configure GDB for debugging and set capabilities for non-root usage
###############################################################
# Same mode as other home-directory files (chmod 740 in the builder stage); CIS rule file_permission_user_init_files requires 0740 or less permissive.
RUN setcap cap_sys_ptrace+ep "$(readlink -f /usr/bin/gdb)" \
&& echo "set auto-load safe-path /" > /home/${ML_USER}/.gdbinit \
&& chown ${ML_USER}:users /home/${ML_USER}/.gdbinit \
&& chmod 644 /home/${ML_USER}/.gdbinit
&& chmod 740 /home/${ML_USER}/.gdbinit

###############################################################
# Remove optional packages that have known vulnerabilities
Expand Down
10 changes: 10 additions & 0 deletions test/structure-test-rootless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schemaVersion: "2.0.0"

# Rootless-only checks. make structure-test adds this file for rootless image types.
fileExistenceTests:
- name: 'gdbinit mode matches other home-directory files'
path: '/home/marklogic_user/.gdbinit'
shouldExist: true
permissions: '-rwxr-----'
uid: 1000
gid: 100
Loading