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

Improve submodule support #1361

Merged
merged 5 commits into from
Oct 26, 2023
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
38 changes: 33 additions & 5 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5946,6 +5946,13 @@
"os": {
"type": "string"
},
"signaturePaths": {
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.CosignSignature"
}
},
"stack": {
"default": {},
"$ref": "#/definitions/kpack.core.v1alpha1.BuildStack"
Expand Down Expand Up @@ -6193,13 +6200,11 @@
"kpack.build.v1alpha2.ClusterBuildpackSpec": {
"type": "object",
"properties": {
"image": {
"type": "string"
},
"serviceAccountRef": {
"$ref": "#/definitions/io.k8s.api.core.v1.ObjectReference"
},
"source": {
"default": {},
"x-kubernetes-list-type": "",
"$ref": "#/definitions/kpack.core.v1alpha1.ImageSource"
}
}
},
Expand Down Expand Up @@ -6498,6 +6503,23 @@
}
}
},
"kpack.build.v1alpha2.CosignSignature": {
"type": "object",
"required": [
"signingSecret",
"targetDigest"
],
"properties": {
"signingSecret": {
"type": "string",
"default": ""
},
"targetDigest": {
"type": "string",
"default": ""
}
}
},
"kpack.build.v1alpha2.Image": {
"type": "object",
"required": [
Expand Down Expand Up @@ -7193,6 +7215,9 @@
"revision"
],
"properties": {
"initializeSubmodules": {
"type": "boolean"
},
"revision": {
"type": "string",
"default": ""
Expand Down Expand Up @@ -7310,6 +7335,9 @@
"type"
],
"properties": {
"initializeSubmodules": {
"type": "boolean"
},
"revision": {
"type": "string",
"default": ""
Expand Down
38 changes: 27 additions & 11 deletions cmd/build-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ var (
imageTag = flag.String("imageTag", os.Getenv("IMAGE_TAG"), "tag of image that will get created by the lifecycle")
runImage = flag.String("runImage", os.Getenv("RUN_IMAGE"), "The base image from which application images are built.")

gitURL = flag.String("git-url", os.Getenv("GIT_URL"), "The url of the Git repository to initialize.")
gitRevision = flag.String("git-revision", os.Getenv("GIT_REVISION"), "The Git revision to make the repository HEAD.")
blobURL = flag.String("blob-url", os.Getenv("BLOB_URL"), "The url of the source code blob.")
stripComponents = flag.Int("strip-components", getenvInt("BLOB_STRIP_COMPONENTS", 0), "The number of directory components to strip from the blobs content when extracting.")
registryImage = flag.String("registry-image", os.Getenv("REGISTRY_IMAGE"), "The registry location of the source code image.")
hostName = flag.String("dns-probe-hostname", os.Getenv("DNS_PROBE_HOSTNAME"), "hostname to dns poll")
sourceSubPath = flag.String("source-sub-path", os.Getenv("SOURCE_SUB_PATH"), "the subpath inside the source directory that will be the buildpack workspace")
buildChanges = flag.String("build-changes", os.Getenv("BUILD_CHANGES"), "JSON string of build changes and their reason")
descriptorPath = flag.String("project-descriptor-path", os.Getenv("PROJECT_DESCRIPTOR_PATH"), "path to project descriptor file")
gitURL = flag.String("git-url", os.Getenv("GIT_URL"), "The url of the Git repository to initialize.")
gitRevision = flag.String("git-revision", os.Getenv("GIT_REVISION"), "The Git revision to make the repository HEAD.")
gitInitializeSubmodules = flag.Bool("git-initialize-submodules", getenvBool("GIT_INITIALIZE_SUBMODULES"), "Initialize submodules during git clone")
blobURL = flag.String("blob-url", os.Getenv("BLOB_URL"), "The url of the source code blob.")
stripComponents = flag.Int("strip-components", getenvInt("BLOB_STRIP_COMPONENTS", 0), "The number of directory components to strip from the blobs content when extracting.")
registryImage = flag.String("registry-image", os.Getenv("REGISTRY_IMAGE"), "The registry location of the source code image.")
hostName = flag.String("dns-probe-hostname", os.Getenv("DNS_PROBE_HOSTNAME"), "hostname to dns poll")
sourceSubPath = flag.String("source-sub-path", os.Getenv("SOURCE_SUB_PATH"), "the subpath inside the source directory that will be the buildpack workspace")
buildChanges = flag.String("build-changes", os.Getenv("BUILD_CHANGES"), "JSON string of build changes and their reason")
descriptorPath = flag.String("project-descriptor-path", os.Getenv("PROJECT_DESCRIPTOR_PATH"), "path to project descriptor file")

builderImage = flag.String("builder-image", os.Getenv("BUILDER_IMAGE"), "The builder image used to build the application")
builderName = flag.String("builder-name", os.Getenv("BUILDER_NAME"), "The builder name provided during creation")
Expand Down Expand Up @@ -207,9 +208,15 @@ func fetchSource(logger *log.Logger, keychain authn.Keychain) error {
return err
}

var initializeSubmodules bool
if gitInitializeSubmodules != nil {
initializeSubmodules = *gitInitializeSubmodules
}

fetcher := git.Fetcher{
Logger: logger,
Keychain: gitKeychain,
Logger: logger,
Keychain: gitKeychain,
InitializeSubmodules: initializeSubmodules,
}
return fetcher.Fetch(appDir, *gitURL, *gitRevision, projectMetadataDir)
case *blobURL != "":
Expand Down Expand Up @@ -297,3 +304,12 @@ func getenvInt(key string, defaultValue int) int {
}
return atoi
}

func getenvBool(key string) bool {
value := os.Getenv(key)
b, err := strconv.ParseBool(value)
if err != nil {
return false
}
return b
}
2 changes: 2 additions & 0 deletions docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ The `source` field is a composition of a source code location and a `subpath`. I
git:
url: ""
revision: ""
initializeSubmodules: false
subPath: ""
```
- `git`: (Source Code is a git repository)
- `url`: The git repository url. Both https and ssh formats are supported; with ssh format requiring a [ssh secret](secrets.md#git-secrets).
- `revision`: The git revision to use. This value may be a commit sha, branch name, or tag.
- `initializeSubmodules`: Initialize submodules inside repo, recurses up to a max depth of 10 submodules.
- `subPath`: A subdirectory within the source folder where application code resides. Can be ignored if the source code resides at the `root` level.

* Blob
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
Git: &corev1alpha1.Git{
URL: "giturl.com/git.git",
Revision: "gitrev1234",
InitializeSubmodules: true,
},
},
Cache: &buildapi.BuildCacheConfig{
Expand Down Expand Up @@ -654,6 +655,11 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
Value: build.Spec.Source.Git.Revision,
},
)
assert.Contains(t, pod.Spec.InitContainers[0].Env,
corev1.EnvVar{
Name: "GIT_INITIALIZE_SUBMODULES",
Value: fmt.Sprintf("%v", build.Spec.Source.Git.InitializeSubmodules),
})
})

it("configures prepare with the blob source", func() {
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/build/v1alpha2/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ type BuildSpec struct {
Cosign *CosignConfig `json:"cosign,omitempty"`
DefaultProcess string `json:"defaultProcess,omitempty"`
// +listType
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
}

func (bs *BuildSpec) RegistryCacheTag() string {
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/build/v1alpha2/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ type ImageBuild struct {
Env []corev1.EnvVar `json:"env,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +listType
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
BuildTimeout *int64 `json:"buildTimeout,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`
BuildTimeout *int64 `json:"buildTimeout,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/build/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions pkg/apis/core/v1alpha1/source_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type Source interface {
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=true
type Git struct {
URL string `json:"url"`
Revision string `json:"revision"`
URL string `json:"url"`
Revision string `json:"revision"`
InitializeSubmodules bool `json:"initializeSubmodules,omitempty"`
}

func (g *Git) BuildEnvVars() []corev1.EnvVar {
Expand All @@ -48,6 +49,10 @@ func (g *Git) BuildEnvVars() []corev1.EnvVar {
Name: "GIT_REVISION",
Value: g.Revision,
},
{
Name: "GIT_INITIALIZE_SUBMODULES",
Value: strconv.FormatBool(g.InitializeSubmodules),
},
}
}

Expand Down Expand Up @@ -165,17 +170,19 @@ const (
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=true
type ResolvedGitSource struct {
URL string `json:"url"`
Revision string `json:"revision"`
SubPath string `json:"subPath,omitempty"`
Type GitSourceKind `json:"type"`
URL string `json:"url"`
Revision string `json:"revision"`
SubPath string `json:"subPath,omitempty"`
Type GitSourceKind `json:"type"`
InitializeSubmodules bool `json:"initializeSubmodules,omitempty"`
}

func (gs *ResolvedGitSource) SourceConfig() SourceConfig {
return SourceConfig{
Git: &Git{
URL: gs.URL,
Revision: gs.Revision,
URL: gs.URL,
Revision: gs.Revision,
InitializeSubmodules: gs.InitializeSubmodules,
},
SubPath: gs.SubPath,
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading