Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-level repos for Artifact Registry #5053

Merged
merged 3 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/content/en/docs/environment/image-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ the full image name is rewritten on top of the default-repo so similar image nam

Automated image name rewriting strategies are determined based on the default-repo and the original image repository:

* default-repo does not begin with gcr.io
* default-repo domain does not contain `gcr.io` or `-docker.pkg.dev`
* **strategy**: escape & concat & truncate to 256

```
Expand All @@ -49,7 +49,7 @@ Automated image name rewriting strategies are determined based on the default-re
rewritten image: aws_account_id.dkr.ecr.region.amazonaws.com/gcr_io_k8s-skaffold_skaffold-example1
```

* default-repo begins with "gcr.io" (special case - as GCR allows for infinite deep image repo names)
* default-repo contain `gcr.io` or `-docker.pkg.dev` (special cases - as GCR and AR allow for arbitrarily deep directory structure in image repo names)
* **strategy**: concat unless prefix matches
* **example1**: prefix doesn't match:

Expand All @@ -63,14 +63,14 @@ Automated image name rewriting strategies are determined based on the default-re
```
original image: gcr.io/k8s-skaffold/skaffold-example1
default-repo: gcr.io/k8s-skaffold
rewritten image: gcr.io/k8s-skaffold/skaffold-example1
rewritten image: gcr.io/k8s-skaffold/skaffold-example1
```
* **example3**: shared prefix:

```
original image: gcr.io/k8s-skaffold/skaffold-example1
default-repo: gcr.io/k8s-skaffold/myimage
rewritten image: gcr.io/k8s-skaffold/myimage/skaffold-example1
rewritten image: gcr.io/k8s-skaffold/myimage/skaffold-example1
```

## Insecure image registries
Expand All @@ -86,15 +86,15 @@ There are several levels of granularity to allow insecure communication with som
```bash
skaffold dev --insecure-registry insecure1.io --insecure-registry insecure2.io
```

1. Per Skaffold run via `SKAFFOLD_INSECURE_REGISTRY` environment variable

```bash
SKAFFOLD_INSECURE_REGISTRY='insecure1.io,insecure2.io' skaffold dev
```

1. Per project via the Skaffold pipeline config `skaffold.yaml`

```yaml
build:
insecureRegistries:
Expand All @@ -108,8 +108,8 @@ There are several levels of granularity to allow insecure communication with som
skaffold config set insecure-registries insecure1.io # for the current kube-context
skaffold config set --global insecure-registries insecure2.io # for any kube-context
```

Note that multiple set commands _add_ to the existing list of insecure registries.
To clear the list, run `skaffold config unset insecure-registries`.

Skaffold will join the lists of insecure registries, if configured via multiple sources.
9 changes: 7 additions & 2 deletions pkg/skaffold/docker/default_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ package docker
import (
"regexp"
"strings"

"github.com/docker/distribution/reference"
)

const maxLength = 255

var (
escapeRegex = regexp.MustCompile(`[/._:@]`)
prefixRegex = regexp.MustCompile(`(.*\.)?gcr.io/[a-zA-Z0-9-_]+/?`)
// gcpProjectIDRegex matches a GCP Project ID as according to console.cloud.google.com.
gcpProjectIDRegex = `[a-z][a-z0-9-]{4,28}[a-z0-9]`
// prefixRegex is used to match a GCR or AR reference, which must have a project ID.
prefixRegex = regexp.MustCompile(`^` + reference.DomainRegexp.String() + `/` + gcpProjectIDRegex + `/?`)
)

func SubstituteDefaultRepoIntoImage(defaultRepo string, image string) (string, error) {
Expand Down Expand Up @@ -68,7 +73,7 @@ func replace(defaultRepo string, baseImage string) string {
}

func registrySupportsMultiLevelRepos(repo string) bool {
return strings.Contains(repo, "gcr.io")
return strings.Contains(repo, "gcr.io") || strings.Contains(repo, "-docker.pkg.dev")
}

func truncate(image string) string {
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/docker/default_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func TestImageReplaceDefaultRepo(t *testing.T) {
defaultRepo: "gcr.io/default",
expectedImage: "gcr.io/default/gcr.io/some/registry",
},
{
description: "basic AR concatenation",
image: "github.com/org/app",
defaultRepo: "us-central1-docker.pkg.dev/default",
expectedImage: "us-central1-docker.pkg.dev/default/github.com/org/app",
},
{
description: "no default repo set",
image: "gcr.io/some/registry",
Expand Down