github.com/osievert/jfrog-cli-core@v1.2.7/artifactory/commands/container/pull.go (about) 1 package container 2 3 import ( 4 "github.com/jfrog/jfrog-cli-core/artifactory/utils" 5 "github.com/jfrog/jfrog-cli-core/artifactory/utils/container" 6 "github.com/jfrog/jfrog-cli-core/utils/config" 7 "github.com/jfrog/jfrog-client-go/utils/errorutils" 8 ) 9 10 type PullCommand struct { 11 ContainerManagerCommand 12 containerManagerType container.ContainerManagerType 13 } 14 15 func NewPullCommand(containerManagerType container.ContainerManagerType) *PullCommand { 16 return &PullCommand{containerManagerType: containerManagerType} 17 } 18 19 // Pull image and create build info if needed 20 func (pc *PullCommand) Run() error { 21 if pc.containerManagerType == container.DockerClient { 22 err := container.ValidateClientApiVersion() 23 if err != nil { 24 return err 25 } 26 } 27 rtDetails, err := pc.RtDetails() 28 if errorutils.CheckError(err) != nil { 29 return err 30 } 31 // Perform login 32 if err := pc.PerformLogin(rtDetails, pc.containerManagerType); err != nil { 33 return err 34 } 35 // Perform pull. 36 cm := container.NewManager(pc.containerManagerType) 37 image := container.NewImage(pc.imageTag) 38 err = cm.Pull(image) 39 if err != nil { 40 return err 41 } 42 buildName := pc.BuildConfiguration().BuildName 43 buildNumber := pc.BuildConfiguration().BuildNumber 44 // Return if no build name and number was provided 45 if buildName == "" || buildNumber == "" { 46 return nil 47 } 48 if err := utils.SaveBuildGeneralDetails(buildName, buildNumber); err != nil { 49 return err 50 } 51 serviceManager, err := utils.CreateServiceManager(rtDetails, false) 52 if err != nil { 53 return err 54 } 55 builder, err := container.NewBuildInfoBuilder(image, pc.Repo(), buildName, buildNumber, serviceManager, container.Pull, cm) 56 if err != nil { 57 return err 58 } 59 buildInfo, err := builder.Build(pc.BuildConfiguration().Module) 60 if err != nil { 61 return err 62 } 63 return utils.SaveBuildInfo(buildName, buildNumber, buildInfo) 64 } 65 66 func (pc *PullCommand) CommandName() string { 67 return "rt_docker_pull" 68 } 69 70 func (pc *PullCommand) RtDetails() (*config.ArtifactoryDetails, error) { 71 return pc.rtDetails, nil 72 }