-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from priyawadhwa/localdir
Add localdir buildcontext to kaniko builder
- Loading branch information
Showing
14 changed files
with
421 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM gcr.io/google-appengine/golang | ||
|
||
WORKDIR /go/src/github.com/GoogleCloudPlatform/skaffold | ||
CMD ["./app"] | ||
COPY main.go . | ||
RUN go build -o app main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== Example: kaniko-local | ||
:icons: font | ||
|
||
This is an example demonstrating | ||
|
||
* *building* a single go file app and with a single stage `Dockerfile` using https://github.com/GoogleContainerTools/kaniko[kaniko] to build on a K8S cluster directly from a local build context | ||
* *tagging* using the default tagPolicy (`gitCommit`) | ||
* *deploying* a single container pod using `kubectl` | ||
ifndef::env-github[] | ||
==== Example files | ||
link:{github-repo-tree}/examples/kaniko[see on Github icon:github[]] | ||
|
||
[source,yaml, indent=3, title=skaffold.yaml] | ||
---- | ||
include::skaffold.yaml[] | ||
---- | ||
|
||
[source,go, indent=3, title=main.go, syntax=go] | ||
---- | ||
include::main.go[] | ||
---- | ||
|
||
[source,docker, indent=3, title=Dockerfile] | ||
---- | ||
include::Dockerfile[] | ||
---- | ||
|
||
[source,yaml, indent=3, title=k8s-pod.yaml] | ||
---- | ||
include::k8s-pod.yaml[] | ||
---- | ||
|
||
endif::[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: getting-started-kaniko | ||
spec: | ||
containers: | ||
- name: getting-started | ||
image: gcr.io/k8s-skaffold/skaffold-example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
for { | ||
fmt.Println("Hello world!") | ||
time.Sleep(time.Second * 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: skaffold/v1alpha4 | ||
kind: Config | ||
build: | ||
artifacts: | ||
- image: gcr.io/k8s-skaffold/skaffold-example | ||
kaniko: | ||
buildContext: | ||
localDir: {} | ||
pullSecretName: e2esecret | ||
namespace: default | ||
deploy: | ||
kubectl: | ||
manifests: | ||
- k8s-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright 2018 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 sources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
cstorage "cloud.google.com/go/storage" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/gcp" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type GCSBucket struct { | ||
tarName string | ||
} | ||
|
||
// Setup uploads the context to the provided GCS bucket | ||
func (g *GCSBucket) Setup(ctx context.Context, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) { | ||
bucket := cfg.BuildContext.GCSBucket | ||
if bucket == "" { | ||
guessedProjectID, err := gcp.ExtractProjectID(artifact.ImageName) | ||
if err != nil { | ||
return "", errors.Wrap(err, "extracting projectID from image name") | ||
} | ||
|
||
bucket = guessedProjectID | ||
} | ||
logrus.Debugln("Upload sources to", bucket, "GCS bucket") | ||
|
||
g.tarName = fmt.Sprintf("context-%s.tar.gz", initialTag) | ||
if err := docker.UploadContextToGCS(ctx, artifact.Workspace, artifact.DockerArtifact, bucket, g.tarName); err != nil { | ||
return "", errors.Wrap(err, "uploading sources to GCS") | ||
} | ||
context := fmt.Sprintf("gs://%s/%s", cfg.BuildContext.GCSBucket, g.tarName) | ||
return context, nil | ||
} | ||
|
||
// Pod returns the pod template for this builder | ||
func (g *GCSBucket) Pod(cfg *latest.KanikoBuild, args []string) *v1.Pod { | ||
return podTemplate(cfg, args) | ||
} | ||
|
||
// ModifyPod does nothing here, since we just need to let kaniko run to completion | ||
func (g *GCSBucket) ModifyPod(p *v1.Pod) error { | ||
return nil | ||
} | ||
|
||
// Cleanup deletes the tarball from the GCS bucket | ||
func (g *GCSBucket) Cleanup(ctx context.Context, cfg *latest.KanikoBuild) error { | ||
c, err := cstorage.NewClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer c.Close() | ||
return c.Bucket(cfg.BuildContext.GCSBucket).Object(g.tarName).Delete(ctx) | ||
} |
Oops, something went wrong.