Skip to content

Commit fcc7dbb

Browse files
committed
Do not assume php layer to launch=true
Instead, read the buildplan and mark the layer accordingly Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
1 parent 0de7438 commit fcc7dbb

10 files changed

+64
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
.idea
33
.bin
44
/bin
5+
/build
56
*.tgz
67
php-dist_*

build.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ func Build(entries EntryResolver,
5656

5757
logger.SelectedDependency(entry, dependency.Version)
5858

59-
phpLayer, err := context.Layers.Get("php", packit.LaunchLayer)
59+
phpLayer, err := context.Layers.Get("php")
6060
if err != nil {
6161
return packit.BuildResult{}, err
6262
}
6363

64+
phpLayer.Launch = entry.Metadata["launch"] == true
6465
phpLayer.Build = entry.Metadata["build"] == true
6566
phpLayer.Cache = entry.Metadata["build"] == true
6667

build_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
161161
BuildEnv: packit.Environment{},
162162
LaunchEnv: packit.Environment{},
163163
Build: false,
164-
Launch: true,
164+
Launch: false,
165165
Cache: false,
166166
Metadata: map[string]interface{}{
167167
phpdist.DepKey: "",
@@ -201,7 +201,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
201201
Expect(buffer.String()).To(ContainSubstring("Executing build process"))
202202
})
203203

204-
context("when the build plan entry includes the build flag", func() {
204+
context("when the build plan entry includes the build, launch flags", func() {
205205
var workingDir string
206206

207207
it.Before(func() {
@@ -214,6 +214,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
214214
Version: "7.2.*",
215215
Metadata: map[string]interface{}{
216216
"version-source": "buildpack.yml",
217+
"launch": true,
217218
"build": true,
218219
},
219220
}
@@ -225,6 +226,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
225226
Version: "7.2.*",
226227
Metadata: map[string]interface{}{
227228
"version-source": "buildpack.yml",
229+
"launch": true,
228230
"build": true,
229231
},
230232
},
@@ -236,7 +238,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
236238
Expect(os.RemoveAll(workingDir)).To(Succeed())
237239
})
238240

239-
it("marks the php layer as cached", func() {
241+
it("marks the php layer as build, cache and launch", func() {
240242
result, err := build(packit.BuildContext{
241243
CNBPath: cnbDir,
242244
Stack: "some-stack",
@@ -248,6 +250,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
248250
Version: "7.2.*",
249251
Metadata: map[string]interface{}{
250252
"version-source": "buildpack.yml",
253+
"launch": true,
251254
"build": true,
252255
},
253256
},
@@ -264,6 +267,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
264267
Version: "7.2.*",
265268
Metadata: map[string]interface{}{
266269
"version-source": "buildpack.yml",
270+
"launch": true,
267271
"build": true,
268272
},
269273
},
@@ -342,7 +346,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
342346
BuildEnv: packit.Environment{},
343347
LaunchEnv: packit.Environment{},
344348
Build: false,
345-
Launch: true,
349+
Launch: false,
346350
Cache: false,
347351
Metadata: map[string]interface{}{
348352
phpdist.DepKey: "",

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
33
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
44
github.com/ForestEckhardt/freezer v0.0.0-20200630185456-a126adb8de1b h1:5ah4g+sbKU2LvMIOeR0+a4PIzrXRxJTqjZwXOdOdQsA=
55
github.com/ForestEckhardt/freezer v0.0.0-20200630185456-a126adb8de1b/go.mod h1:Tp5MaiHIfM9TOqTFYlqHsittmOnFGsUcUVDX+AtbNrI=
6+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
67
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
78
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
89
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
@@ -97,9 +98,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
9798
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
9899
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
99100
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
101+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
100102
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
101-
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
102-
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
103103
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
104104
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
105105
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

integration.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"build-plan": "github.com/ForestEckhardt/build-plan"
3+
}

integration/init_test.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration_test
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"os"
67
"path/filepath"
78
"strings"
@@ -18,16 +19,22 @@ import (
1819
)
1920

2021
var (
21-
phpDistBuildpack string
22-
offlinePhpDistBuildpack string
23-
version string
22+
phpDistBuildpack string
23+
offlinePhpDistBuildpack string
24+
buildPlanBuildpack string
25+
offlineBuildPlanBuildpack string
26+
version string
2427

2528
buildpackInfo struct {
2629
Buildpack struct {
2730
ID string
2831
Name string
2932
}
3033
}
34+
35+
config struct {
36+
BuildPlan string `json:"build-plan"`
37+
}
3138
)
3239

3340
func TestIntegration(t *testing.T) {
@@ -38,10 +45,16 @@ func TestIntegration(t *testing.T) {
3845

3946
file, err := os.Open("../buildpack.toml")
4047
Expect(err).NotTo(HaveOccurred())
41-
defer file.Close()
4248

4349
_, err = toml.DecodeReader(file, &buildpackInfo)
4450
Expect(err).NotTo(HaveOccurred())
51+
Expect(file.Close()).To(Succeed())
52+
53+
file, err = os.Open("../integration.json")
54+
Expect(err).NotTo(HaveOccurred())
55+
56+
Expect(json.NewDecoder(file).Decode(&config)).To(Succeed())
57+
Expect(file.Close()).To(Succeed())
4558

4659
buildpackStore := occam.NewBuildpackStore()
4760

@@ -59,6 +72,15 @@ func TestIntegration(t *testing.T) {
5972
Execute(root)
6073
Expect(err).NotTo(HaveOccurred())
6174

75+
buildPlanBuildpack, err = buildpackStore.Get.
76+
Execute(config.BuildPlan)
77+
Expect(err).ToNot(HaveOccurred())
78+
79+
offlineBuildPlanBuildpack, err = buildpackStore.Get.
80+
WithOfflineDependencies().
81+
Execute(config.BuildPlan)
82+
Expect(err).ToNot(HaveOccurred())
83+
6284
SetDefaultEventuallyTimeout(5 * time.Second)
6385

6486
suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel())

integration/offline_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ func testOffline(t *testing.T, context spec.G, it spec.S) {
5555
var logs fmt.Stringer
5656
image, logs, err = pack.WithNoColor().Build.
5757
WithNoPull().
58-
WithBuildpacks(offlinePhpDistBuildpack).
58+
WithBuildpacks(
59+
offlinePhpDistBuildpack,
60+
offlineBuildPlanBuildpack,
61+
).
5962
WithNetwork("none").
6063
Execute(name, source)
6164
Expect(err).NotTo(HaveOccurred(), logs.String())

integration/simple_app_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {
5656
var logs fmt.Stringer
5757
image, logs, err = pack.WithNoColor().Build.
5858
WithNoPull().
59-
WithBuildpacks(phpDistBuildpack).
59+
WithBuildpacks(
60+
phpDistBuildpack,
61+
buildPlanBuildpack,
62+
).
6063
Execute(name, source)
6164
Expect(err).NotTo(HaveOccurred(), logs.String())
6265

@@ -65,6 +68,7 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {
6568
" Resolving PHP version",
6669
" Candidate version sources (in priority order):",
6770
" buildpack.yml -> \"7.2.*\"",
71+
" <unknown> -> \"\"",
6872
"",
6973
MatchRegexp(` Selected PHP version \(using buildpack\.yml\): 7\.2\.\d+`),
7074
"",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[[requires]]
2+
name = "php"
3+
4+
[requires.metadata]
5+
launch = true

plan_entry_resolver.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ func NewPlanEntryResolver(logger LogEmitter) PlanEntryResolver {
1919
func (r PlanEntryResolver) Resolve(entries []packit.BuildpackPlanEntry) packit.BuildpackPlanEntry {
2020
var (
2121
priorities = map[string]int{
22-
"buildpack.yml": 3,
23-
"composer.lock": 2,
24-
"composer.json": 2,
22+
"buildpack.yml": 3,
23+
"composer.lock": 2,
24+
"composer.json": 2,
2525
"default-versions": 1,
26-
"": -1,
26+
"": -1,
2727
}
2828
)
2929

@@ -47,6 +47,10 @@ func (r PlanEntryResolver) Resolve(entries []packit.BuildpackPlanEntry) packit.B
4747
if entry.Metadata["build"] == true {
4848
chosenEntry.Metadata["build"] = true
4949
}
50+
51+
if entry.Metadata["launch"] == true {
52+
chosenEntry.Metadata["launch"] = true
53+
}
5054
}
5155

5256
r.logger.Candidates(entries)

0 commit comments

Comments
 (0)