Skip to content
Open
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
2 changes: 1 addition & 1 deletion cmd/bashbrew/cmd-build.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func cmdBuild(c *cli.Context) error {
if err != nil {
fmt.Printf("Building %s (%s)\n", cacheTag, r.EntryIdentifier(entry))
if !dryRun {
commit, err := r.fetchGitRepo(arch, entry)
commit, err := r.fetchGitRepo(arch, entry, auth)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching git repo for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bashbrew/cmd-fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func cmdFetch(c *cli.Context) error {
}

for _, entryArch := range arches {
commit, err := r.fetchGitRepo(entryArch, entry)
commit, err := r.fetchGitRepo(entryArch, entry, auth)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching git repo for %q (tags %q on arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bashbrew/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822En
return scratchDockerfileMetadata()
}

commit, err := r.fetchGitRepo(arch, entry)
commit, err := r.fetchGitRepo(arch, entry, auth)
if err != nil {
return dockerfile.Metadata{}, cli.NewMultiError(fmt.Errorf("failed fetching Git repo for arch %q from entry %q", arch, entry.String()), err)
}
Expand Down
13 changes: 8 additions & 5 deletions cmd/bashbrew/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
goGit "github.com/go-git/go-git/v5"
goGitConfig "github.com/go-git/go-git/v5/config"
goGitPlumbing "github.com/go-git/go-git/v5/plumbing"

"github.com/go-git/go-git/v5/plumbing/transport/http"
)

func gitCache() string {
Expand Down Expand Up @@ -97,8 +99,8 @@ func getGitCommit(commit string) (string, error) {
return h.String(), nil
}

func (r Repo) archGitFS(arch string, entry *manifest.Manifest2822Entry) (fs.FS, error) {
commit, err := r.fetchGitRepo(arch, entry)
func (r Repo) archGitFS(arch string, entry *manifest.Manifest2822Entry, auth http.AuthMethod) (fs.FS, error) {
commit, err := r.fetchGitRepo(arch, entry, auth)
if err != nil {
return nil, fmt.Errorf("failed fetching %q: %w", r.EntryIdentifier(entry), err)
}
Expand All @@ -112,8 +114,8 @@ func (r Repo) archGitFS(arch string, entry *manifest.Manifest2822Entry) (fs.FS,
}

// returns the timestamp of the ArchGitCommit -- useful for SOURCE_DATE_EPOCH
func (r Repo) ArchGitTime(arch string, entry *manifest.Manifest2822Entry) (time.Time, error) {
f, err := r.archGitFS(arch, entry)
func (r Repo) ArchGitTime(arch string, entry *manifest.Manifest2822Entry, auth http.AuthMethod) (time.Time, error) {
f, err := r.archGitFS(arch, entry, auth)
if err != nil {
return time.Time{}, err
}
Expand Down Expand Up @@ -194,7 +196,7 @@ func gitNormalizeForTagUsage(text string) string {

var gitRepoCache = map[string]string{}

func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (string, error) {
func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry, auth http.AuthMethod) (string, error) {
cacheKey := strings.Join([]string{
entry.ArchGitRepo(arch),
entry.ArchGitFetch(arch),
Expand Down Expand Up @@ -280,6 +282,7 @@ func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (stri
err := gitRemote.Fetch(&goGit.FetchOptions{
RefSpecs: []goGitConfig.RefSpec{goGitConfig.RefSpec(fetchString)},
Tags: goGit.NoTags,
Auth: auth,

//Progress: os.Stdout,
})
Expand Down
34 changes: 32 additions & 2 deletions cmd/bashbrew/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/docker-library/bashbrew/architecture"
"github.com/docker-library/bashbrew/manifest"

"github.com/go-git/go-git/v5/plumbing/transport/http"
)

// TODO somewhere, ensure that the Docker engine we're talking to is API version 1.22+ (Docker 1.10+)
Expand All @@ -36,6 +38,10 @@ var (
debugFlag = false
noSortFlag = false

gitUsername string
gitPassword string
auth http.AuthMethod

// separated so that FlagsConfig.ApplyTo can access them
flagEnvVars = map[string]string{
"debug": "BASHBREW_DEBUG",
Expand All @@ -48,6 +54,9 @@ var (

"constraint": "BASHBREW_CONSTRAINTS",
"arch-namespace": "BASHBREW_ARCH_NAMESPACES",

"git-username": "BASHBREW_GIT_USERNAME",
"git-password": "BASHBREW_GIT_PASSWORD",
}
)

Expand Down Expand Up @@ -138,6 +147,18 @@ func main() {
EnvVar: flagEnvVars["cache"],
Usage: "where the git wizardry is stashed",
},
cli.StringFlag{
Name: "git-username",
Value: "",
EnvVar: flagEnvVars["git-username"],
Usage: "access the git repository as this user",
},
cli.StringFlag{
Name: "git-password",
Value: "",
EnvVar: flagEnvVars["git-password"],
Usage: "authenticate access to the Git repository with this password or token",
},
}

app.Before = func(c *cli.Context) error {
Expand Down Expand Up @@ -177,6 +198,15 @@ func main() {
namespace = c.GlobalString("namespace")
constraints = c.GlobalStringSlice("constraint")
exclusiveConstraints = c.GlobalBool("exclusive-constraints")
gitUsername = c.GlobalString("git-username")
gitPassword = c.GlobalString("git-password")

if gitUsername != "" && gitPassword != "" {
auth = &http.BasicAuth{
Username: gitUsername,
Password: gitPassword,
}
}

if arch == "" {
// weird edge case... ("BASHBREW_ARCH=")
Expand Down Expand Up @@ -462,7 +492,7 @@ func main() {
}

if c.Bool("sha256") {
sum, err := r.ArchGitChecksum(arch, r.TagEntry)
sum, err := r.ArchGitChecksum(arch, r.TagEntry, auth)
if err != nil {
return err
}
Expand All @@ -472,7 +502,7 @@ func main() {
if xTerm.IsTerminal(int(os.Stdout.Fd())) {
return fmt.Errorf("cowardly refusing to output a tar to a terminal")
}
return r.archContextTar(arch, r.TagEntry, os.Stdout)
return r.archContextTar(arch, r.TagEntry, auth, os.Stdout)
}
},

Expand Down
10 changes: 6 additions & 4 deletions cmd/bashbrew/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import (

"github.com/docker-library/bashbrew/manifest"
"github.com/docker-library/bashbrew/pkg/tarscrub"

"github.com/go-git/go-git/v5/plumbing/transport/http"
)

func (r Repo) archContextTar(arch string, entry *manifest.Manifest2822Entry, w io.Writer) error {
f, err := r.archGitFS(arch, entry)
func (r Repo) archContextTar(arch string, entry *manifest.Manifest2822Entry, auth http.AuthMethod, w io.Writer) error {
f, err := r.archGitFS(arch, entry, auth)
if err != nil {
return err
}

return tarscrub.WriteTar(f, w)
}

func (r Repo) ArchGitChecksum(arch string, entry *manifest.Manifest2822Entry) (string, error) {
func (r Repo) ArchGitChecksum(arch string, entry *manifest.Manifest2822Entry, auth http.AuthMethod) (string, error) {
h := sha256.New()
err := r.archContextTar(arch, entry, h)
err := r.archContextTar(arch, entry, auth, h)
if err != nil {
return "", err
}
Expand Down