Skip to content

Commit

Permalink
Add option to render manifest from previous build result
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDog committed Jan 23, 2020
1 parent aee8c11 commit f97c675
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cmd/skaffold/app/cmd/render.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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")
}).
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f97c675

Please sign in to comment.