forked from paketo-buildpacks/bionic-full-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildpack_integration_test.go
147 lines (117 loc) · 3.6 KB
/
buildpack_integration_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package acceptance_test
import (
"bytes"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/google/uuid"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/occam"
. "github.com/paketo-buildpacks/occam/matchers"
"github.com/paketo-buildpacks/packit/v2/pexec"
)
func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
phpBuildpack string
builderConfigFilepath string
pack occam.Pack
docker occam.Docker
source string
name string
builder string
image occam.Image
container occam.Container
)
it.Before(func() {
pack = occam.NewPack().WithVerbose()
docker = occam.NewDocker()
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
buildpackStore := occam.NewBuildpackStore()
phpBuildpack, err = buildpackStore.Get.
Execute("github.com/paketo-buildpacks/php")
Expect(err).NotTo(HaveOccurred())
source, err = occam.Source(filepath.Join("integration", "testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())
builderConfigFile, err := os.CreateTemp("", "builder.toml")
Expect(err).NotTo(HaveOccurred())
builderConfigFilepath = builderConfigFile.Name()
_, err = fmt.Fprintf(builderConfigFile, `
[stack]
build-image = "%s:latest"
id = "io.buildpacks.stacks.bionic"
run-image = "%s:latest"
`,
stack.BuildImageID,
stack.RunImageID,
)
Expect(err).NotTo(HaveOccurred())
Expect(archiveToDaemon(stack.BuildArchive, stack.BuildImageID)).To(Succeed())
Expect(archiveToDaemon(stack.RunArchive, stack.RunImageID)).To(Succeed())
builder = fmt.Sprintf("builder-%s", uuid.NewString())
logs, err := createBuilder(builderConfigFilepath, builder)
Expect(err).NotTo(HaveOccurred(), logs)
})
it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(docker.Image.Remove.Execute(builder)).To(Succeed())
Expect(os.RemoveAll(builderConfigFilepath)).To(Succeed())
Expect(docker.Image.Remove.Execute(stack.BuildImageID)).To(Succeed())
Expect(docker.Image.Remove.Execute(stack.RunImageID)).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})
it("builds an app with a buildpack", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("if-not-present").
WithBuildpacks(
phpBuildpack,
).
WithEnv(map[string]string{
"BP_PHP_WEB_DIR": "htdocs",
}).
WithBuilder(builder).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
WithPublishAll().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(Serve(ContainSubstring("SUCCESS: date loads.")).OnPort(8080).WithEndpoint("/index.php?date"))
})
}
func archiveToDaemon(path, id string) error {
skopeo := pexec.NewExecutable("skopeo")
return skopeo.Execute(pexec.Execution{
Args: []string{
"copy",
fmt.Sprintf("oci-archive://%s", path),
fmt.Sprintf("docker-daemon:%s:latest", id),
},
})
}
func createBuilder(config string, name string) (string, error) {
buf := bytes.NewBuffer(nil)
pack := pexec.NewExecutable("pack")
err := pack.Execute(pexec.Execution{
Stdout: buf,
Stderr: buf,
Args: []string{
"builder",
"create",
name,
fmt.Sprintf("--config=%s", config),
},
})
return buf.String(), err
}