Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Try to bring kaniko implementation up-to-date with the latest lifecycle #19

Closed
Closed
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
55 changes: 15 additions & 40 deletions kaniko/code/buildpackconfig/buildPackConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import (
"compress/gzip"
"encoding/json"
"errors"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/executor"
"github.com/google/go-containerregistry/pkg/v1/tarball"
image_util "github.com/GoogleContainerTools/kaniko/pkg/image"
fs_util "github.com/GoogleContainerTools/kaniko/pkg/util"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/sirupsen/logrus"

"github.com/redhat-buildpacks/poc/kaniko/store"
"github.com/redhat-buildpacks/poc/kaniko/util"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
)

const (
homeDir = "/"
kanikoDir = "/kaniko"
cacheDir = "/cache"
cacheDir = "/layers/kaniko"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this path customizable using Lifecycle ? If yes, then we should define an ENV var and externalize it

workspaceDir = "/workspace"
defaultDockerFileName = "Dockerfile"
layerTarFileName = "newlayer.tar"
destination = "new_image"
DOCKER_FILE_NAME_ENV_NAME = "DOCKER_FILE_NAME"
IGNORE_PATHS_ENV_NAME = "IGNORE_PATHS"
)

Expand Down Expand Up @@ -68,16 +68,7 @@ func NewBuildPackConfig() *BuildPackConfig {
}

func (b *BuildPackConfig) InitDefaults() {

logrus.Debug("Check if DOCKER_FILE_NAME env is defined...")
b.DockerFileName = util.GetValFromEnVar(DOCKER_FILE_NAME_ENV_NAME)
if b.DockerFileName == "" {
b.DockerFileName = defaultDockerFileName
}
logrus.Debugf("DockerfileName is: %s", b.DockerFileName)
Comment on lines -72 to -77
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as this information will be supplied from /layers/config/metadata.toml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. So we have to review the README.md file to be sure that we do not support/use anymore a dockerfile but instead a TOML file containing the Dockerfile(s)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. As the "spec requirements" for the extender are still very much in flux I wonder if it makes sense to have another place where we could iterate on it more easily - I started a document here to try to start to formalize this. When it's a little more solidified we could put it in the repo, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note that the code will still need to be updated further ...forthcoming... to reflect what's in the document, but I think this is closer to where we want to land WRT variable names, etc.)


logrus.Debug("Check if IGNORE_PATHS env is defined...")

result := util.GetValFromEnVar(IGNORE_PATHS_ENV_NAME)
if result == "" {
b.IgnorePaths = ignorePaths
Expand All @@ -92,29 +83,13 @@ func (b *BuildPackConfig) InitDefaults() {
})
}

logrus.Debug("Checking if CNB_* env var have been declared ...")
b.CnbEnvVars = util.GetCNBEnvVar()
logrus.Debugf("CNB ENV var is: %s", b.CnbEnvVars)

// Convert the CNB ENV vars to Kaniko BuildArgs
for k, v := range b.CnbEnvVars {
logrus.Debugf("CNB env key: %s, value: %s", k, v)
arg := k + "=" + v
b.BuildArgs = append(b.BuildArgs, arg)
}

// setup the path to access the Dockerfile within the workspace dir
dockerFilePath := b.WorkspaceDir + "/" + b.DockerFileName
Comment on lines -95 to -107
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README should also remove this section explaining how to pass parameters using TOML Dockerfiles and not ENV Vars ;-)


// init the Kaniko options
b.Opts = config.KanikoOptions{
CacheOptions: config.CacheOptions{CacheDir: cacheDir},
DockerfilePath: dockerFilePath,
IgnoreVarRun: true,
NoPush: true,
SrcContext: b.WorkspaceDir,
SnapshotMode: "full",
BuildArgs: b.BuildArgs,
IgnorePaths: b.IgnorePaths,
TarPath: b.LayerTarFileName,
Destinations: []string{b.Destination},
Expand All @@ -124,7 +99,7 @@ func (b *BuildPackConfig) InitDefaults() {
logrus.Debug("KanikoOptions defined")
}

func (b *BuildPackConfig) BuildDockerFile() (err error) {
func (b *BuildPackConfig) BuildDockerFile(opts config.KanikoOptions) (err error) {

// If we look to the Kaniko code, they are moving under the root dire directory
logrus.Debug("Moving to root dir")
Expand All @@ -133,15 +108,15 @@ func (b *BuildPackConfig) BuildDockerFile() (err error) {
}

logrus.Debugf("Building the %s ...", b.DockerFileName)
logrus.Debugf("Options used %+v", b.Opts)
b.NewImage, err = executor.DoBuild(&b.Opts)
logrus.Debugf("Options used %+v", opts)
b.NewImage, err = executor.DoBuild(&opts)
if (err != nil) {
return err
}

// Push the image to its destination
logrus.Info("Push the image to its destination")
err = executor.DoPush(b.NewImage, &b.Opts)
err = executor.DoPush(b.NewImage, &opts)
return err
}

Expand Down
3 changes: 1 addition & 2 deletions kaniko/code/go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module github.com/redhat-buildpacks/poc/kaniko

require (
github.com/BurntSushi/toml v0.3.1
github.com/GoogleContainerTools/kaniko v1.7.1-0.20220114205832-76624697df87
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/google/go-containerregistry v0.4.1-0.20210128200529-19c2b639fab1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
gotest.tools v2.2.0+incompatible // indirect
)

replace (
Expand Down
Loading