Created
January 28, 2020 14:29
-
-
Save imjasonh/99e51197477ee05913519e7dab40fe9e to your computer and use it in GitHub Desktop.
Sketch of change to migrate `git-init` to script mode (https://github.com/tektoncd/pipeline/issues/1961)
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
// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input. | |
func (s *GitResource) GetInputTaskModifier(_ *TaskSpec, path string) (TaskModifier, error) { | |
return &InternalTaskModifier{ | |
StepsToPrepend: []Step{{ | |
Container: corev1.Container{ | |
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(gitSource + "-" + s.Name), | |
Image: s.GitImage, | |
WorkingDir: pipeline.WorkspaceDir, | |
// This is used to populate the ResourceResult status. | |
Env: []corev1.EnvVar{{ | |
Name: "TEKTON_RESOURCE_NAME", | |
Value: s.Name, | |
}, { | |
Name: "URL", | |
Value: s.URL, | |
}, { | |
Name: "REVISION", | |
Value: s.Revision, | |
}, { | |
Name: "PATH", | |
Value: s.Path, | |
}}, | |
}, | |
Script: `#!/usr/bin/env bash | |
set -euxo pipefail | |
if [[ ${PATH} != "" ]]; do | |
git init ${PATH} | |
cd ${PATH} | |
else | |
git init | |
done | |
git remote add origin ${URL} | |
# TODO: sslVerify | |
# TODO: submodules=false | |
git fetch --recurse-submodules=yes origin ${REVISION} | |
# TODO: depth | |
# TODO: if git fetch failed, do a full clone and git checkout | |
git reset --hard FETCH_HEAD | |
# Write git commit SHA to termination message path. | |
commit=$(git rev-parse HEAD) | |
echo "commit ${commit}" >> /tekton/termination | |
`, | |
}}, | |
}, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment