forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_test.go
55 lines (44 loc) · 1.25 KB
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package pack_test
import (
"context"
"fmt"
"math/rand"
"github.com/buildpacks/pack"
)
// This example shows the basic usage of the package: Create a client,
// Create a configuration object, Call the client's Build function.
func Example_build() {
//create a context object
context := context.Background()
//initialize a pack client
client, err := pack.NewClient()
if err != nil {
panic(err)
}
// please replace this with the location of a sample application,
// for a list of prepared samples see the 'apps' folder at
// https://github.com/buildpacks/samples
appPath := "local/path/to/application/root"
// randomly select a builder to use from among the following
builderList := []string{
"gcr.io/buildpacks/builder:v1",
"heroku/buildpacks:18",
"gcr.io/paketo-buildpacks/builder:base",
}
randomIndex := rand.Intn(len(builderList))
randomBuilder := builderList[randomIndex]
// initialize our options
buildOpts := pack.BuildOptions{
Image: "pack-lib-test-image:0.0.1",
Builder: randomBuilder,
AppPath: appPath,
TrustBuilder: true,
}
fmt.Println("building application image")
// preform an image build
err = client.Build(context, buildOpts)
if err != nil {
panic(err)
}
fmt.Println("build completed")
}