Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdep commit option #777

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cuvva/cuvva-public-go

go 1.18
go 1.21

require (
github.com/Masterminds/squirrel v1.5.2
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ github.com/hashicorp/go-tfe v0.24.0/go.mod h1:gyXLXbpBVxA2F/6opah8XBsOkZJxHYQmgh
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
Expand Down
19 changes: 11 additions & 8 deletions tools/cdep/app/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
return cher.New("invalid_operation", nil)
}

log.Info("getting latest commit hash")
if req.Commit == "" {
log.Info("getting latest commit hash")
latestHash, err := git.GetLatestCommitHash(ctx, req.Branch)
if err != nil {
return fmt.Errorf("failed to get commit hash: %w", err)
}

latestHash, err := git.GetLatestCommitHash(ctx, req.Branch)
if err != nil {
return fmt.Errorf("failed to get commit hash: %w", err)
req.Commit = latestHash
}

repoPath, err := paths.GetConfigRepo()
Expand Down Expand Up @@ -121,13 +124,13 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
}
}

err := checkECRImage(p, latestHash, req.Branch)
err := checkECRImage(p, req.Commit, req.Branch)
if err != nil {
e := errors.Wrap(err, "ecr")
log.Warn(e)
}

changed, err := a.AddToConfig(p, req.Branch, latestHash)
changed, err := a.AddToConfig(p, req.Branch, req.Commit)
if err != nil {
return fmt.Errorf("add to config: %w", err)
}
Expand All @@ -146,7 +149,7 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
log.Warn(err)
}

changed, err := a.AddToConfig(p, req.Branch, latestHash)
changed, err := a.AddToConfig(p, req.Branch, req.Commit)
if err != nil {
return err
}
Expand All @@ -164,7 +167,7 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
log.Warn(err)
}

changed, err := a.AddToConfig(p, req.Branch, latestHash)
changed, err := a.AddToConfig(p, req.Branch, req.Commit)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions tools/cdep/app/update_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ import (
func (a App) UpdateDefault(ctx context.Context, req *parsers.Params, overruleChecks []string) error {
log.Info("getting latest commit hash")

latestHash, err := git.GetLatestCommitHash(ctx, req.Branch)
if err != nil {
return err
if req.Commit == "" {
latestHash, err := git.GetLatestCommitHash(ctx, req.Branch)
if err != nil {
return err
}

req.Commit = latestHash
}

repoPath, err := paths.GetConfigRepo()
Expand Down Expand Up @@ -115,7 +119,7 @@ func (a App) UpdateDefault(ctx context.Context, req *parsers.Params, overruleChe
var changed bool

if strings.HasSuffix(fullPath, "_base.json") || strings.HasSuffix(fullPath, ".yaml") {
changed, err = a.AddToConfig(fullPath, req.Branch, latestHash)
changed, err = a.AddToConfig(fullPath, req.Branch, req.Commit)
if err != nil {
return err
}
Expand Down
17 changes: 15 additions & 2 deletions tools/cdep/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

func init() {
UpdateCmd.Flags().StringP("branch", "b", cdep.DefaultBranch, "Branch to deploy")
UpdateCmd.Flags().StringP("commit", "c", "", "Commit to deploy instead of the latest")
UpdateCmd.Flags().BoolP("prod", "", false, "Work on prod")
UpdateCmd.Flags().BoolP("dry-run", "", false, "Dry run only?")
UpdateCmd.Flags().StringSliceP("overrule-checks", "", []string{}, "Overrule checks the tool does")
Expand All @@ -44,9 +45,12 @@ var UpdateCmd = &cobra.Command{
Long: "Please read the README.md file",
Example: strings.Join([]string{
"update service avocado sms email -b extra-logging",
"update lambda basil ltm-proxy",
"update service avocado sms email -b extra-logging -c f1ec178befe6ed26ce9cec0aa419c763c203bc92",
"update service all sms email -c 1ed6fd7450031a5240584f8bbe8ec527f9020b5b",
"update service prod email --prod",
"update lambda basil ltm-proxy",
"update cloudfront prod website --prod",
"update terra avocado aws-env",
}, "\n"),
Aliases: []string{"u"},
Args: updateArgs,
Expand All @@ -73,11 +77,20 @@ var UpdateCmd = &cobra.Command{
return err
}

params, err := parsers.Parse(args, branch, useProd, message)
commit, err := cmd.Flags().GetString("commit")
if err != nil {
return err
}

params, err := parsers.Parse(args, useProd)
if err != nil {
return err
}

params.Branch = branch
params.Message = message
params.Commit = commit

awsSession, err := session.NewSessionWithOptions(session.Options{
Profile: "root",
Config: aws.Config{
Expand Down
12 changes: 11 additions & 1 deletion tools/cdep/commands/update_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var UpdateDefaultCmd = &cobra.Command{
Long: "Please read the README.md file",
Example: strings.Join([]string{
"update-default services avocado",
"update-default services avocado -c f1ec178befe6ed26ce9cec0aa419c763c203bc92",
"update-default lambda all",
}, "\n"),
Args: updateDefaultArgs,
Expand All @@ -63,11 +64,20 @@ var UpdateDefaultCmd = &cobra.Command{
return err
}

params, err := parsers.Parse(args, cdep.DefaultBranch, useProd, message)
commit, err := cmd.Flags().GetString("commit")
if err != nil {
return err
}

params, err := parsers.Parse(args, useProd)
if err != nil {
return err
}

params.Branch = cdep.DefaultBranch
params.Message = message
params.Commit = commit

awsSession, err := session.NewSessionWithOptions(session.Options{
Profile: "root",
Config: aws.Config{
Expand Down
4 changes: 1 addition & 3 deletions tools/cdep/parsers/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var exceptions = map[string]struct{}{
"web-mid": {},
}

func Parse(args []string, branch string, prodSys bool, message string) (*Params, error) {
func Parse(args []string, prodSys bool) (*Params, error) {
if len(args) < 2 {
return nil, errors.New("missing arguments")
}
Expand Down Expand Up @@ -65,8 +65,6 @@ func Parse(args []string, branch string, prodSys bool, message string) (*Params,
Type: t,
System: system,
Environment: args[1],
Branch: branch,
Items: itemSet,
Message: message,
}, nil
}
5 changes: 5 additions & 0 deletions tools/cdep/parsers/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Params struct {
Type string
Environment string
Branch string
Commit string
System string
Items []string
Message string
Expand All @@ -31,6 +32,10 @@ func (p Params) String(command string) (out string) {
out = fmt.Sprintf("%s -b %s", out, p.Branch)
}

if p.Commit != "" {
out = fmt.Sprintf("%s -c %s", out, p.Commit)
}

if p.System == "prod" {
out = fmt.Sprintf("%s --prod", out)
}
Expand Down
Loading