Skip to content

Commit

Permalink
feat: add a "stacker convert" to convert a Dockerfile (#349)
Browse files Browse the repository at this point in the history
* 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
rchincha authored Jan 9, 2023
1 parent 3fb1a55 commit c00511a
Show file tree
Hide file tree
Showing 10 changed files with 525 additions and 215 deletions.
72 changes: 72 additions & 0 deletions cmd/stacker/convert.go
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
}
1 change: 1 addition & 0 deletions cmd/stacker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func main() {
app.Commands = []cli.Command{
buildCmd,
recursiveBuildCmd,
convertCmd,
publishCmd,
chrootCmd,
cleanCmd,
Expand Down
27 changes: 16 additions & 11 deletions cmd/stacker/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var publishCmd = cli.Command{
Usage: "regex pattern to use when searching for stackerfile paths",
Value: stackerFilePathRegex,
},
cli.StringFlag{
Name: "substitute-file",
Usage: "file containing variable substitution in stackerfiles, 'FOO: bar' yaml format",
},
cli.StringFlag{
Name: "search-dir, d",
Usage: "directory under which to search for stackerfiles to publish",
Expand Down Expand Up @@ -104,17 +108,18 @@ func doPublish(ctx *cli.Context) error {
}

args := stacker.PublishArgs{
Config: config,
ShowOnly: ctx.Bool("show-only"),
Substitute: ctx.StringSlice("substitute"),
Tags: ctx.StringSlice("tag"),
Url: ctx.String("url"),
Username: ctx.String("username"),
Password: ctx.String("password"),
Force: ctx.Bool("force"),
Progress: shouldShowProgress(ctx),
SkipTLS: ctx.Bool("skip-tls"),
LayerTypes: layerTypes,
Config: config,
ShowOnly: ctx.Bool("show-only"),
Substitute: ctx.StringSlice("substitute"),
SubstituteFile: ctx.String("substitute-file"),
Tags: ctx.StringSlice("tag"),
Url: ctx.String("url"),
Username: ctx.String("username"),
Password: ctx.String("password"),
Force: ctx.Bool("force"),
Progress: shouldShowProgress(ctx),
SkipTLS: ctx.Bool("skip-tls"),
LayerTypes: layerTypes,
}

var stackerFiles []string
Expand Down
19 changes: 11 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/martinjungblut/go-cryptsetup v0.0.0-20220314071908-7b9938e4a08c
github.com/minio/sha256-simd v1.0.0
github.com/mitchellh/hashstructure v1.1.0
github.com/moby/buildkit v0.10.6
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.3-0.20211202222133-eacdcc10569b
github.com/opencontainers/umoci v0.4.8-0.20220412065115-12453f247749
Expand All @@ -31,6 +32,7 @@ require (
golang.org/x/sys v0.3.0
golang.org/x/term v0.3.0
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
)

require (
Expand All @@ -43,15 +45,16 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/containerd v1.6.1 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.9.0 // indirect
github.com/containerd/containerd v1.6.3-0.20220401172941-5ff8fce1fcc6 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.11.3 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/containers/libtrust v0.0.0-20200511145503-9c3a6c22cd9a // indirect
github.com/containers/ocicrypt v1.1.2 // indirect
github.com/containers/ocicrypt v1.1.3 // indirect
github.com/containers/storage v1.37.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.0+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.11+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand All @@ -73,14 +76,14 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.4 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/moby/sys/mountinfo v0.6.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -91,7 +94,7 @@ require (
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -114,7 +117,7 @@ require (
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
Expand Down
Loading

0 comments on commit c00511a

Please sign in to comment.