-
Notifications
You must be signed in to change notification settings - Fork 6
Try to bring kaniko implementation up-to-date with the latest lifecycle #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
workspaceDir = "/workspace" | ||
defaultDockerFileName = "Dockerfile" | ||
layerTarFileName = "newlayer.tar" | ||
destination = "new_image" | ||
DOCKER_FILE_NAME_ENV_NAME = "DOCKER_FILE_NAME" | ||
IGNORE_PATHS_ENV_NAME = "IGNORE_PATHS" | ||
) | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as this information will be supplied from /layers/config/metadata.toml There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}, | ||
|
@@ -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") | ||
|
@@ -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 | ||
} | ||
|
||
|
There was a problem hiding this comment.
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