func (res *smResource) Provision(l logger.Logger) (err error) { l = l.Tag(res.ID) for _, pkg := range res.Packages { if err := pkg.Provision(l, res.client); err != nil { return err } } return nil }
func (res *smResource) Prepare(l logger.Logger) error { l = l.Tag(res.ID) if err := res.initializeClient(); err != nil { return err } for _, pkg := range res.Packages { if err := pkg.Prepare(res.client, res.Attributes); err != nil { return err } } return nil }
func newLoggedSession(l logger.Logger, sess Session) (Session, error) { s := &loggedSession{Session: sess, wg: new(sync.WaitGroup)} stdout, err := s.Session.StdoutPipe() if err != nil { return nil, errors.Wrap(err, "failed to build stdout pipe") } stderr, err := s.Session.StderrPipe() if err != nil { return nil, errors.Wrap(err, "failed to build stderr pipe") } s.wg.Add(2) go s.readStream(l.Tag("stdout"), stdout) go s.readStream(l.Tag("stderr"), stderr) return s, nil }
func (pkg *smPackage) Provision(l logger.Logger, client connection.Client) (err error) { l = l.Tag(pkg.ID) oldState := pkg.state pkg.state = make([]string, len(pkg.Scripts)) allCached := true defer func() { if allCached { return } e := pkg.writeTargetState(client) if err == nil { err = e } }() for i, s := range pkg.Scripts { hash := s.Hash() if allCached && i < len(oldState) && oldState[i][1:] == hash { l.Printf("step %d cached", i) pkg.state[i] = "." + hash continue } allCached = false if err = s.Exec(l, client); err != nil { l.Printf("failed in %s", hash) pkg.state[i] = "-" + hash pkg.state = pkg.state[:i+1] return err } pkg.state[i] = "+" + hash } return nil }