Skip to content

Instantly share code, notes, and snippets.

@imjasonh
Created January 28, 2020 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imjasonh/99e51197477ee05913519e7dab40fe9e to your computer and use it in GitHub Desktop.
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)
// 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