github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/client/example_build_test.go (about) 1 //go:build !windows && example 2 // +build !windows,example 3 4 package client_test 5 6 import ( 7 "context" 8 "fmt" 9 "path/filepath" 10 11 "github.com/buildpacks/pack/pkg/client" 12 ) 13 14 // This example shows the basic usage of the package: Create a client, 15 // call a configuration object, call the client's Build function. 16 func Example_build() { 17 // create a context object 18 context := context.Background() 19 20 // initialize a pack client 21 pack, err := client.NewClient() 22 if err != nil { 23 panic(err) 24 } 25 26 // replace this with the location of a sample application 27 // For a list of prepared samples see the 'apps' folder at 28 // https://github.com/buildpacks/samples. 29 appPath := filepath.Join("testdata", "some-app") 30 31 // initialize our options 32 buildOpts := client.BuildOptions{ 33 Image: "pack-lib-test-image:0.0.1", 34 Builder: "cnbs/sample-builder:bionic", 35 AppPath: appPath, 36 TrustBuilder: func(string) bool { return true }, 37 } 38 39 // build an image 40 err = pack.Build(context, buildOpts) 41 if err != nil { 42 panic(err) 43 } 44 45 fmt.Println("build completed") 46 // Output: build completed 47 }