forked from GoogleContainerTools/skaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ko): Init support for the ko builder
Adds the ko builder as an option when running `skaffold init` in a directory containing Go code. The ko builder will show up as an option for directories containing a `go.mod` file. The feature can be disabled by adding the `--XXenableKoInit=false` flag. Tracking: GoogleContainerTools#7131
- Loading branch information
Showing
13 changed files
with
196 additions
and
61 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
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
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
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,70 @@ | ||
/* | ||
Copyright 2022 The Skaffold Authors | ||
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 init | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer/build" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
) | ||
|
||
// ArtifactConfig holds information about a Ko project | ||
type ArtifactConfig struct { | ||
File string `json:"path,omitempty"` | ||
} | ||
|
||
var _ build.InitBuilder = &ArtifactConfig{} | ||
|
||
// Validate checks if the file is a Go module file. | ||
func Validate(path string) bool { | ||
return filepath.Base(path) == "go.mod" | ||
} | ||
|
||
// Name returns the name of the builder. | ||
func (c ArtifactConfig) Name() string { | ||
return "Ko" | ||
} | ||
|
||
// Describe returns the initBuilder's string representation. | ||
// This representation is used when prompting the user to choose a builder. | ||
func (c ArtifactConfig) Describe() string { | ||
return fmt.Sprintf("%s (%s)", c.Name(), c.File) | ||
} | ||
|
||
// ArtifactType returns a definition of the artifact to be built. | ||
func (c ArtifactConfig) ArtifactType(_ string) latest.ArtifactType { | ||
return latest.ArtifactType{ | ||
KoArtifact: &latest.KoArtifact{ | ||
Dependencies: &latest.KoDependencies{ | ||
Paths: []string{"**/*.go", "go.*"}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ConfiguredImage returns the target image configured by the builder, or empty string if no image is configured. | ||
func (c ArtifactConfig) ConfiguredImage() string { | ||
// Target image is not configured in Ko. | ||
return "" | ||
} | ||
|
||
// Path returns the path to the build definition. | ||
func (c ArtifactConfig) Path() string { | ||
return c.File | ||
} |
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,52 @@ | ||
/* | ||
Copyright 2022 The Skaffold Authors | ||
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 init | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/skaffold/testutil" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
path string | ||
expect bool | ||
}{ | ||
{ | ||
description: "go.mod in current directory", | ||
path: "go.mod", | ||
expect: true, | ||
}, | ||
{ | ||
description: "go.mod in subdirectory", | ||
path: "foo/go.mod", | ||
expect: true, | ||
}, | ||
{ | ||
description: "not go.mod", | ||
path: "Gopkg.toml", | ||
expect: false, | ||
}, | ||
} | ||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
t.CheckDeepEqual(test.expect, Validate(test.path)) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.