-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
402 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2019 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. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cache | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
|
||
"github.com/GoogleContainerTools/kaniko/pkg/config" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
) | ||
|
||
func ExampleWarmer_Warm() { | ||
tarBuf := new(bytes.Buffer) | ||
manifestBuf := new(bytes.Buffer) | ||
w := &Warmer{ | ||
Remote: remote.Image, | ||
Local: LocalSource, | ||
TarWriter: tarBuf, | ||
ManifestWriter: manifestBuf, | ||
} | ||
|
||
options := &config.WarmerOptions{} | ||
|
||
digest, err := w.Warm("ubuntu:latest", options) | ||
if err != nil { | ||
if !IsAlreadyCached(err) { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
log.Printf("digest %v tar len %d\nmanifest:\n%s\n", digest, tarBuf.Len(), manifestBuf.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2019 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. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cache | ||
|
||
// IsAlreadyCached returns true if the supplied error is of the type AlreadyCachedErr | ||
// otherwise it returns false. | ||
func IsAlreadyCached(err error) bool { | ||
switch err.(type) { | ||
case AlreadyCachedErr: | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// AlreadyCachedErr is returned when the Docker image requested for caching is already | ||
// present in the cache. | ||
type AlreadyCachedErr struct { | ||
msg string | ||
} | ||
|
||
func (a AlreadyCachedErr) Error() string { | ||
return a.msg | ||
} | ||
|
||
// IsNotFound returns true if the supplied error is of the type NotFoundErr | ||
// otherwise it returns false. | ||
func IsNotFound(e error) bool { | ||
switch e.(type) { | ||
case NotFoundErr: | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// NotFoundErr is returned when the requested Docker image is not present in the cache. | ||
type NotFoundErr struct { | ||
msg string | ||
} | ||
|
||
func (e NotFoundErr) Error() string { | ||
return e.msg | ||
} | ||
|
||
// IsExpired returns true if the supplied error is of the type ExpiredErr | ||
// otherwise it returns false. | ||
func IsExpired(e error) bool { | ||
switch e.(type) { | ||
case ExpiredErr: | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// ExpiredErr is returned when the requested Docker image is present in the cache, but is | ||
// expired according to the supplied TTL. | ||
type ExpiredErr struct { | ||
msg string | ||
} | ||
|
||
func (e ExpiredErr) Error() string { | ||
return e.msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.