grim/convey

Parents 0b79cbad2618
Children 86d5adfafe0d
Add new task aws/ecr-login for logging into AWS ECR. Fixed #161
--- a/ChangeLog Tue Feb 13 22:42:18 2018 -0600
+++ b/ChangeLog Tue Feb 13 22:42:39 2018 -0600
@@ -14,6 +14,7 @@
command. Fixed #162
* Add copies of all VCS environment variables without their prefix as well as
a VCS environment variable. Fixed #164
+ * Added a new aws/ecr-login task for logging into AWS ECR. Fixed #161
0.13.1: 20180114
* Write warning, error, and fatal log messages to stderr. Fixed #156
--- a/REFERENCE.md Tue Feb 13 22:42:18 2018 -0600
+++ b/REFERENCE.md Tue Feb 13 22:42:39 2018 -0600
@@ -135,6 +135,24 @@
----
+### aws/ecr-login
+
+The `aws/ecr-login` task will log into AWS Elastic Container Registry. It
+depends on the AWS cli package being installed and configured to work.
+
+#### Attributes
+
+| Name | Required | Default | Description |
+| ------ | -------- | ------- | ----------- |
+| region | | | The AWS region to used. |
+
+#### Example
+
+ login:
+ type: aws/ecr-login
+
+----
+
### convey/clean task
A clean task will remove files from the host relative and limited to the working directory of convey.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aws/aws.go Tue Feb 13 22:42:39 2018 -0600
@@ -0,0 +1,29 @@
+// 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 intrinsic contains the intrinsic commands
+package aws
+
+import (
+ "bitbucket.org/rw_grim/convey/tasks"
+)
+
+var (
+ // Tasks is a map of intrinsic tasks.
+ Tasks = map[string]tasks.Task{
+ "ecr-login": &ECRGetLogin{},
+ }
+)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aws/data/ecr-test.yml Tue Feb 13 22:42:39 2018 -0600
@@ -0,0 +1,21 @@
+---
+environment:
+ - REGION=us-east-2
+ - ACCOUNT_ID=1234567890
+tasks:
+ ecr-login:
+ type: aws/ecr-login
+ tag:
+ type: docker/tag
+ source: alpine:edge
+ destination: ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/alpine:edge
+ push:
+ type: docker/push
+ image: ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/alpine:edge
+plans:
+ default:
+ stages:
+ - tasks:
+ - ecr-login
+ - tag
+ - push
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aws/ecr-get-login.go Tue Feb 13 22:42:39 2018 -0600
@@ -0,0 +1,75 @@
+// 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/aphistic/gomol"
+ "github.com/kballard/go-shellquote"
+
+ "bitbucket.org/rw_grim/convey/command"
+ "bitbucket.org/rw_grim/convey/docker"
+ "bitbucket.org/rw_grim/convey/environment"
+ "bitbucket.org/rw_grim/convey/state"
+ "bitbucket.org/rw_grim/convey/tasks"
+)
+
+type ECRGetLogin struct {
+ Region string `yaml:"region"`
+}
+
+// Executes the `aws ecr get-login` command and calls docker login with the
+// results
+func (ecr *ECRGetLogin) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
+ cmd := command.NewGenerator("aws", "ecr", "get-login")
+ if ecr.Region != "" {
+ region, err := environment.Mapper(ecr.Region, env)
+ if err != nil {
+ return err
+ }
+
+ cmd.Append("--region", region)
+ }
+
+ stdout, stderr, err := command.RunOutput(name, cmd.Command(), st.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, st)
+}
+
+// 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
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aws/errors.go Tue Feb 13 22:42:39 2018 -0600
@@ -0,0 +1,25 @@
+// 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 (
+ "errors"
+)
+
+var (
+ errNoRegion = errors.New("no region specified")
+)
--- a/config/tasks.go Tue Feb 13 22:42:18 2018 -0600
+++ b/config/tasks.go Tue Feb 13 22:42:39 2018 -0600
@@ -17,6 +17,7 @@
package config
import (
+ "bitbucket.org/rw_grim/convey/aws"
"bitbucket.org/rw_grim/convey/docker"
"bitbucket.org/rw_grim/convey/intrinsic"
"bitbucket.org/rw_grim/convey/tasks"
@@ -36,6 +37,11 @@
TasksMap["docker/"+taskName] = task
}
+ // add the aws tasks
+ for taskName, task := range aws.Tasks {
+ TasksMap["aws/"+taskName] = task
+ }
+
// add the intrinsic convey tasks
for taskName, task := range intrinsic.Tasks {
TasksMap["convey/"+taskName] = task