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 Jun 16, 2020
1 parent 7b73876 commit 9820c33
Show file tree
Hide file tree
Showing 22 changed files with 479 additions and 71 deletions.
9 changes: 4 additions & 5 deletions cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
)

var (
buildOutputFile flags.BuildOutputFileFlag
preBuiltImages flags.Images
deployFromBuildOutputFile flags.BuildOutputFileFlag
preBuiltImages flags.Images
)

// NewCmdDeploy describes the CLI command to deploy artifacts.
Expand All @@ -46,15 +46,14 @@ func NewCmdDeploy() *cobra.Command {
WithCommonFlags().
WithFlags(func(f *pflag.FlagSet) {
f.VarP(&preBuiltImages, "images", "i", "A list of pre-built images to deploy")
f.VarP(&buildOutputFile, "build-artifacts", "a", `Filepath containing build output.
E.g. build.out created by running skaffold build --quiet -o "{{json .}}" > build.out`)
f.VarP(&deployFromBuildOutputFile, "build-artifacts", "a", "File containing build result from a previous 'skaffold build --file-output'")
}).
NoArgs(doDeploy)
}

func doDeploy(ctx context.Context, out io.Writer) error {
return withRunner(ctx, func(r runner.Runner, config *latest.SkaffoldConfig) error {
deployed, err := getArtifactsToDeploy(out, buildOutputFile.BuildArtifacts(), preBuiltImages.Artifacts(), config.Build.Artifacts)
deployed, err := getArtifactsToDeploy(out, deployFromBuildOutputFile.BuildArtifacts(), preBuiltImages.Artifacts(), config.Build.Artifacts)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/skaffold/app/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ var FlagRegistry = []Flag{
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "run", "debug", "deploy", "render", "build", "delete", "diagnose"},
},
{
Name: "add-skaffold-labels",
Usage: "Add Skaffold-specific labels to rendered manifest. If false, custom labels are still applied. Helpful for GitOps model where Skaffold is not the deployer.",
Value: &opts.AddSkaffoldLabels,
DefValue: true,
FlagAddMethod: "BoolVar",
DefinedOn: []string{"render"},
},
}

func (fl *Flag) flag() *pflag.Flag {
Expand Down
26 changes: 20 additions & 6 deletions cmd/skaffold/app/cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import (
"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
showBuild bool
renderOutputPath string
renderFromBuildOutputFile flags.BuildOutputFileFlag
offline bool
)

// NewCmdRender describes the CLI command to build artifacts render Kubernetes manifests.
Expand All @@ -42,6 +46,8 @@ func NewCmdRender() *cobra.Command {
WithCommonFlags().
WithFlags(func(f *pflag.FlagSet) {
f.BoolVar(&showBuild, "loud", false, "Show the build logs and output")
f.VarP(&renderFromBuildOutputFile, "build-artifacts", "a", "File containing build result from a previous 'skaffold build --file-output'")
f.BoolVar(&offline, "offline", false, `Do not connect to Kubernetes API server for manifest creation and validation. This is helpful when no Kubernetes cluster is available (e.g. GitOps model). No metadata.namespace attribute is injected in this case - the manifest content does not get changed.`)
f.StringVar(&renderOutputPath, "output", "", "file to write rendered manifests to")
f.StringVar(&opts.DigestSource, "digest-source", "local", "Set to 'local' to build images locally and use digests from built images; Set to 'remote' to resolve the digest of images by tag from the remote registry; Set to 'none' to use tags directly from the Kubernetes manifests")
}).
Expand All @@ -55,11 +61,19 @@ 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))
if err != nil {
return fmt.Errorf("executing build: %w", err)
var bRes []build.Artifact

if renderFromBuildOutputFile.String() != "" {
bRes = renderFromBuildOutputFile.BuildArtifacts()
} else {
var err error
bRes, err = r.BuildAndTest(ctx, buildOut, targetArtifacts(opts, config))
if err != nil {
return fmt.Errorf("executing build: %w", err)
}
}
if err := r.Render(ctx, out, bRes, renderOutputPath); err != nil {

if err := r.Render(ctx, out, bRes, offline, renderOutputPath); err != nil {
return fmt.Errorf("rendering manifests: %w", err)
}
return nil
Expand Down
9 changes: 7 additions & 2 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ Examples:
skaffold build -q | skaffold deploy --build-artifacts -
Options:
-a, --build-artifacts=: Filepath containing build output.
E.g. build.out created by running skaffold build --quiet -o "{{json .}}" > build.out
-a, --build-artifacts=: File containing build result from a previous 'skaffold build --file-output'
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
-d, --default-repo='': Default repository value (overrides global config)
--enable-rpc=false: Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)
Expand Down Expand Up @@ -700,12 +699,15 @@ Examples:
skaffold render --digest-source=remote
Options:
--add-skaffold-labels=true: Add Skaffold-specific labels to rendered manifest. If false, custom labels are still applied. Helpful for GitOps model where Skaffold is not the deployer.
-a, --build-artifacts=: File containing build result from a previous 'skaffold build --file-output'
-d, --default-repo='': Default repository value (overrides global config)
--digest-source='local': Set to 'local' to build images locally and use digests from built images; Set to 'remote' to resolve the digest of images by tag from the remote registry; Set to 'none' to use tags directly from the Kubernetes manifests
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
-l, --label=[]: Add custom labels to deployed objects. Set multiple times for multiple labels
--loud=false: Show the build logs and output
-n, --namespace='': Run deployments in the specified namespace
--offline=false: Do not connect to Kubernetes API server for manifest creation and validation. This is helpful when no Kubernetes cluster is available (e.g. GitOps model). No metadata.namespace attribute is injected in this case - the manifest content does not get changed.
--output='': file to write rendered manifests to
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
--profile-auto-activation=true: Set to false to disable profile auto activation
Expand All @@ -719,12 +721,15 @@ Use "skaffold options" for a list of global command-line options (applies to all
```
Env vars:

* `SKAFFOLD_ADD_SKAFFOLD_LABELS` (same as `--add-skaffold-labels`)
* `SKAFFOLD_BUILD_ARTIFACTS` (same as `--build-artifacts`)
* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
* `SKAFFOLD_DIGEST_SOURCE` (same as `--digest-source`)
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_LABEL` (same as `--label`)
* `SKAFFOLD_LOUD` (same as `--loud`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_OFFLINE` (same as `--offline`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
Expand Down
Loading

0 comments on commit 9820c33

Please sign in to comment.