Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/configuration/config.yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ DockerConfig:
KanikoConfig:
- `cache` *bool* if true the last image build is used as cache repository
- `namespace` *string* specifies the namespace where the build pod should be started
- `pullSecret` *string* mount this pullSecret instead of creating one to authenticate to the registry

### images[].build.options
BuildOptions:
Expand Down
1 change: 0 additions & 1 deletion examples/kaniko/.devspace/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ images:
build:
kaniko:
cache: true
namespace: ""
name: yourdockername/kaniko
36 changes: 33 additions & 3 deletions examples/kaniko/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ This example shows how kaniko can be used instead of docker to build and push an

# Step 0: Prerequisites

In order for this example to work you need access to a docker registry, where you can push images to (e.g. hub.docker.com, gcr.io etc.). There are two options how you can push images to registries with devspace.
In order for this example to work you need access to a docker registry, where you can push images to (e.g. hub.docker.com, gcr.io etc.). There are three options how you can push images to registries with devspace.

## Option 1: Use docker credentials store
If you have docker installed, devspace can take the required auth information directly out of the docker credentials store and will create the needed secret for you in the target cluster automatically. Make sure you are logged in the registry with `docker login`.

## Option 2: Provide auth information yourself
As a second option you can provide your credentials directly in the config.yaml. See example below:
As a second option you can provide your credentials directly in the config.yaml and devspace cli will create a pull secret for you automatically. See example below:

```yaml
images:
default:
build:
kaniko:
cache: true
namespace: ""
# Don't prefix image name with registry url
name: name/devspace
registry: myRegistry
Expand All @@ -33,6 +32,37 @@ registries:

devspace will then automatically create a secret for you which kaniko can use to push to that registry.

## Option 3: Provide kaniko pull secret yourself
As a third option you can provide the pullSecret to use for kaniko yourself. Make sure the pull secret has the following form:

```yaml
apiVersion: v1
kind: Secret
data:
# .dockerconfigjson encoded in base64 e.g.:
# {
# "auths": {
# "myRegistryUrl": {
# "auth": "base64Encoded(user:password/token)",
# "email": "myemail@test.de"
# }
# }
# }
.dockerconfigjson: BASE64EncodedDockerConfigJson
```

Now specify the pullsecret name as the pull secret to use for kaniko in the .devspace/config:

```yaml
images:
default:
build:
kaniko:
cache: true
name: registryName/name/devspace
pullSecret: myPullSecretName
```

## Optional: Use self hosted cluster (minikube, GKE etc.) instead of devspace-cloud

If you want to use your own cluster instead of the devspace-cloud as deployment target, make sure `kubectl` is configured correctly to access the target cluster. Then just erase the `cluster` section in the `.devspace/config.yaml` and devspace will use your current kubectl context as deployment target.
Expand Down
12 changes: 11 additions & 1 deletion pkg/devspace/builder/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
// Builder holds the necessary information to build and push docker images
type Builder struct {
RegistryURL string
PullSecretName string
ImageName string
ImageTag string
PreviousImageTag string
Expand All @@ -33,9 +34,10 @@ type Builder struct {
}

// NewBuilder creates a new kaniko.Builder instance
func NewBuilder(registryURL, imageName, imageTag, lastImageTag, buildNamespace string, kubectl *kubernetes.Clientset, allowInsecureRegistry bool) (*Builder, error) {
func NewBuilder(registryURL, pullSecretName, imageName, imageTag, lastImageTag, buildNamespace string, kubectl *kubernetes.Clientset, allowInsecureRegistry bool) (*Builder, error) {
return &Builder{
RegistryURL: registryURL,
PullSecretName: pullSecretName,
ImageName: imageName,
ImageTag: imageTag,
PreviousImageTag: lastImageTag,
Expand All @@ -47,6 +49,10 @@ func NewBuilder(registryURL, imageName, imageTag, lastImageTag, buildNamespace s

// Authenticate authenticates kaniko for pushing to the RegistryURL (if username == "", it will try to get login data from local docker daemon)
func (b *Builder) Authenticate(username, password string, checkCredentialsStore bool) (*types.AuthConfig, error) {
if b.PullSecretName != "" {
return nil, nil
}

email := "noreply@devspace-cloud.com"

if len(username) == 0 {
Expand Down Expand Up @@ -74,6 +80,10 @@ func (b *Builder) Authenticate(username, password string, checkCredentialsStore
// BuildImage builds a dockerimage within a kaniko pod
func (b *Builder) BuildImage(contextPath, dockerfilePath string, options *types.ImageBuildOptions) error {
pullSecretName := registry.GetRegistryAuthSecretName(b.RegistryURL)
if b.PullSecretName != "" {
pullSecretName = b.PullSecretName
}

randString, _ := randutil.GenerateRandomString(12)
buildID := strings.ToLower(randString)
buildPod := &k8sv1.Pod{
Expand Down
5 changes: 3 additions & 2 deletions pkg/devspace/config/v1/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type BuildConfig struct {

// KanikoConfig tells the DevSpace CLI to build with Docker on Minikube or on localhost
type KanikoConfig struct {
Cache *bool `yaml:"cache"`
Namespace *string `yaml:"namespace,omitempty"`
Cache *bool `yaml:"cache"`
Namespace *string `yaml:"namespace,omitempty"`
PullSecret *string `yaml:"pullSecret,omitempty"`
}

// DockerConfig tells the DevSpace CLI to build with Docker on Minikube or on localhost
Expand Down
7 changes: 6 additions & 1 deletion pkg/devspace/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ func Build(client *kubernetes.Clientset, generatedConfig *generated.Config, imag
allowInsecurePush = *registryConf.Insecure
}

imageBuilder, err = kaniko.NewBuilder(registryURL, imageName, imageTag, (*generatedConfig).ImageTags[imageName], buildNamespace, client, allowInsecurePush)
pullSecret := ""
if imageConf.Build.Kaniko.PullSecret != nil {
pullSecret = *imageConf.Build.Kaniko.PullSecret
}

imageBuilder, err = kaniko.NewBuilder(registryURL, pullSecret, imageName, imageTag, (*generatedConfig).ImageTags[imageName], buildNamespace, client, allowInsecurePush)
if err != nil {
log.Fatalf("Error creating kaniko builder: %v", err)
}
Expand Down