Skip to content

Commit

Permalink
Merge pull request #394 from fujiwara/fix/ignore-image-config
Browse files Browse the repository at this point in the history
Fix: `--ignore .ImageConfig` didn't work.
  • Loading branch information
fujiwara authored Apr 19, 2024
2 parents 494e871 + 0583b76 commit 5c22685
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ Flags:

lambroll also support to deploy a container image for Lambda.

PackageType=Image and Code.ImageUri are required in function.json.
`PackageType=Image` and `Code.ImageUri` are required in function.json.
`ImageConfig` is optional.

```json
{
Expand All @@ -253,6 +254,15 @@ PackageType=Image and Code.ImageUri are required in function.json.
"PackageType": "Image",
"Code": {
"ImageUri": "012345678912.dkr.ecr.ap-northeast-1.amazonaws.com/lambda/test:latest"
},
"ImageConfig": {
"Command": [
"/path/to/bootstrap"
],
"WorkingDirectory": "/var/task",
"EntryPoint": [
"/path/to/entrypoint"
],
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (app *App) prepareFunctionCodeForDeploy(ctx context.Context, opt *DeployOpt
log.Printf("[info] uploading function %d bytes to s3://%s/%s", info.Size(), *bucket, *key)
versionID, err := app.uploadFunctionToS3(ctx, zipfile, *bucket, *key)
if err != nil {
fmt.Errorf("failed to upload function zip to s3://%s/%s: %w", *bucket, *key, err)
return fmt.Errorf("failed to upload function zip to s3://%s/%s: %w", *bucket, *key, err)
}
if versionID != "" {
log.Printf("[info] object created as version %s", versionID)
Expand Down
11 changes: 6 additions & 5 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (opt *DeployOption) String() string {
return string(b)
}

// Deploy deployes a new lambda function code
// Deploy deploys a new lambda function code
func (app *App) Deploy(ctx context.Context, opt *DeployOption) error {
if err := opt.Expand(); err != nil {
return err
Expand Down Expand Up @@ -119,6 +119,10 @@ func (app *App) Deploy(ctx context.Context, opt *DeployOption) error {
}
fillDefaultValues(fn)

if err := app.prepareFunctionCodeForDeploy(ctx, opt, fn); err != nil {
return fmt.Errorf("failed to prepare function code for deploy: %w", err)
}

if ignore := opt.Ignore; ignore != "" {
q, err := gojq.Parse(ignore)
if err != nil {
Expand All @@ -135,10 +139,6 @@ func (app *App) Deploy(ctx context.Context, opt *DeployOption) error {
unmarshalJSON(src, &fn, app.functionFilePath)
}

if err := app.prepareFunctionCodeForDeploy(ctx, opt, fn); err != nil {
return fmt.Errorf("failed to prepare function code for deploy: %w", err)
}

log.Println("[info] updating function configuration", opt.label())
confIn := &lambda.UpdateFunctionConfigurationInput{
DeadLetterConfig: fn.DeadLetterConfig,
Expand All @@ -160,6 +160,7 @@ func (app *App) Deploy(ctx context.Context, opt *DeployOption) error {
ImageConfig: fn.ImageConfig,
SnapStart: fn.SnapStart,
}
log.Printf("[debug] %s", jsonStr(confIn))

var newerVersion string
if !opt.DryRun {
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func toGeneralMap(s any, omitEmpty bool) (any, error) {
return x, nil
}

func jsonStr(s any) string {
b, err := json.MarshalIndent(s, "", " ")
if err != nil {
log.Printf("[warn] failed to marshal json: %s", err)
}
return string(b)
}

func marshalJSON(s interface{}) ([]byte, error) {
x, err := toGeneralMap(s, true)
if err != nil {
Expand Down

0 comments on commit 5c22685

Please sign in to comment.