forked from shipwright-io/cli
-
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.
Local source code feature (using bundle images)
Reference shipwright-io/build#717 Add `bundle` package that contains convenience code to push a local source code directory as a bundle image to a container registry. Add new flags for container image and local directory settings. Add `github.com/google/go-containerregistry`. Add `github.com/schollz/progressbar/v3`.
- Loading branch information
1 parent
bc1fe60
commit d4069d8
Showing
803 changed files
with
112,204 additions
and
12,468 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package bundle | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/go-containerregistry/pkg/authn" | ||
"github.com/google/go-containerregistry/pkg/name" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
progressbar "github.com/schollz/progressbar/v3" | ||
"github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
) | ||
|
||
func Push(ctx context.Context, io *genericclioptions.IOStreams, localDirectory string, targetImage string) error { | ||
tag, err := name.NewTag(targetImage) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
auth, err := authn.DefaultKeychain.Resolve(tag.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
updates := make(chan v1.Update, 1) | ||
done := make(chan struct{}, 1) | ||
go func() { | ||
var progress *progressbar.ProgressBar | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
|
||
case <-done: | ||
return | ||
|
||
case update, ok := <-updates: | ||
if !ok { | ||
return | ||
} | ||
|
||
if progress == nil { | ||
progress = progressbar.NewOptions(int(update.Total), | ||
progressbar.OptionSetWriter(io.ErrOut), | ||
progressbar.OptionEnableColorCodes(true), | ||
progressbar.OptionShowBytes(true), | ||
progressbar.OptionSetWidth(15), | ||
progressbar.OptionSetPredictTime(false), | ||
progressbar.OptionSetDescription("Uploading local source..."), | ||
progressbar.OptionSetTheme(progressbar.Theme{ | ||
Saucer: "[green]=[reset]", | ||
SaucerHead: "[green]>[reset]", | ||
SaucerPadding: " ", | ||
BarStart: "[", | ||
BarEnd: "]"}), | ||
progressbar.OptionClearOnFinish(), | ||
) | ||
defer progress.Close() | ||
} | ||
|
||
progress.ChangeMax64(update.Total) | ||
progress.Set64(update.Complete) | ||
} | ||
} | ||
}() | ||
|
||
fmt.Fprintf(io.Out, "Bundling %q as %q ...\n", localDirectory, targetImage) | ||
_, err = sources.Bundle( | ||
tag, | ||
localDirectory, | ||
remote.WithAuth(auth), | ||
remote.WithProgress(updates), | ||
) | ||
|
||
done <- struct{}{} | ||
return err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.