diff --git a/README.md b/README.md index ec6eb5e9..2e9c2485 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ pipeline { } ``` +## Disable fingerprinting + +Recording fingerprints are great, but for large Jenkins instances it can become a scalability and performance issue. +It is possible to disable recording of fingerprints by setting the system property +org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints.DISABLE equal to true. This will +not remove old fingerprints but will prevent new fingerprints from being recorded. + ## License [MIT License](http://opensource.org/licenses/MIT) diff --git a/src/main/java/org/jenkinsci/plugins/docker/commons/fingerprint/DockerFingerprints.java b/src/main/java/org/jenkinsci/plugins/docker/commons/fingerprint/DockerFingerprints.java index 442cf07b..48d04d5a 100644 --- a/src/main/java/org/jenkinsci/plugins/docker/commons/fingerprint/DockerFingerprints.java +++ b/src/main/java/org/jenkinsci/plugins/docker/commons/fingerprint/DockerFingerprints.java @@ -23,6 +23,7 @@ */ package org.jenkinsci.plugins.docker.commons.fingerprint; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.BulkChange; import hudson.model.Fingerprint; import hudson.model.Run; @@ -39,6 +40,8 @@ import javax.annotation.Nonnull; import jenkins.model.FingerprintFacet; import org.apache.commons.lang.StringUtils; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; /** * Entry point into fingerprint related functionalities in Docker. @@ -47,7 +50,15 @@ public class DockerFingerprints { private static final Logger LOGGER = Logger.getLogger(DockerFingerprints.class.getName()); - + + /** + * System property, which, when set to true (default false), disables + * recording of new fingerprints. + */ + @SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="mutable for scripts") + @Restricted(NoExternalUse.class) + public static boolean DISABLE = Boolean.getBoolean(DockerFingerprints.class.getName() + ".DISABLE"); + private DockerFingerprints() {} // no instantiation /** @@ -221,6 +232,10 @@ private DockerFingerprints() {} // no instantiation * Adds a new {@link ContainerRecord} for the specified image, creating necessary intermediate objects as it goes. */ public static void addRunFacet(@Nonnull ContainerRecord record, @Nonnull Run run) throws IOException { + if (DISABLE) { + LOGGER.info("Recording of fingerprints is disabled, no RUN fingerprint record will be made."); + return; + } String imageId = record.getImageId(); Fingerprint f = forImage(run, imageId); synchronized (f) { @@ -256,6 +271,10 @@ public static void addRunFacet(@Nonnull ContainerRecord record, @Nonnull Run run) throws IOException { + if (DISABLE) { + LOGGER.info("Recording of fingerprints is disabled, no FROM fingerprint record will be made."); + return; + } long timestamp = System.currentTimeMillis(); if (ancestorImageId != null) { Fingerprint f = forImage(run, ancestorImageId); @@ -311,4 +330,13 @@ public static void addFromFacet(@CheckForNull String ancestorImageId, @Nonnull S } } + /** + * Indicates whether recording of new fingerprints are disabled. + * + * @return true if fingerprint recording is disabled, otherwise false. + */ + public static boolean isFingerprintsDisabled() { + return DISABLE; + } + }