Merge pull request #1153 from why-xn/master
Checkout a specific git commit
This commit is contained in:
commit
1bf66ef435
|
|
@ -164,7 +164,7 @@ When running kaniko, use the `--context` flag with the appropriate prefix to spe
|
||||||
| GCS Bucket | gs://[bucket name]/[path to .tar.gz] | `gs://kaniko-bucket/path/to/context.tar.gz` |
|
| GCS Bucket | gs://[bucket name]/[path to .tar.gz] | `gs://kaniko-bucket/path/to/context.tar.gz` |
|
||||||
| S3 Bucket | s3://[bucket name]/[path to .tar.gz] | `s3://kaniko-bucket/path/to/context.tar.gz` |
|
| S3 Bucket | s3://[bucket name]/[path to .tar.gz] | `s3://kaniko-bucket/path/to/context.tar.gz` |
|
||||||
| Azure Blob Storage| https://[account].[azureblobhostsuffix]/[container]/[path to .tar.gz] | `https://myaccount.blob.core.windows.net/container/path/to/context.tar.gz` |
|
| Azure Blob Storage| https://[account].[azureblobhostsuffix]/[container]/[path to .tar.gz] | `https://myaccount.blob.core.windows.net/container/path/to/context.tar.gz` |
|
||||||
| Git Repository | git://[repository url][#reference] | `git://github.com/acme/myproject.git#refs/heads/mybranch` |
|
| Git Repository | git://[repository url][#reference][#commit-id] | `git://github.com/acme/myproject.git#refs/heads/mybranch#<desired-commit-id>` |
|
||||||
|
|
||||||
If you don't specify a prefix, kaniko will assume a local directory.
|
If you don't specify a prefix, kaniko will assume a local directory.
|
||||||
For example, to use a GCS bucket called `kaniko-bucket`, you would pass in `--context=gs://kaniko-bucket/path/to/context.tar.gz`.
|
For example, to use a GCS bucket called `kaniko-bucket`, you would pass in `--context=gs://kaniko-bucket/path/to/context.tar.gz`.
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,29 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
options.ReferenceName = plumbing.ReferenceName(parts[1])
|
options.ReferenceName = plumbing.ReferenceName(parts[1])
|
||||||
}
|
}
|
||||||
_, err := git.PlainClone(directory, false, &options)
|
r, err := git.PlainClone(directory, false, &options)
|
||||||
|
|
||||||
|
if err == nil && len(parts) > 2 {
|
||||||
|
// ... retrieving the commit being pointed by HEAD
|
||||||
|
_, err := r.Head()
|
||||||
|
if err != nil {
|
||||||
|
return directory, err
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := r.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return directory, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... checking out to desired commit
|
||||||
|
err = w.Checkout(&git.CheckoutOptions{
|
||||||
|
Hash: plumbing.NewHash(parts[2]),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return directory, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return directory, err
|
return directory, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue