Giter VIP home page Giter VIP logo

kbuild's Introduction

kbuild

Build container images inside a Kubernetes Cluster with your local build context.

For more information see: Kaniko

Requirements

  1. ~/.docker/config.json exists and authenticated to a registry
  2. ~/.kube/config exists and configured with the correct cluster
  3. A Kubernetes Cluster
  4. A Container Registry

Installation

For Linux or Mac use

curl -fsSL https://raw.githubusercontent.com/cedrickring/kbuild/master/scripts/get | bash

Usage

Build an image of the current directory with tag repository:tag

kbuild -t repository:tag

To specify a Dockerfile in the working directory, use:

kbuild -t repository:tag -d Dockerfile.dev

or

kbuild --tag repository:tag --dockerfile Dockerfile.dev

respectively.

You can specify multiple image tags by repeating the tag flag.

Additional Flags

-w / --workdir

Specify the working directory (defaults to the directory you're currently in)

-d / --dockerfile

Path to the Dockerfile in the build context (defaults to Dockerfile)

-c / --cache

Enable RUN command caching for faster builds (See here)

--cache-repo

Specify the repo to cache build steps in (defaults to <repository>cache, repo retrieved from the image tag)

-n / --namespace

Specify namespace for the builder to run in (defaults to "default" namespace)

--build-arg

This flag allows you to pass in build args (ARG) for the Kaniko executor

--bucket

The bucket to use for Google Cloud Storage

Registry credentials

You can either have your Docker Container Registry credentials in your ~/.docker/config.json or provide them with the --username (-u) and --password (-p) flags.

When using the cli flags, the container registry url is guessed based on the first provided image tag. e.g. -t my.registry.com/tag is guessed as my.registry.com. If no specific registry is provided in the tag, it defaults to https://index.docker.io/v1/.

Google Cloud Storage

If you want to use the Google Cloud Storage to store your build context, you have to pass gcs as the first argument to kbuild and specify the --bucket to use.

Example: kbuild -t image:tag --bucket mybucket gcs

You might need to create a service account key and store the path to the service-account.json in the GOOGLE_APPLICATION_CREDENTIALS environment variable.

How does kbuild work?

In order to use the local context, the context needs to be tar-ed, copied to an Init Container, which shares an empty volume with the Kaniko container, and extracted in the empty volume (only for local context).

Limitations

  • You cannot specify args for the Kaniko executor

Windows

  • The docker-credential-wincred helper is not supported by Kaniko

kbuild's People

Contributors

cedrickring avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wangjianze

kbuild's Issues

Add support for build args

A command flag should be added to support build args e.g. --arg ARG1=value --arg ARG2=value etc. The args should be used for the build context and should be propagated to the Kaniko executor.

Add proxy to kaniko container

File changed

diff --git a/pkg/kaniko/pod.go b/pkg/kaniko/pod.go
index 7bea553..526cc47 100644
--- a/pkg/kaniko/pod.go
+++ b/pkg/kaniko/pod.go
@@ -41,6 +41,22 @@ func (b Build) getKanikoPod() *v1.Pod {
                                        Args: []string{
                                                "--dockerfile=" + b.DockerfilePath,
                                        },
+                                       Env: []v1.EnvVar{
+                                               {
+                                                       Name:  "HTTPS_PROXY",
+                                                       Value: "http://proxy.com:8080",
+                                               },
+                                               {
+                                                       Name:  "HTTPS_PROXY",
+                                                       Value: "http://proxy.com:8080",
+                                               },
+                                               {
+                                                       Name:  "NO_PROXY",
+                                                       Value: "xx2.com",
+                                               }},
                                        VolumeMounts: []v1.VolumeMount{
                                                {
                                                        Name:      "docker-config",
 ✘ ⚙ shashank.koppar@P34320  ~/Documents/kbuild   master ●  make
go fmt ./pkg/... ./cmd/...
pkg/kaniko/pod.go
go vet ./pkg/... ./cmd/...
# _/Users/shashank.koppar/Documents/kbuild/pkg/kaniko
pkg/kaniko/build.go:62:37: cannot use client (type *"github.com/cedrickring/kbuild/vendor/k8s.io/client-go/kubernetes".Clientset) as type *"k8s.io/client-go/kubernetes".Clientset in argument to b.checkForConfigMap
pkg/kaniko/build.go:75:20: cannot use pod (type *"k8s.io/api/core/v1".Pod) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Pod in argument to b.Source.ModifyPod
pkg/kaniko/build.go:82:31: cannot use pod (type *"k8s.io/api/core/v1".Pod) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Pod in argument to b.Source.UploadTar
pkg/kaniko/build.go:88:11: cannot assign *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Pod to pod (type *"k8s.io/api/core/v1".Pod) in multiple assignment
pkg/kaniko/build.go:88:24: cannot use pod (type *"k8s.io/api/core/v1".Pod) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Pod in argument to pods.Create
pkg/kaniko/build.go:95:4: cannot use &"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions literal (type *"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions in argument to pods.Delete
pkg/kaniko/build.go:103:31: cannot use pod (type *"k8s.io/api/core/v1".Pod) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Pod in argument to b.Source.UploadTar
pkg/kaniko/build.go:111:24: cannot use client (type *"github.com/cedrickring/kbuild/vendor/k8s.io/client-go/kubernetes".Clientset) as type *"k8s.io/client-go/kubernetes".Clientset in argument to b.streamLogs
pkg/kaniko/build.go:125:57: cannot use "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions literal (type "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions) as type "github.com/cedrickring/kbuild/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions in argument to pods.Get
# _/Users/shashank.koppar/Documents/kbuild/pkg/kaniko/source
pkg/kaniko/source/gcs.go:64:82: cannot use &"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions literal (type *"k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions in argument to k8sClient.CoreV1().Secrets(g.Namespace).Delete
pkg/kaniko/source/gcs.go:99:57: cannot use secret (type *"k8s.io/api/core/v1".Secret) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".Secret in argument to client.CoreV1().Secrets(g.Namespace).Create
# _/Users/shashank.koppar/Documents/kbuild/cmd [_/Users/shashank.koppar/Documents/kbuild/cmd.test]
cmd/kbuild.go:142:3: cannot use credentialsMap (type *"k8s.io/api/core/v1".ConfigMap) as type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".ConfigMap in field value
cmd/kbuild.go:209:41: cannot use docker.GetCredentialsAsConfigMap(credentials) (type *"github.com/cedrickring/kbuild/vendor/k8s.io/api/core/v1".ConfigMap) as type *"k8s.io/api/core/v1".ConfigMap in return argument
make: *** [vet] Error 2

I get this error when I try to execute make
How can I build a new binary?

met configmap issue when using rancher

I use rancher https://rancher.com/products/rancher to manage my kubernetes and get configmaps error, i do have admin permission.

$ kbuild -t abc
INFO[0000] Using credentials from ~/.docker/config.json
INFO[0000] Using local build context source
INFO[0000] Run-Step caching is disabled.
INFO[0000] Running in namespace "default"
FATA[0000] check for config map: creating configmap: {"Code":{"Code":"Forbidden","Status":403},"Message":"clusters.management.cattle.io \"c-76bcv\" is forbidden: User \"u-3hdhdog\" cannot get resource \"clusters\" in API group \"management.cattle.io\" at the cluster scope","Cause":null,"FieldName":""} (post configmaps)

Remove all external dependencies from kbuild

Which includes the need of:

  • kubectl (there should be a way to do this with the k8s.io/kubernetes package)
  • ~/.docker/config.json

The registry credentials can be either provided by --user <user> --password <password> or with the aliases -u <user> -p <password>. If they're not provided explicitly, they should be retrieved from the ~/.docker/config.json.

Add support for multiple image tags

Currently only one image tag is supported via -t <my-image-tag>. It should be possible to add more tags via -t <first-tag> -t <second-tag> etc.

Add support for .dockerignore file

Currently all files in the working directory are copied into the build context. Users should be able to specify paths to be excluded.

Add support for generic k8s cluster

It will be good to support generic k8s cluster, contents can be

  • kubectl cp from local to remote pod (may use ksync)
  • use pvc from shared local to remote pod

If needed, the remote pod (kaniko) can be run as permanent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.