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

Restore import path with uppercase characters in custom build ko example #6286

Merged
merged 4 commits into from
Aug 11, 2021
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
10 changes: 7 additions & 3 deletions integration/examples/custom/build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/usr/bin/env bash
set -e

if ! [ -x "$(command -v ko)" ]; then
if ! [ -x "$(go env GOPATH)/bin/ko" ]; then
pushd $(mktemp -d)
go mod init tmp; GOFLAGS= go get github.com/google/ko/cmd/ko@v0.6.0
curl -L https://github.com/google/ko/archive/v0.8.3.tar.gz | tar --strip-components 1 -zx
go build -o $(go env GOPATH)/bin/ko .
popd
fi

output=$(ko publish --local --preserve-import-paths --tags= . | tee)
output=$($(go env GOPATH)/bin/ko publish --local --preserve-import-paths --tags= . | tee)
ref=$(echo "$output" | tail -n1)

docker tag "$ref" "$IMAGE"
if [[ "${PUSH_IMAGE}" == "true" ]]; then
echo "Pushing $IMAGE"
docker push "$IMAGE"
else
echo "Not pushing $IMAGE"
fi
6 changes: 3 additions & 3 deletions integration/examples/custom/k8s/pod.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: getting-started
name: getting-started-custom
spec:
containers:
- name: getting-started
image: github.com/googlecontainertools/skaffold/examples/custom
- name: getting-started-custom
image: ko://github.com/GoogleContainerTools/skaffold/examples/custom
2 changes: 1 addition & 1 deletion integration/examples/custom/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: skaffold/v2beta21
kind: Config
build:
artifacts:
- image: github.com/googlecontainertools/skaffold/examples/custom
- image: ko://github.com/GoogleContainerTools/skaffold/examples/custom
custom:
buildCommand: ./build.sh
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var tests = []struct {
{
description: "custom builder",
dir: "examples/custom",
pods: []string{"getting-started"},
pods: []string{"getting-started-custom"},
},
{
description: "buildpacks Go",
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/kubernetes/loader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/client-go/tools/clientcmd/api"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
Expand Down Expand Up @@ -60,7 +61,7 @@ func NewImageLoader(kubeContext string, cli *kubectl.CLI) *ImageLoader {
func imagesToLoad(localImages, deployerImages, images []graph.Artifact) []graph.Artifact {
local := map[string]bool{}
for _, image := range localImages {
local[image.ImageName] = true
local[docker.SanitizeImageName(image.ImageName)] = true
}

tracked := map[string]bool{}
Expand All @@ -72,7 +73,7 @@ func imagesToLoad(localImages, deployerImages, images []graph.Artifact) []graph.

var res []graph.Artifact
for _, image := range images {
if tracked[image.ImageName] {
if tracked[docker.SanitizeImageName(image.ImageName)] {
res = append(res, image)
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/kubernetes/loader/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ func TestImagesToLoad(t *testing.T) {
builtImages: []graph.Artifact{{ImageName: "image1", Tag: "foo"}},
expectedImages: nil,
},
{
name: "single image marked as local, with ko prefix and Go import path with uppercase characters",
localImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
deployerImages: []graph.Artifact{{ImageName: "example.com/organization/image1", Tag: "Foo"}},
builtImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
expectedImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
},
{
name: "two images marked as local",
localImages: []graph.Artifact{{ImageName: "image1", Tag: "foo"}, {ImageName: "image2", Tag: "bar"}},
Expand Down