Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --compose-file option to skaffold init #1282

Merged
merged 3 commits into from
Nov 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/skaffold/app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"

Expand All @@ -45,6 +46,7 @@ import (
const NoDockerfile = "None (image not built from these sources)"

var (
composeFile string
cliArtifacts []string
skipBuild bool
force bool
Expand All @@ -63,13 +65,23 @@ func NewCmdInit(out io.Writer) *cobra.Command {
cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file")
cmd.Flags().BoolVar(&skipBuild, "skip-build", false, "Skip generating build artifacts in skaffold config")
cmd.Flags().BoolVar(&force, "force", false, "Force the generation of the skaffold config")
cmd.Flags().StringVar(&composeFile, "compose-file", "", "Initialize from a docker-compose file")
cmd.Flags().StringArrayVarP(&cliArtifacts, "artifact", "a", nil, "'='-delimited dockerfile/image pair to generate build artifact\n(example: --artifact=/web/Dockerfile.web=gcr.io/web-project/image)")
return cmd
}

func doInit(out io.Writer) error {
rootDir := "."

if composeFile != "" {
// run kompose first to generate k8s manifests, then run skaffold init
logrus.Infof("running 'kompose convert' for file %s", composeFile)
komposeCmd := exec.Command("kompose", "convert", "-f", composeFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a preference around supported version for kompose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added it to the dockerfile with a pinned version. I only tried with the latest (v1.17.0), but I'm assuming any older version that does what it's supposed to do will work with skaffold.

if err := util.RunCmd(komposeCmd); err != nil {
return errors.Wrap(err, "running kompose")
}
}

var potentialConfigs, k8sConfigs, dockerfiles, images []string
err := filepath.Walk(rootDir, func(path string, f os.FileInfo, e error) error {
if f.IsDir() {
Expand Down