Class ReplaceAddWithCopy

java.lang.Object
org.openrewrite.Recipe
org.openrewrite.docker.ReplaceAddWithCopy
All Implemented Interfaces:
Cloneable

public class ReplaceAddWithCopy extends org.openrewrite.Recipe
Replaces ADD instructions with COPY instructions where appropriate.

ADD has two features that COPY does not:

  1. It can fetch URLs
  2. It automatically extracts tar archives

Using COPY instead of ADD is a best practice (CIS Docker Benchmark 4.9) because:

  • COPY is more transparent - it only copies files
  • ADD's auto-extraction can be unexpected and create security issues
  • For URL fetching, using RUN with curl/wget is preferred for better caching
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.openrewrite.Recipe

    org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe
  • Field Summary

    Fields inherited from class org.openrewrite.Recipe

    contributors, examples, PANIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext>
     

    Methods inherited from class org.openrewrite.Recipe

    addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReplaceAddWithCopy

      public ReplaceAddWithCopy()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in class org.openrewrite.Recipe
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe