Skip to content

Commit

Permalink
Merge pull request #2942 from nkubala/render-command
Browse files Browse the repository at this point in the history
Add unimplemented 'skaffold render' command
  • Loading branch information
nkubala authored Sep 25, 2019
2 parents 78b3c71 + c4dea45 commit 667bd76
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
NewCmdBuild(),
NewCmdDeploy(),
NewCmdDelete(),
NewCmdRender(),
},
},
{
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 @@ -229,6 +229,14 @@ var FlagRegistry = []Flag{
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug", "deploy", "run"},
},
{
Name: "render-only",
Usage: "Print rendered kubernetes manifests instead of deploying them",
Value: &opts.RenderOnly,
DefValue: false,
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "run"},
},
{
Name: "config",
Shorthand: "c",
Expand Down
66 changes: 66 additions & 0 deletions cmd/skaffold/app/cmd/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2019 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"context"
"io"
"io/ioutil"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var (
showBuild bool
renderOutputPath string
)

// NewCmdRender describes the CLI command to build artifacts render kubernetes manifests.
func NewCmdRender() *cobra.Command {
return NewCmd("render").
WithDescription("Perform all image builds, and output rendered kubernetes manifests").
WithCommonFlags().
WithFlags(func(f *pflag.FlagSet) {
f.BoolVar(&showBuild, "loud", false, "Show the build logs and output")
f.StringVar(&renderOutputPath, "output", "", "file to write rendered manifests to")
}).
NoArgs(cancelWithCtrlC(context.Background(), doRender))
}

func doRender(ctx context.Context, out io.Writer) error {
buildOut := ioutil.Discard
if showBuild {
buildOut = out
}

return withRunner(ctx, func(r runner.Runner, config *latest.SkaffoldConfig) 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 {
return errors.Wrap(err, "rendering manifests")
}
return nil
})
}
37 changes: 37 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Pipeline building blocks for CI/CD:
* [skaffold build](#skaffold-build) - to just build and tag your image(s)
* [skaffold deploy](#skaffold-deploy) - to deploy the given image(s)
* [skaffold delete](#skaffold-delete) - to cleanup the deployed artifacts
* [skaffold render](#skaffold-render) - build and tag images, and output templated kubernetes manifests

Getting started with a new project:

Expand Down Expand Up @@ -71,6 +72,7 @@ Pipeline building blocks for CI/CD:
build Build the artifacts
deploy Deploy pre-built artifacts
delete Delete the deployed application
render Perform all image builds, and output rendered kubernetes manifests
Getting started with a new project:
init Generate configuration for deploying an application
Expand Down Expand Up @@ -446,6 +448,7 @@ Options:
--no-prune-children=false: Skip removing layers reused by Skaffold
--port-forward=false: Port-forward exposed container ports within pods
-p, --profile=[]: Activate profiles by name
--render-only=false: Print rendered kubernetes manifests instead of deploying them
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
--rpc-port=50051: tcp port to expose event API
--skip-tests=false: Whether to skip the tests after building
Expand Down Expand Up @@ -480,6 +483,7 @@ Env vars:
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RENDER_ONLY` (same as `--render-only`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
* `SKAFFOLD_SKIP_TESTS` (same as `--skip-tests`)
Expand Down Expand Up @@ -580,6 +584,37 @@ The following options can be passed to any command:
```

### skaffold render

Perform all image builds, and output rendered kubernetes manifests

```
Options:
-d, --default-repo='': Default repository value (overrides global config)
-f, --filename='skaffold.yaml': Filename or URL to the pipeline file
--loud=false: Show the build logs and output
-n, --namespace='': Run deployments in the specified namespace
--output='': file to write rendered manifests to
-p, --profile=[]: Activate profiles by name
Usage:
skaffold render [options]
Use "skaffold options" for a list of global command-line options (applies to all commands).
```
Env vars:

* `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`)
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_LOUD` (same as `--loud`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)

### skaffold run

Run a pipeline
Expand Down Expand Up @@ -610,6 +645,7 @@ Options:
--no-prune=false: Skip removing images and containers built by Skaffold
--no-prune-children=false: Skip removing layers reused by Skaffold
-p, --profile=[]: Activate profiles by name
--render-only=false: Print rendered kubernetes manifests instead of deploying them
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
--rpc-port=50051: tcp port to expose event API
--skip-tests=false: Whether to skip the tests after building
Expand Down Expand Up @@ -641,6 +677,7 @@ Env vars:
* `SKAFFOLD_NO_PRUNE` (same as `--no-prune`)
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_RENDER_ONLY` (same as `--render-only`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
* `SKAFFOLD_SKIP_TESTS` (same as `--skip-tests`)
Expand Down
1 change: 1 addition & 0 deletions docs/content/en/docs/references/cli/index_header
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Pipeline building blocks for CI/CD:
* [skaffold build](#skaffold-build) - to just build and tag your image(s)
* [skaffold deploy](#skaffold-deploy) - to deploy the given image(s)
* [skaffold delete](#skaffold-delete) - to cleanup the deployed artifacts
* [skaffold render](#skaffold-render) - build and tag images, and output templated kubernetes manifests

Getting started with a new project:

Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type SkaffoldOptions struct {
AutoBuild bool
AutoSync bool
AutoDeploy bool
RenderOnly bool
PortForward PortForwardOptions
CustomTag string
Namespace string
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/runner/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
)

func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []build.Artifact) error {
if r.runCtx.Opts.RenderOnly {
return r.Render(ctx, out, artifacts, "")
}

if config.IsKindCluster(r.runCtx.KubeContext) {
// With `kind`, docker images have to be loaded with the `kind` CLI.
if err := r.loadImagesInKindNodes(ctx, out, artifacts); err != nil {
Expand Down
28 changes: 28 additions & 0 deletions pkg/skaffold/runner/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2019 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package runner

import (
"context"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
)

func (r *SkaffoldRunner) Render(ctx context.Context, out io.Writer, builds []build.Artifact, filepath string) error {
return r.deployer.Render(ctx, out, builds, filepath)
}
1 change: 1 addition & 0 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Runner interface {
BuildAndTest(context.Context, io.Writer, []*latest.Artifact) ([]build.Artifact, error)
DeployAndLog(context.Context, io.Writer, []build.Artifact) error
GeneratePipeline(context.Context, io.Writer, *latest.SkaffoldConfig, []string, string) error
Render(context.Context, io.Writer, []build.Artifact, string) error
Cleanup(context.Context, io.Writer) error
Prune(context.Context, io.Writer) error
HasDeployed() bool
Expand Down
3 changes: 1 addition & 2 deletions pkg/skaffold/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package runner

import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -172,7 +171,7 @@ func (t *TestBench) Deploy(_ context.Context, _ io.Writer, artifacts []build.Art
}

func (t *TestBench) Render(_ context.Context, _ io.Writer, artifacts []build.Artifact, _ string) error {
return errors.New("not yet implemented")
return nil
}

func (t *TestBench) Actions() []Actions {
Expand Down

0 comments on commit 667bd76

Please sign in to comment.