Giter Club home page Giter Club logo

Comments (5)

ForestEckhardt avatar ForestEckhardt commented on July 28, 2024 2

Just wanted to give a quick update on this question. Currently there is a release of the Paketo Git buildpack that allows user to configure a custom git credential manager using a service binding. Feel free to check that buildpack out and give it a test drive and see if this works out for you.

from go-mod-vendor.

ForestEckhardt avatar ForestEckhardt commented on July 28, 2024 2

With the merging of paketo-buildpacks/go#558 I believe that this workflow should now be supported! I am going to close this issue for now but if you have any further feedback feel free to either open a new issue or reopen this one!

from go-mod-vendor.

cirocosta avatar cirocosta commented on July 28, 2024

Hi!

Thanks for bringing it up, @kvedurmu !

@matthewmcnew had suggested using using service bindings for providing the credentials, so I came up with a little patch to this buildpack that allowed me to copy a .netrc injected via bindings to $HOME/.netrc where git could then read the creds to use in its transport (https)

diff --git a/build.go b/build.go
index 4736fbe..81f8977 100644
--- a/build.go
+++ b/build.go
@@ -1,6 +1,11 @@
 package gomodvendor

 import (
+       "fmt"
+       "io"
+       "os"
+       "path/filepath"
+
        "github.com/paketo-buildpacks/packit"
 )

@@ -10,10 +15,38 @@ type BuildProcess interface {
        Execute(path, workingDir string) error
 }

+func cp(src, dst string) error {
+       in, err := os.Open(src)
+       if err != nil {
+               return fmt.Errorf("open: %w", err)
+       }
+       defer in.Close()
+
+       out, err := os.Create(dst)
+       if err != nil {
+               return fmt.Errorf("create: %w", err)
+       }
+       defer out.Close()
+
+       if _, err = io.Copy(out, in); err != nil {
+               return fmt.Errorf("copy: %w", err)
+       }
+
+       return nil
+}
+
+const netrcFromBinding = "/platform/bindings/netrc/secret/.netrc"
+
 func Build(buildProcess BuildProcess, logs LogEmitter) packit.BuildFunc {
        return func(context packit.BuildContext) (packit.BuildResult, error) {
                logs.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)

+               if _, err := os.Stat(netrcFromBinding); !os.IsNotExist(err) {
+                       if err := cp(netrcFromBinding, filepath.Join(os.Getenv("HOME"), ".netrc")); err != nil {
+                               return packit.BuildResult{}, fmt.Errorf("cp: %w", err)
+                       }
+               }
+
                ok, err := buildProcess.ShouldRun(context.WorkingDir)
                if err != nil {
                        return packit.BuildResult{}, err

which then works great with kpacks use of service bindings:

#@ load("@ytt:data", "data")

---
kind: Build
apiVersion: kpack.io/v1alpha1
metadata:
  name: build
spec:
  tags: ['harbor.internal.unicorns.com/my/thing']
  serviceAccount: controllers-creds
  bindings:
    - name: netrc
      metadataRef:
        name: netrc-metadata
      secretRef:
        name: bindings-netrc
  builder:
    image: harbor.internal.unicorns.com/my/builder-with-patched-go-mod@sha256:12345
  source:
    git:
      url: 'https://gitlab.internal.unicorns.com/my/project'
      revision: a-revision
---
apiVersion: v1
kind: Secret
metadata:
  name: bindings-netrc
type: Opaque
stringData:
  .netrc: |-
    machine gitlab.internal.unicorns.com
    #@ "login" + data.values.git.username
    #@ "password" + data.values.git.token

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: netrc-metadata
data:
  kind: go
  provider: sample

happy to help in any form!

from go-mod-vendor.

dfreilich avatar dfreilich commented on July 28, 2024

I'm interested in seeing this happen as well! Any chance there'll be any movement on this?

from go-mod-vendor.

tomkennedy513 avatar tomkennedy513 commented on July 28, 2024

This would be useful for me! I'm currently trying to pull in a private dependency and had to resort to vendoring in the dependency manually for the time being.

from go-mod-vendor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.