|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
| 4 | + "log" |
5 | 5 | "os"
|
| 6 | + |
| 7 | + "github.com/urfave/cli" |
6 | 8 | )
|
7 | 9 |
|
| 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 | + |
8 | 65 | func main() {
|
9 |
| - err := RepackImage("docker-daemon:lambda-php:latest") |
| 66 | + app, _ := createApp() |
| 67 | + err := app.Run(os.Args) |
10 | 68 | if err != nil {
|
11 |
| - fmt.Printf("Error: %+v", err) |
| 69 | + log.Fatal(err) |
12 | 70 | os.Exit(1)
|
13 | 71 | }
|
14 | 72 | }
|
0 commit comments