grim/convey

Add a new subtask task

2020-03-02, Gary Kramlich
469b76e1bd24
Add a new subtask task
// Convey
// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package aws
import (
"github.com/kballard/go-shellquote"
log "github.com/sirupsen/logrus"
"hg.sr.ht/~grim/convey/docker"
"hg.sr.ht/~grim/convey/environment"
"hg.sr.ht/~grim/convey/exec"
"hg.sr.ht/~grim/convey/runtime"
"hg.sr.ht/~grim/convey/tasks"
)
// ECRGetLogin represents an `aws ecr get-login` command.
type ECRGetLogin struct {
Region string `yaml:"region"`
}
// Execute runs the `aws ecr get-login` command and calls docker login with the
// results.
func (ecr *ECRGetLogin) Execute(name string, logger *log.Entry, env *environment.Environment, rt *runtime.Runtime) error {
fullEnv := env.Copy().Merge(rt.Environment)
cmd := exec.NewGenerator("aws", "ecr", "get-login")
region := fullEnv.Map(ecr.Region)
if region != "" {
cmd.Append("--region", region)
}
stdout, stderr, err := exec.RunOutput(name, cmd.Command(), rt.State.PlanTimeout)
if err != nil {
logger.Warnf("error: %s", stderr)
return err
}
argv, err := shellquote.Split(stdout)
if err != nil {
return err
}
task, err := docker.ParseCommand(argv)
if err != nil {
return err
}
return task.Execute(name, logger, env, rt)
}
// New creates a aws/ecr-get-login task.
func (ecr *ECRGetLogin) New() tasks.Task {
return &ECRGetLogin{}
}
// Valid checks that the build task is valid.
func (ecr *ECRGetLogin) Valid() error {
return nil
}