Skip to content

Commit

Permalink
pkg: prepend library when using registry mirror
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
  • Loading branch information
greut committed May 12, 2020
1 parent cb11a99 commit b2692c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Before executing a command, kaniko checks the cache for the layer.
If it exists, kaniko will pull and extract the cached layer instead of executing the command.
If not, kaniko will execute the command and then push the newly created layer to the cache.

Users can opt into caching by setting the `--cache=true` flag.
Users can opt into caching by setting the `--cache` flag.
A remote repository for storing cached layers can be provided via the `--cache-repo` flag.
If this flag isn't provided, a cached repo will be inferred from the `--destination` provided.

Expand All @@ -341,7 +341,7 @@ docker run -v $(pwd):/workspace gcr.io/kaniko-project/warmer:latest --cache-dir=

`--image` can be specified for any number of desired images.
This command will cache those images by digest in a local directory named `cache`.
Once the cache is populated, caching is opted into with the same `--cache=true` flag as above.
Once the cache is populated, caching is opted into with the same `--cache` flag as above.
The location of the local cache is provided via the `--cache-dir` flag, defaulting to `/cache` as with the cache warmer.
See the `examples` directory for how to use with kubernetes clusters and persistent cache volumes.

Expand Down Expand Up @@ -441,13 +441,13 @@ You can set it multiple times for multiple arguments.
#### --cache
Set this flag as `--cache=true` to opt into caching with kaniko.
Set this flag as `--cache` to opt into caching with kaniko.

#### --cache-dir

Set this flag to specify a local directory cache for base images. Defaults to `/cache`.

_This flag must be used in conjunction with the `--cache=true` flag._
_This flag must be used in conjunction with the `--cache` flag._

#### --cache-repo

Expand All @@ -456,7 +456,7 @@ Set this flag to specify a remote repository that will be used to store cached l
If this flag is not provided, a cache repo will be inferred from the `--destination` flag.
If `--destination=gcr.io/kaniko-project/test`, then cached layers will be stored in `gcr.io/kaniko-project/test/cache`.

_This flag must be used in conjunction with the `--cache=true` flag._
_This flag must be used in conjunction with the `--cache` flag._

#### --context-sub-path

Expand Down
2 changes: 1 addition & 1 deletion cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func cacheFlagsValid() error {
if !opts.Cache {
return nil
}
// If --cache=true and --no-push=true, then cache repo must be provided
// If --cache and --no-push, then cache repo must be provided
// since cache can't be inferred from destination
if opts.CacheRepo == "" && opts.NoPush {
return errors.New("if using cache with --no-push, specify cache repo with --cache-repo")
Expand Down
2 changes: 1 addition & 1 deletion integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (d *DockerFileBuilder) buildCachedImages(config *integrationTestConfig, cac
_, ex, _, _ := runtime.Caller(0)
cwd := filepath.Dir(ex)

cacheFlag := "--cache=true"
cacheFlag := "--cache"

for dockerfile := range d.TestCacheDockerfiles {
benchmarkEnv := "BENCHMARK_FILE=false"
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"path/filepath"
"strconv"
"strings"

"github.com/GoogleContainerTools/kaniko/pkg/timing"

Expand Down Expand Up @@ -118,6 +119,13 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
return nil, err
}

if !strings.ContainsRune(image, '/') {
ref, err = name.ParseReference("library/"+image, name.WeakValidation)
if err != nil {
return nil, err
}
}

toSet = true
}

Expand Down

0 comments on commit b2692c7

Please sign in to comment.