@@ -8,20 +8,13 @@ import (
88
99 "github.com/awslabs/aws-lambda-container-image-converter/img2lambda/extract"
1010 "github.com/awslabs/aws-lambda-container-image-converter/img2lambda/publish"
11+ "github.com/awslabs/aws-lambda-container-image-converter/img2lambda/types"
1112 "github.com/awslabs/aws-lambda-container-image-converter/img2lambda/version"
1213 "github.com/urfave/cli"
1314)
1415
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 {}
2518
2619 app := cli .NewApp ()
2720 app .EnableBashCompletion = true
@@ -36,30 +29,30 @@ func createApp() (*cli.App, *cmdOptions) {
3629 cli.StringFlag {
3730 Name : "image, i" ,
3831 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 ,
4033 },
4134 cli.StringFlag {
4235 Name : "region, r" ,
4336 Usage : "AWS region" ,
4437 Value : "us-east-1" ,
45- Destination : & opts .region ,
38+ Destination : & opts .Region ,
4639 },
4740 cli.StringFlag {
4841 Name : "output-directory, o" ,
4942 Usage : "Destination directory for command output" ,
5043 Value : "./output" ,
51- Destination : & opts .outputDir ,
44+ Destination : & opts .OutputDir ,
5245 },
5346 cli.StringFlag {
5447 Name : "layer-namespace, n" ,
5548 Usage : "Prefix for the layers published to Lambda" ,
5649 Value : "img2lambda" ,
57- Destination : & opts .layerNamespace ,
50+ Destination : & opts .LayerNamespace ,
5851 },
5952 cli.BoolFlag {
6053 Name : "dry-run, d" ,
6154 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 ,
6356 },
6457 }
6558
@@ -69,15 +62,15 @@ func createApp() (*cli.App, *cmdOptions) {
6962 return app , & opts
7063}
7164
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 " )
7568 cli .ShowAppHelpAndExit (context , 1 )
7669 }
7770}
7871
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 )
8174 if err != nil {
8275 return err
8376 }
@@ -86,8 +79,8 @@ func repackImageAction(opts *cmdOptions) error {
8679 return errors .New ("No compatible layers found in the image (likely nothing found in /opt)" )
8780 }
8881
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 )
9184 if err != nil {
9285 return err
9386 }
0 commit comments