-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a "stacker convert" to convert a Dockerfile (#349)
* feat: add a "stacker convert" to convert a Dockerfile Start with a subset of Dockerfile grammar. (syntax version 1) """ stacker help convert help convert NAME: stacker-dynamic convert - converts a Dockerfile into a stacker yaml file USAGE: stacker-dynamic convert [command options] [arguments...] OPTIONS: --docker-file value, -i value the input Dockerfile (default: "Dockerfile") --output-file value, -o value the output stacker file (default: "stacker.yaml") --substitute-file value, -s value the output file containing detected substitutions (default: "stacker-subs.yaml") """ Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> * feat: add "substitute-file" support for publish cmd Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
- Loading branch information
Showing
10 changed files
with
525 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/urfave/cli" | ||
"stackerbuild.io/stacker/pkg/stacker" | ||
) | ||
|
||
var convertCmd = cli.Command{ | ||
Name: "convert", | ||
Usage: "converts a Dockerfile into a stacker yaml file (experimental, best-effort)", | ||
Action: doConvert, | ||
Flags: initConvertFlags(), | ||
Before: beforeConvert, | ||
} | ||
|
||
func initConvertFlags() []cli.Flag { | ||
return append( | ||
initCommonConvertFlags(), | ||
cli.StringFlag{ | ||
Name: "docker-file, i", | ||
Usage: "the input Dockerfile", | ||
Value: "Dockerfile", | ||
}, | ||
cli.StringFlag{ | ||
Name: "output-file, o", | ||
Usage: "the output stacker file", | ||
Value: "stacker.yaml", | ||
}, | ||
cli.StringFlag{ | ||
Name: "substitute-file, s", | ||
Usage: "the output file containing detected substitutions", | ||
Value: "stacker-subs.yaml", | ||
}, | ||
) | ||
} | ||
|
||
func initCommonConvertFlags() []cli.Flag { | ||
return []cli.Flag{} | ||
} | ||
|
||
func beforeConvert(ctx *cli.Context) error { | ||
// Validate build failure arguments | ||
|
||
return nil | ||
} | ||
|
||
func newConvertArgs(ctx *cli.Context) (stacker.ConvertArgs, error) { | ||
args := stacker.ConvertArgs{ | ||
Config: config, | ||
Progress: shouldShowProgress(ctx), | ||
InputFile: ctx.String("docker-file"), | ||
OutputFile: ctx.String("output-file"), | ||
SubstituteFile: ctx.String("substitute-file"), | ||
} | ||
return args, nil | ||
} | ||
|
||
func doConvert(ctx *cli.Context) error { | ||
args, err := newConvertArgs(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
converter := stacker.NewConverter(&args) | ||
if err = converter.Convert(); err != nil { | ||
log.Fatalf("conversion failed: %e", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.