@@ -8,20 +8,13 @@ import (
8
8
9
9
"github.com/awslabs/aws-lambda-container-image-converter/img2lambda/extract"
10
10
"github.com/awslabs/aws-lambda-container-image-converter/img2lambda/publish"
11
+ "github.com/awslabs/aws-lambda-container-image-converter/img2lambda/types"
11
12
"github.com/awslabs/aws-lambda-container-image-converter/img2lambda/version"
12
13
"github.com/urfave/cli"
13
14
)
14
15
15
- type cmdOptions struct {
16
- image string // Name of the container image
17
- region string // AWS region
18
- outputDir string // Output directory for the Lambda layers
19
- dryRun bool // Dry-run (will not register with Lambda)
20
- layerNamespace string // Prefix for published Lambda layers
21
- }
22
-
23
- func createApp () (* cli.App , * cmdOptions ) {
24
- opts := cmdOptions {}
16
+ func createApp () (* cli.App , * types.CmdOptions ) {
17
+ opts := types.CmdOptions {}
25
18
26
19
app := cli .NewApp ()
27
20
app .EnableBashCompletion = true
@@ -36,30 +29,30 @@ func createApp() (*cli.App, *cmdOptions) {
36
29
cli.StringFlag {
37
30
Name : "image, i" ,
38
31
Usage : "Name of the source container image. For example, 'my-docker-image:latest'. The Docker daemon must be pulled locally already." ,
39
- Destination : & opts .image ,
32
+ Destination : & opts .Image ,
40
33
},
41
34
cli.StringFlag {
42
35
Name : "region, r" ,
43
36
Usage : "AWS region" ,
44
37
Value : "us-east-1" ,
45
- Destination : & opts .region ,
38
+ Destination : & opts .Region ,
46
39
},
47
40
cli.StringFlag {
48
41
Name : "output-directory, o" ,
49
42
Usage : "Destination directory for command output" ,
50
43
Value : "./output" ,
51
- Destination : & opts .outputDir ,
44
+ Destination : & opts .OutputDir ,
52
45
},
53
46
cli.StringFlag {
54
47
Name : "layer-namespace, n" ,
55
48
Usage : "Prefix for the layers published to Lambda" ,
56
49
Value : "img2lambda" ,
57
- Destination : & opts .layerNamespace ,
50
+ Destination : & opts .LayerNamespace ,
58
51
},
59
52
cli.BoolFlag {
60
53
Name : "dry-run, d" ,
61
54
Usage : "Conduct a dry-run: Repackage the image, but only write the Lambda layers to local disk (do not publish to Lambda)" ,
62
- Destination : & opts .dryRun ,
55
+ Destination : & opts .DryRun ,
63
56
},
64
57
}
65
58
@@ -69,15 +62,15 @@ func createApp() (*cli.App, *cmdOptions) {
69
62
return app , & opts
70
63
}
71
64
72
- func validateCliOptions (opts * cmdOptions , context * cli.Context ) {
73
- if opts .image == "" {
74
- fmt .Println ("ERROR: Image name is required\n " )
65
+ func validateCliOptions (opts * types. CmdOptions , context * cli.Context ) {
66
+ if opts .Image == "" {
67
+ fmt .Print ("ERROR: Image name is required\n \n " )
75
68
cli .ShowAppHelpAndExit (context , 1 )
76
69
}
77
70
}
78
71
79
- func repackImageAction (opts * cmdOptions ) error {
80
- layers , err := extract .RepackImage ("docker-daemon:" + opts .image , opts .outputDir )
72
+ func repackImageAction (opts * types. CmdOptions ) error {
73
+ layers , err := extract .RepackImage ("docker-daemon:" + opts .Image , opts .OutputDir )
81
74
if err != nil {
82
75
return err
83
76
}
@@ -86,8 +79,8 @@ func repackImageAction(opts *cmdOptions) error {
86
79
return errors .New ("No compatible layers found in the image (likely nothing found in /opt)" )
87
80
}
88
81
89
- if ! opts .dryRun {
90
- err := publish .PublishLambdaLayers (opts . image , layers , opts . region , opts . layerNamespace , opts . outputDir )
82
+ if ! opts .DryRun {
83
+ err := publish .PublishLambdaLayers (types . ConvertToPublishOptions ( opts ), layers )
91
84
if err != nil {
92
85
return err
93
86
}
0 commit comments