Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 858e5a3

Browse files
committed
Start adding cli options
1 parent fcf11f8 commit 858e5a3

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ docker build -t lambda-php .
88
docker run lambda-php hello '{"name": "World"}'
99
1010
docker run lambda-php goodbye '{"name": "World"}'
11+
12+
../../bin/img2lambda -i docker-daemon:lambda-php:latest
1113
```
1214

1315
## License Summary
1416

15-
This sample code is made available under a modified MIT license. See the LICENSE file.
17+
This sample code is made available under a modified MIT license. See the LICENSE file.

main.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,72 @@
11
package main
22

33
import (
4-
"fmt"
4+
"log"
55
"os"
6+
7+
"github.com/urfave/cli"
68
)
79

10+
type cmdOptions struct {
11+
image string // Name of the container image
12+
region string // AWS region
13+
outputDir string // Output directory for the Lambda layers
14+
dryRun bool // Dry-run (will not register with Lambda)
15+
layerNamespace string // Prefix for published Lambda layers
16+
}
17+
18+
func createApp() (*cli.App, *cmdOptions) {
19+
opts := cmdOptions{}
20+
21+
app := cli.NewApp()
22+
app.EnableBashCompletion = true
23+
app.Name = "img2lambda"
24+
app.Usage = "Repackages a container image into Lambda layers and publishes them to Lambda"
25+
app.Action = func(c *cli.Context) error {
26+
return repackImageAction(&opts)
27+
}
28+
app.Flags = []cli.Flag{
29+
cli.StringFlag{
30+
Name: "image, i",
31+
Usage: "Name of the source container image. Format is 'transport:details', such as 'docker-daemon:my-docker-image:latest",
32+
Destination: &opts.image,
33+
},
34+
cli.StringFlag{
35+
Name: "region, r",
36+
Usage: "AWS region",
37+
Value: "us-east-1",
38+
Destination: &opts.region,
39+
},
40+
cli.StringFlag{
41+
Name: "output-directory, o",
42+
Usage: "Destination directory for command output",
43+
Value: "./output",
44+
Destination: &opts.outputDir,
45+
},
46+
cli.StringFlag{
47+
Name: "layer-namespace, n",
48+
Usage: "Prefix for the layers published to Lambda",
49+
Value: "img2lambda",
50+
Destination: &opts.layerNamespace,
51+
},
52+
cli.BoolFlag{
53+
Name: "dry-run, d",
54+
Usage: "Conduct a dry-run: Repackage the image, but write the Lambda layers to local disk (do not publish to Lambda)",
55+
Destination: &opts.dryRun,
56+
},
57+
}
58+
return app, &opts
59+
}
60+
61+
func repackImageAction(opts *cmdOptions) error {
62+
return RepackImage(opts.image)
63+
}
64+
865
func main() {
9-
err := RepackImage("docker-daemon:lambda-php:latest")
66+
app, _ := createApp()
67+
err := app.Run(os.Args)
1068
if err != nil {
11-
fmt.Printf("Error: %+v", err)
69+
log.Fatal(err)
1270
os.Exit(1)
1371
}
1472
}

0 commit comments

Comments
 (0)