github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/exec/artifact_output_step.go (about) 1 package exec 2 3 import ( 4 "context" 5 "fmt" 6 7 "code.cloudfoundry.org/lager" 8 "code.cloudfoundry.org/lager/lagerctx" 9 "github.com/pf-qiu/concourse/v6/atc" 10 "github.com/pf-qiu/concourse/v6/atc/db" 11 "github.com/pf-qiu/concourse/v6/atc/exec/build" 12 "github.com/pf-qiu/concourse/v6/atc/worker" 13 ) 14 15 type ArtifactNotFoundError struct { 16 ArtifactName string 17 } 18 19 func (e ArtifactNotFoundError) Error() string { 20 return fmt.Sprintf("artifact '%s' not found", e.ArtifactName) 21 } 22 23 type ArtifactOutputStep struct { 24 plan atc.Plan 25 build db.Build 26 workerClient worker.Client 27 } 28 29 func NewArtifactOutputStep(plan atc.Plan, build db.Build, workerClient worker.Client) Step { 30 return &ArtifactOutputStep{ 31 plan: plan, 32 build: build, 33 workerClient: workerClient, 34 } 35 } 36 37 func (step *ArtifactOutputStep) Run(ctx context.Context, state RunState) (bool, error) { 38 logger := lagerctx.FromContext(ctx).WithData(lager.Data{ 39 "plan-id": step.plan.ID, 40 }) 41 42 outputName := step.plan.ArtifactOutput.Name 43 44 buildArtifact, found := state.ArtifactRepository().ArtifactFor(build.ArtifactName(outputName)) 45 if !found { 46 return false, ArtifactNotFoundError{outputName} 47 } 48 49 // TODO (Runtime/#3607): step shouldn't know about volumes, 50 // use the artifactRepo and artifact interface 51 volume, found, err := step.workerClient.FindVolume(logger, step.build.TeamID(), buildArtifact.ID()) 52 if err != nil { 53 return false, err 54 } 55 56 if !found { 57 return false, ArtifactNotFoundError{outputName} 58 } 59 60 dbWorkerArtifact, err := volume.InitializeArtifact(outputName, step.build.ID()) 61 if err != nil { 62 return false, err 63 } 64 65 logger.Info("initialize-artifact-from-source", lager.Data{ 66 "handle": volume.Handle(), 67 "artifact_id": dbWorkerArtifact.ID(), 68 }) 69 70 return true, nil 71 }