Skip to content

Commit

Permalink
Merge pull request #152 from fujiwara/alias-to-latest
Browse files Browse the repository at this point in the history
add --alias-to-latest option to deploy command.
  • Loading branch information
fujiwara authored Jul 9, 2021
2 parents fb9d8ae + 8052ad0 commit 2d801b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,24 @@ usage: lambroll deploy [<flags>]
deploy or create function

Flags:
--help Show context-sensitive help (also try --help-long
and --help-man).
--log-level=info log level (trace, debug, info, warn, error)
--function="function.json" Function file path
--profile="$AWS_PROFILE" AWS credential profile name
--region="$AWS_REGION" AWS region
--profile="" AWS credential profile name
--region="" AWS region
--tfstate="" URL to terraform.tfstate
--endpoint="" AWS API Lambda Endpoint
--envfile=ENVFILE ... environment files
--src="." function zip archive or src dir
--exclude-file=".lambdaignore"
--exclude-file=".lambdaignore"
exclude file
--dry-run dry run
--publish publish function
--alias="current" alias name for publish
--skip-archive skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition
--alias-to-latest set alias to unpublished $LATEST version
--skip-archive skip to create zip archive. requires Code.S3Bucket
and Code.S3Key in function definition
```

`deploy` works as below.
Expand Down
1 change: 1 addition & 0 deletions cmd/lambroll/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func _main() int {
DryRun: deploy.Flag("dry-run", "dry run").Bool(),
Publish: deploy.Flag("publish", "publish function").Default("true").Bool(),
AliasName: deploy.Flag("alias", "alias name for publish").Default(lambroll.CurrentAliasName).String(),
AliasToLatest: deploy.Flag("alias-to-latest", "set alias to unpublished $LATEST version").Default("false").Bool(),
SkipArchive: deploy.Flag("skip-archive", "skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition").Default("false").Bool(),
}

Expand Down
12 changes: 8 additions & 4 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type DeployOption struct {
ExcludeFile *string
Publish *bool
AliasName *string
AliasToLatest *bool
DryRun *bool
SkipArchive *bool
}
Expand Down Expand Up @@ -152,13 +153,16 @@ func (app *App) Deploy(opt DeployOption) error {
newerVersion = *res.Version
log.Printf("[info] deployed version %s %s", *res.Version, opt.label())
} else {
log.Println("[info] deployed")
newerVersion = versionLatest
log.Printf("[info] deployed version %s %s", newerVersion, opt.label())
}
if *opt.DryRun || !*opt.Publish {
if *opt.DryRun {
return nil
}

return app.updateAliases(*fn.FunctionName, versionAlias{newerVersion, *opt.AliasName})
if *opt.Publish || *opt.AliasToLatest {
return app.updateAliases(*fn.FunctionName, versionAlias{newerVersion, *opt.AliasName})
}
return nil
}

func (app *App) updateFunctionCodeWithRetry(ctx context.Context, in *lambda.UpdateFunctionCodeInput) (*lambda.FunctionConfiguration, error) {
Expand Down
2 changes: 2 additions & 0 deletions lambroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/shogo82148/go-retry"
)

const versionLatest = "$LATEST"

var retryPolicy = retry.Policy{
MinDelay: time.Second,
MaxDelay: 5 * time.Second,
Expand Down

0 comments on commit 2d801b4

Please # to comment.