github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/containerupdate/tar.go (about)

     1  package containerupdate
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/tilt-dev/tilt/pkg/model"
     7  )
     8  
     9  // TarExitCodePermissionDenied is returned by `tar` if it does not have
    10  // sufficient permissions to write the extracted files.
    11  const TarExitCodePermissionDenied = 2
    12  
    13  func tarCmd() model.Cmd {
    14  	return model.Cmd{
    15  		Argv: []string{"tar", "-C", "/", "-x", "-f", "-"},
    16  	}
    17  }
    18  
    19  func permissionDeniedErr(err error) error {
    20  	return fmt.Errorf("%v\n"+
    21  		"This usually means the container filesystem denied access. Please check:\n"+
    22  		"  1) That the container image has writable files\n"+
    23  		"  2) That the container image default user has write access to the files\n"+
    24  		"  3) That the Pod spec doesn't have a SecurityContext that would block writes",
    25  		err)
    26  }
    27  
    28  func cannotExecErr(err error) error {
    29  	return fmt.Errorf("%v\n"+
    30  		"This usually means that Tilt could not exec `tar`.\n"+
    31  		"Please check that the container image includes `tar` in $PATH.\n"+
    32  		"Some minimal images, such as those that are built `FROM scratch`, "+
    33  		"will not work with Live Update by default.\n"+
    34  		"See https://github.com/tilt-dev/tilt/issues/4303 for details.",
    35  		err)
    36  }
    37  
    38  func wrapTarExecErr(err error, cmd model.Cmd, exitCode int) error {
    39  	switch exitCode {
    40  	case TarExitCodePermissionDenied:
    41  		return permissionDeniedErr(err)
    42  	case GenericExitCodeCannotExec:
    43  		// docker uses this to mean not found, so it's treated the same
    44  		fallthrough
    45  	case GenericExitCodeNotFound:
    46  		// in a `run()` step or other user-defined command, this typically
    47  		// is handled by build.RunStepFailure with a fairly generic message
    48  		// about not found in PATH, but here we provide Live Update specific
    49  		// guidance, since the user will need to adjust their image
    50  		return cannotExecErr(err)
    51  	default:
    52  		return NewExecError(cmd, exitCode)
    53  	}
    54  }