Skip to content

Commit

Permalink
Adding support for Cloud Native Buildpacks (#3000)
Browse files Browse the repository at this point in the history
* Prepare version v1beta18

Signed-off-by: David Gageot <david@gageot.net>

* Support for Cloud Native Buildpacks

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot authored Oct 30, 2019
1 parent 5a78a0e commit b6fa9f2
Show file tree
Hide file tree
Showing 69 changed files with 4,156 additions and 121 deletions.
2 changes: 1 addition & 1 deletion docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ weight = 1
copyright = "Skaffold Authors"
privacy_policy = "https://policies.google.com/privacy"
github_repo = "https://github.com/GoogleContainerTools/skaffold"
skaffold_version = "skaffold/v1beta17"
skaffold_version = "skaffold/v1beta18"

# Google Custom Search Engine ID. Remove or comment out to disable search.
gcs_engine_id = "013756393218025596041:3nojel67sum"
Expand Down
2,059 changes: 2,059 additions & 0 deletions docs/content/en/schemas/v1beta18.json

Large diffs are not rendered by default.

64 changes: 1 addition & 63 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ func TestBuild(t *testing.T) {
dir: "testdata/tagPolicy",
args: []string{"-p", "envTemplate"},
expectImage: imageName + "tag",
}, {
description: "buildpacks",
dir: "examples/buildpacks",
},
{
description: "custom",
dir: "examples/custom",
setup: func(t *testing.T, _ string) func() {
cmd := exec.Command("pack", "set-default-builder", "heroku/buildpacks")
if err := cmd.Run(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/bazel/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
3 changes: 2 additions & 1 deletion integration/examples/buildpacks/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module github.com/GoogleContainerTools/skaffold/examples/buildpacks

go 1.12
// +heroku goVersion go1.13.1
go 1.13
14 changes: 9 additions & 5 deletions integration/examples/buildpacks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package main

import (
"fmt"
"time"
"log"
"net/http"
)

func main() {
for {
fmt.Println("Hello world!")
http.HandleFunc("/", hello)

time.Sleep(time.Second * 1)
}
log.Println("Listening on port 8080")
http.ListenAndServe(":8080", nil)
}

func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}
13 changes: 3 additions & 10 deletions integration/examples/buildpacks/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-example
custom:
buildCommand: ./build.sh
dependencies:
paths:
- .
deploy:
kubectl:
manifests:
- k8s-*
buildpack:
builder: "heroku/buildpacks"
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ and the skaffold config, which configures artifact `gcr.io/k8s-skaffold/skaffold

```yaml
$ cat skaffold.yaml
apiVersion: skaffold/v1beta14
apiVersion: skaffold/v1beta15
kind: Config
build:
artifacts:
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions integration/examples/custom/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/GoogleContainerTools/skaffold/examples/buildpacks

go 1.12
8 changes: 8 additions & 0 deletions integration/examples/custom/k8s-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: getting-started
spec:
containers:
- name: getting-started
image: gcr.io/k8s-skaffold/skaffold-example
14 changes: 14 additions & 0 deletions integration/examples/custom/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"time"
)

func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Second * 1)
}
}
14 changes: 14 additions & 0 deletions integration/examples/custom/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-example
custom:
buildCommand: ./build.sh
dependencies:
paths:
- .
deploy:
kubectl:
manifests:
- k8s-*
2 changes: 1 addition & 1 deletion integration/examples/gcb-kaniko/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
googleCloudBuild:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/generate-pipeline/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/getting-started/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/google-cloud-build/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
googleCloudBuild:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
tagPolicy:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/helm-deployment/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
tagPolicy:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/hot-reload/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib-gradle/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib-multimodule/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/kaniko-local/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/kaniko/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/kustomize/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
deploy:
kustomize: {}
2 changes: 1 addition & 1 deletion integration/examples/microservices/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/nodejs/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/profiles/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
# only build and deploy "world-service" on main profile
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/react-reload/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/structure-tests/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
9 changes: 7 additions & 2 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ func TestRun(t *testing.T) {
args: []string{"-p", "gcb"},
deployments: []string{"web"},
gcpOnly: true,
},
{
}, {
description: "buildpacks",
dir: "examples/buildpacks",
pods: []string{"getting-started"},
// Don't run on kind because of this issue: https://github.com/buildpack/pack/issues/277
gcpOnly: true,
}, {
description: "custom builder",
dir: "testdata/custom",
pods: []string{"bazel"},
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/build/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
local:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/custom/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/debug/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/dev/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/gke_loadbalancer/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/jib-gradle/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/jib/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/kaniko-microservices/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/kaniko-sub-folder/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/kaniko-target/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/tagPolicy/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: skaffold/v1beta17
apiVersion: skaffold/v1beta18
kind: Config
build:
artifacts:
Expand Down
59 changes: 59 additions & 0 deletions pkg/skaffold/build/buildpacks/buildpacks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
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 buildpacks

import (
"context"
"io"

"github.com/pkg/errors"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
)

// BuildpackBuilder is a builder for buildpack artifacts
type BuildpackBuilder struct {
localDocker docker.LocalDaemon
pushImages bool
}

// NewArtifactBuilder returns a new buildpack artifact builder
func NewArtifactBuilder(localDocker docker.LocalDaemon, pushImages bool) *BuildpackBuilder {
return &BuildpackBuilder{
localDocker: localDocker,
pushImages: pushImages,
}
}

// Build builds an artifact with Cloud Native Buildpacks:
// https://buildpacks.io/
func (b *BuildpackBuilder) Build(ctx context.Context, out io.Writer, a *latest.Artifact, tag string) (string, error) {
built, err := b.build(ctx, out, a.Workspace, a.BuildpackArtifact, tag)
if err != nil {
return "", err
}

if err := b.localDocker.Tag(ctx, built, tag); err != nil {
return "", errors.Wrapf(err, "tagging %s->%s", built, tag)
}

if b.pushImages {
return b.localDocker.Push(ctx, out, tag)
}
return b.localDocker.ImageID(ctx, tag)
}
Loading

0 comments on commit b6fa9f2

Please sign in to comment.