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

add --alias-to-latest option to deploy command. #152

Merged
merged 2 commits into from
Jul 9, 2021
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
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