Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit addf04f

Browse files
committed
wip1
1 parent 034ac9e commit addf04f

1 file changed

Lines changed: 80 additions & 59 deletions

File tree

integration/integration_test.go

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
"github.com/google/go-containerregistry/pkg/name"
3434
"github.com/google/go-containerregistry/pkg/v1/daemon"
35-
"golang.org/x/sync/errgroup"
3635

3736
"github.com/GoogleContainerTools/kaniko/pkg/timing"
3837
"github.com/GoogleContainerTools/kaniko/pkg/util"
@@ -42,40 +41,6 @@ import (
4241
var config = initGCPConfig()
4342
var imageBuilder *DockerFileBuilder
4443

45-
type gcpConfig struct {
46-
gcsBucket string
47-
imageRepo string
48-
onbuildBaseImage string
49-
hardlinkBaseImage string
50-
}
51-
52-
type imageDetails struct {
53-
name string
54-
numLayers int
55-
digest string
56-
}
57-
58-
func (i imageDetails) String() string {
59-
return fmt.Sprintf("Image: [%s] Digest: [%s] Number of Layers: [%d]", i.name, i.digest, i.numLayers)
60-
}
61-
62-
func initGCPConfig() *gcpConfig {
63-
var c gcpConfig
64-
flag.StringVar(&c.gcsBucket, "bucket", "gs://kaniko-test-bucket", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.")
65-
flag.StringVar(&c.imageRepo, "repo", "gcr.io/kaniko-test", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo.")
66-
flag.Parse()
67-
68-
if c.gcsBucket == "" || c.imageRepo == "" {
69-
log.Fatalf("You must provide a gcs bucket (\"%s\" was provided) and a docker repo (\"%s\" was provided)", c.gcsBucket, c.imageRepo)
70-
}
71-
if !strings.HasSuffix(c.imageRepo, "/") {
72-
c.imageRepo = c.imageRepo + "/"
73-
}
74-
c.onbuildBaseImage = c.imageRepo + "onbuild-base:latest"
75-
c.hardlinkBaseImage = c.imageRepo + "hardlink-base:latest"
76-
return &c
77-
}
78-
7944
const (
8045
daemonPrefix = "daemon://"
8146
dockerfilesPath = "dockerfiles"
@@ -102,19 +67,6 @@ const (
10267
]`
10368
)
10469

105-
func meetsRequirements() bool {
106-
requiredTools := []string{"container-diff", "gsutil"}
107-
hasRequirements := true
108-
for _, tool := range requiredTools {
109-
_, err := exec.LookPath(tool)
110-
if err != nil {
111-
fmt.Printf("You must have %s installed and on your PATH\n", tool)
112-
hasRequirements = false
113-
}
114-
}
115-
return hasRequirements
116-
}
117-
11870
func TestMain(m *testing.M) {
11971
if !meetsRequirements() {
12072
fmt.Println("Missing required tools")
@@ -188,19 +140,20 @@ func TestMain(m *testing.M) {
188140
}
189141
imageBuilder = NewDockerFileBuilder(dockerfiles)
190142

191-
g := errgroup.Group{}
192-
for dockerfile := range imageBuilder.FilesBuilt {
193-
df := dockerfile
194-
g.Go(func() error {
195-
return imageBuilder.BuildImage(config.imageRepo, config.gcsBucket, dockerfilesPath, df)
196-
})
197-
}
198-
if err := g.Wait(); err != nil {
199-
fmt.Printf("Error building images: %s", err)
200-
os.Exit(1)
201-
}
143+
//g := errgroup.Group{}
144+
//for dockerfile := range imageBuilder.FilesBuilt {
145+
// df := dockerfile
146+
// g.Go(func() error {
147+
// return imageBuilder.BuildImage(config.imageRepo, config.gcsBucket, dockerfilesPath, df)
148+
// })
149+
//}
150+
//if err := g.Wait(); err != nil {
151+
// fmt.Printf("Error building images: %s", err)
152+
// os.Exit(1)
153+
//}
202154
os.Exit(m.Run())
203155
}
156+
204157
func TestRun(t *testing.T) {
205158
for dockerfile := range imageBuilder.FilesBuilt {
206159
t.Run("test_"+dockerfile, func(t *testing.T) {
@@ -212,6 +165,9 @@ func TestRun(t *testing.T) {
212165
if _, ok := imageBuilder.TestCacheDockerfiles[dockerfile]; ok {
213166
t.SkipNow()
214167
}
168+
169+
imageBuilder.FilesBuilt[dockerfile] = buildImage(t, dockerfile, imageBuilder)
170+
215171
dockerImage := GetDockerImage(config.imageRepo, dockerfile)
216172
kanikoImage := GetKanikoImage(config.imageRepo, dockerfile)
217173

@@ -329,10 +285,14 @@ func TestLayers(t *testing.T) {
329285
for dockerfile := range imageBuilder.FilesBuilt {
330286
t.Run("test_layer_"+dockerfile, func(t *testing.T) {
331287
dockerfile := dockerfile
288+
332289
t.Parallel()
333290
if _, ok := imageBuilder.DockerfilesToIgnore[dockerfile]; ok {
334291
t.SkipNow()
335292
}
293+
294+
imageBuilder.FilesBuilt[dockerfile] = buildImage(t, dockerfile, imageBuilder)
295+
336296
// Pull the kaniko image
337297
dockerImage := GetDockerImage(config.imageRepo, dockerfile)
338298
kanikoImage := GetKanikoImage(config.imageRepo, dockerfile)
@@ -348,6 +308,20 @@ func TestLayers(t *testing.T) {
348308
}
349309
}
350310

311+
func buildImage(t *testing.T, dockerfile string, imageBuilder *DockerFileBuilder) bool {
312+
if imageBuilder.FilesBuilt[dockerfile] {
313+
return true
314+
}
315+
316+
if err := imageBuilder.BuildImage(
317+
config.imageRepo, config.gcsBucket, dockerfilesPath, dockerfile,
318+
); err != nil {
319+
t.Errorf("Error building image: %s", err)
320+
t.FailNow()
321+
}
322+
return true
323+
}
324+
351325
// Build each image with kaniko twice, and then make sure they're exactly the same
352326
func TestCache(t *testing.T) {
353327
populateVolumeCache()
@@ -522,3 +496,50 @@ func logBenchmarks(benchmark string) error {
522496
}
523497
return nil
524498
}
499+
500+
type gcpConfig struct {
501+
gcsBucket string
502+
imageRepo string
503+
onbuildBaseImage string
504+
hardlinkBaseImage string
505+
}
506+
507+
type imageDetails struct {
508+
name string
509+
numLayers int
510+
digest string
511+
}
512+
513+
func (i imageDetails) String() string {
514+
return fmt.Sprintf("Image: [%s] Digest: [%s] Number of Layers: [%d]", i.name, i.digest, i.numLayers)
515+
}
516+
517+
func initGCPConfig() *gcpConfig {
518+
var c gcpConfig
519+
flag.StringVar(&c.gcsBucket, "bucket", "gs://kaniko-test-bucket", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.")
520+
flag.StringVar(&c.imageRepo, "repo", "gcr.io/kaniko-test", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo.")
521+
flag.Parse()
522+
523+
if c.gcsBucket == "" || c.imageRepo == "" {
524+
log.Fatalf("You must provide a gcs bucket (\"%s\" was provided) and a docker repo (\"%s\" was provided)", c.gcsBucket, c.imageRepo)
525+
}
526+
if !strings.HasSuffix(c.imageRepo, "/") {
527+
c.imageRepo = c.imageRepo + "/"
528+
}
529+
c.onbuildBaseImage = c.imageRepo + "onbuild-base:latest"
530+
c.hardlinkBaseImage = c.imageRepo + "hardlink-base:latest"
531+
return &c
532+
}
533+
534+
func meetsRequirements() bool {
535+
requiredTools := []string{"container-diff", "gsutil"}
536+
hasRequirements := true
537+
for _, tool := range requiredTools {
538+
_, err := exec.LookPath(tool)
539+
if err != nil {
540+
fmt.Printf("You must have %s installed and on your PATH\n", tool)
541+
hasRequirements = false
542+
}
543+
}
544+
return hasRequirements
545+
}

0 commit comments

Comments
 (0)