Skip to content

Commit

Permalink
Merge pull request #525 from hazelops/IZE-697-ize-push-app-explain
Browse files Browse the repository at this point in the history
IZE-697 added `explain` flag for `ize push`
  • Loading branch information
psihachina authored Nov 3, 2022
2 parents e5f3d47 + 80e3b23 commit d67a063
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"context"

"github.com/hazelops/ize/internal/config"
"github.com/hazelops/ize/internal/manager"
"github.com/hazelops/ize/internal/manager/alias"
Expand All @@ -16,6 +17,7 @@ type PushOptions struct {
Config *config.Project
AppName string
App interface{}
Explain bool
}

var pushLongDesc = templates.LongDesc(`
Expand Down Expand Up @@ -73,6 +75,8 @@ func NewCmdPush(project *config.Project) *cobra.Command {
},
}

cmd.Flags().BoolVar(&o.Explain, "explain", false, "bash alternative shown")

return cmd
}

Expand Down Expand Up @@ -119,5 +123,9 @@ func (o *PushOptions) Run() error {
}
}

if o.Explain {
return m.Explain()
}

return m.Push(ui)
}
28 changes: 27 additions & 1 deletion internal/manager/ecs/explain.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package ecs

import (
"text/template"

"github.com/hazelops/ize/internal/config"
)

func (e *Manager) Explain() error {
return nil
e.prepare()
return e.Project.Generate(pushEcsAppTmpl, template.FuncMap{
"app": func() config.Ecs {
return *e.App
},
})
}

var pushEcsAppTmpl = `
# Authenticate the Docker CLI to registry
aws ecr get-login-password --region {{.AwsRegion}} | docker login --username AWS --password-stdin {{.DockerRegistry}}
# Create a repository
aws ecr describe-repositories --repository-names {{.Namespace}}-{{app.Name}} || \
aws ecr create-repository \
--repository-name {{.Namespace}}-{{app.Name}} \
--region {{.AwsRegion}}
# Push an image to Amazon ECR
docker push {{.DockerRegistry}}/{{.Namespace}}-{{app.Name}}:{{.Tag}} && \
docker push {{.DockerRegistry}}/{{.Namespace}}-{{app.Name}}:{{.Env}}-latest
`

0 comments on commit d67a063

Please sign in to comment.