mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 07:08:24 +02:00
Merge master, refactor to work with ARG
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
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.
|
||||
@@ -45,7 +42,7 @@ import (
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func DoBuild(dockerfilePath, srcContext, snapshotMode string) (name.Reference, v1.Image, error) {
|
||||
func DoBuild(dockerfilePath, srcContext, snapshotMode string, args []string) (name.Reference, v1.Image, error) {
|
||||
// Parse dockerfile and unpack base image to root
|
||||
d, err := ioutil.ReadFile(dockerfilePath)
|
||||
if err != nil {
|
||||
@@ -103,7 +100,7 @@ func DoBuild(dockerfilePath, srcContext, snapshotMode string) (name.Reference, v
|
||||
if err := resolveOnBuild(&stage, &imageConfig.Config); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
buildArgs := dockerfile.NewBuildArgs(args)
|
||||
for _, cmd := range stage.Commands {
|
||||
dockerCommand, err := commands.GetCommand(cmd, srcContext)
|
||||
if err != nil {
|
||||
@@ -112,7 +109,7 @@ func DoBuild(dockerfilePath, srcContext, snapshotMode string) (name.Reference, v
|
||||
if dockerCommand == nil {
|
||||
continue
|
||||
}
|
||||
if err := dockerCommand.ExecuteCommand(&imageConfig.Config); err != nil {
|
||||
if err := dockerCommand.ExecuteCommand(&imageConfig.Config, buildArgs); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !finalStage {
|
||||
@@ -157,7 +154,7 @@ func DoBuild(dockerfilePath, srcContext, snapshotMode string) (name.Reference, v
|
||||
}
|
||||
return ref, sourceImage, nil
|
||||
}
|
||||
if err := saveStageDependencies(index, stages); err != nil {
|
||||
if err := saveStageDependencies(index, stages, buildArgs); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// Delete the filesystem
|
||||
@@ -184,9 +181,9 @@ func DoPush(ref name.Reference, image v1.Image, destination string) error {
|
||||
}
|
||||
return remote.Write(destRef, image, pushAuth, http.DefaultTransport, wo)
|
||||
}
|
||||
func saveStageDependencies(index int, stages []instructions.Stage) error {
|
||||
func saveStageDependencies(index int, stages []instructions.Stage, buildArgs *dockerfile.BuildArgs) error {
|
||||
// First, get the files in this stage later stages will need
|
||||
dependencies, err := dockerfile.Dependencies(index, stages)
|
||||
dependencies, err := dockerfile.Dependencies(index, stages, buildArgs)
|
||||
logrus.Infof("saving dependencies %s", dependencies)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user