From f97c67591e6220de910a5eabae16b26d168aec47 Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Thu, 23 Jan 2020 15:37:12 +0100 Subject: [PATCH] Add option to render manifest from previous build result --- cmd/skaffold/app/cmd/render.go | 36 +++++++++++++++---- docs/content/en/docs/references/cli/_index.md | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cmd/skaffold/app/cmd/render.go b/cmd/skaffold/app/cmd/render.go index b5d7f6eb7d5..7ac180f7cf2 100644 --- a/cmd/skaffold/app/cmd/render.go +++ b/cmd/skaffold/app/cmd/render.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Skaffold Authors +Copyright 2020 The Skaffold Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,18 +20,22 @@ import ( "context" "io" "io/ioutil" + "os" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" ) var ( - showBuild bool - renderOutputPath string + fromBuildFileOutputPath string + showBuild bool + renderOutputPath string ) // NewCmdRender describes the CLI command to build artifacts render Kubernetes manifests. @@ -40,6 +44,7 @@ func NewCmdRender() *cobra.Command { WithDescription("[alpha] Perform all image builds, and output rendered Kubernetes manifests"). WithCommonFlags(). WithFlags(func(f *pflag.FlagSet) { + f.StringVar(&fromBuildFileOutputPath, "from-build-file-output", "", "Don't build, but use file created with `skaffold build --file-output`") f.BoolVar(&showBuild, "loud", false, "Show the build logs and output") f.StringVar(&renderOutputPath, "output", "", "file to write rendered manifests to") }). @@ -53,10 +58,29 @@ func doRender(ctx context.Context, out io.Writer) error { } return withRunner(ctx, func(r runner.Runner, config *latest.SkaffoldConfig) error { - bRes, err := r.BuildAndTest(ctx, buildOut, targetArtifacts(opts, config)) + var bRes []build.Artifact - if err != nil { - return errors.Wrap(err, "executing build") + if fromBuildFileOutputPath != "" { + if _, err := os.Stat(fromBuildFileOutputPath); os.IsNotExist(err) { + return errors.Wrap(err, "reading build file output") + } + buf, err := ioutil.ReadFile(fromBuildFileOutputPath) + if err != nil { + return errors.Wrap(err, "reading build file output") + } + + buildOutput, err := flags.ParseBuildOutput(buf) + if err != nil { + return errors.Wrap(err, "parsing build file output") + } + + bRes = buildOutput.Builds + } else { + var err error + bRes, err = r.BuildAndTest(ctx, buildOut, targetArtifacts(opts, config)) + if err != nil { + return errors.Wrap(err, "executing build") + } } if err := r.Render(ctx, out, bRes, renderOutputPath); err != nil { diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md index 83ba0e1d078..eaa52e14dfe 100644 --- a/docs/content/en/docs/references/cli/_index.md +++ b/docs/content/en/docs/references/cli/_index.md @@ -652,6 +652,7 @@ The following options can be passed to any command: Options: -d, --default-repo='': Default repository value (overrides global config) -f, --filename='skaffold.yaml': Filename or URL to the pipeline file + --from-build-file-output='': Don't build, but use file created with `skaffold build --file-output` --loud=false: Show the build logs and output -n, --namespace='': Run deployments in the specified namespace --output='': file to write rendered manifests to