Skip to content

Commit dfcde18

Browse files
ryanmoranSophie Wigmore
and
Sophie Wigmore
authored
Adds platform path to build and detect context (#134)
* Adds platform path to build and detect context - moves types referenced in build and detect contexts into their own files to make it a bit easier to find them when navigating the repo - adds new postal.Service.Deliver method that allows the user to pass in a platform path location. The existing postal.Service.Install method reuses Deliver with a hardcoded platform path of /platform and is marked as deprecated * no-op readme update Co-authored-by: Sophie Wigmore <swigmore@vmware.com>
1 parent 27b1a65 commit dfcde18

16 files changed

+580
-266
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ according to the specification:
88

99
## Buildpack Interface
1010

11-
According to the specification, the buildpack interface is composed of both
11+
According to the CNB specification, the buildpack interface is composed of both
1212
a detect and build phase. Each of these phases has a corresponding set of
1313
packit primitives enable developers to easily implement a buildpack.
1414

bom.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package packit
2+
3+
// BOMEntry contains a bill of materials entry.
4+
type BOMEntry struct {
5+
// Name represents the name of the entry.
6+
Name string `toml:"name"`
7+
8+
// Metadata is the metadata of the entry. Optional.
9+
Metadata map[string]interface{} `toml:"metadata,omitempty"`
10+
}
11+
12+
// UnmetEntry contains the name of an unmet dependency from the build process
13+
type UnmetEntry struct {
14+
// Name represents the name of the entry.
15+
Name string `toml:"name"`
16+
}

build.go

+16-139
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
"github.com/paketo-buildpacks/packit/internal"
1313
)
1414

15+
// BuildFunc is the definition of a callback that can be invoked when the Build
16+
// function is executed. Buildpack authors should implement a BuildFunc that
17+
// performs the specific build phase operations for a buildpack.
18+
type BuildFunc func(BuildContext) (BuildResult, error)
19+
1520
// BuildContext provides the contextual details that are made available by the
1621
// buildpack lifecycle during the build phase. This context is populated by the
1722
// Build function and passed to BuildFunc during execution.
@@ -25,6 +30,10 @@ type BuildContext struct {
2530
// files included in the buildpack.
2631
CNBPath string
2732

33+
// Platform includes the platform context according to the specification:
34+
// https://github.com/buildpacks/spec/blob/main/buildpack.md#build
35+
Platform Platform
36+
2837
// Layers provides access to layers managed by the buildpack. It can be used
2938
// to create new layers or retrieve cached layers from previous builds.
3039
Layers Layers
@@ -43,11 +52,6 @@ type BuildContext struct {
4352
WorkingDir string
4453
}
4554

46-
// BuildFunc is the definition of a callback that can be invoked when the Build
47-
// function is executed. Buildpack authors should implement a BuildFunc that
48-
// performs the specific build phase operations for a buildpack.
49-
type BuildFunc func(BuildContext) (BuildResult, error)
50-
5155
// BuildResult allows buildpack authors to indicate the result of the build
5256
// phase for a given buildpack. This result, returned in a BuildFunc callback,
5357
// will be parsed and persisted by the Build function and returned to the
@@ -76,137 +80,6 @@ type BuildResult struct {
7680
Build BuildMetadata
7781
}
7882

79-
// BOMEntry contains a bill of materials entry.
80-
type BOMEntry struct {
81-
// Name represents the name of the entry.
82-
Name string `toml:"name"`
83-
84-
// Metadata is the metadata of the entry. Optional.
85-
Metadata map[string]interface{} `toml:"metadata,omitempty"`
86-
}
87-
88-
// UnmetEntry contains the name of an unmet dependency from the build process
89-
type UnmetEntry struct {
90-
// Name represents the name of the entry.
91-
Name string `toml:"name"`
92-
}
93-
94-
// LaunchMetadata represents the launch metadata details persisted in the
95-
// launch.toml file according to the buildpack lifecycle specification:
96-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#launchtoml-toml.
97-
type LaunchMetadata struct {
98-
// Processes is a list of processes that will be returned to the lifecycle to
99-
// be executed during the launch phase.
100-
Processes []Process
101-
102-
// Slices is a list of slices that will be returned to the lifecycle to be
103-
// exported as separate layers during the export phase.
104-
Slices []Slice
105-
106-
// Labels is a map of key-value pairs that will be returned to the lifecycle to be
107-
// added as config label on the image metadata. Keys must be unique.
108-
Labels map[string]string
109-
110-
// BOM is the Bill-of-Material entries containing information about the
111-
// dependencies provided to the launch environment.
112-
BOM []BOMEntry
113-
}
114-
115-
func (l LaunchMetadata) isEmpty() bool {
116-
return (len(l.Processes) == 0 &&
117-
len(l.Slices) == 0 &&
118-
len(l.Labels) == 0 &&
119-
len(l.BOM) == 0)
120-
}
121-
122-
func (b BuildMetadata) isEmpty() bool {
123-
return (len(b.BOM) == 0 &&
124-
len(b.Unmet) == 0)
125-
}
126-
127-
// BuildMetadata represents the build metadata details persisted in the
128-
// build.toml file according to the buildpack lifecycle specification:
129-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildtoml-toml.
130-
type BuildMetadata struct {
131-
// BOM is the Bill-of-Material entries containing information about the
132-
// dependencies provided to the build environment.
133-
BOM []BOMEntry `toml:"bom"`
134-
135-
// Unmet is a list of unmet entries from the build process that it was unable
136-
// to provide.
137-
Unmet []UnmetEntry `toml:"unmet"`
138-
}
139-
140-
// Process represents a process to be run during the launch phase as described
141-
// in the specification:
142-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#launch. The
143-
// fields of the process are describe in the specification of the launch.toml
144-
// file:
145-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#launchtoml-toml.
146-
type Process struct {
147-
// Type is an identifier to describe the type of process to be executed, eg.
148-
// "web".
149-
Type string `toml:"type"`
150-
151-
// Command is the start command to be executed at launch.
152-
Command string `toml:"command"`
153-
154-
// Args is a list of arguments to be passed to the command at launch.
155-
Args []string `toml:"args"`
156-
157-
// Direct indicates whether the process should bypass the shell when invoked.
158-
Direct bool `toml:"direct"`
159-
}
160-
161-
// Slice represents a layer of the working directory to be exported during the
162-
// export phase. These slices help to optimize data transfer for files that are
163-
// commonly shared across applications. Slices are described in the layers
164-
// section of the buildpack spec:
165-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#layers. The slice
166-
// fields are described in the specification of the launch.toml file:
167-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#launchtoml-toml.
168-
type Slice struct {
169-
Paths []string `toml:"paths"`
170-
}
171-
172-
// BuildpackInfo is a representation of the basic information for a buildpack
173-
// provided in its buildpack.toml file as described in the specification:
174-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildpacktoml-toml.
175-
type BuildpackInfo struct {
176-
// ID is the identifier specified in the `buildpack.id` field of the buildpack.toml.
177-
ID string `toml:"id"`
178-
179-
// Name is the identifier specified in the `buildpack.name` field of the buildpack.toml.
180-
Name string `toml:"name"`
181-
182-
// Version is the identifier specified in the `buildpack.version` field of the buildpack.toml.
183-
Version string `toml:"version"`
184-
}
185-
186-
// BuildpackPlan is a representation of the buildpack plan provided by the
187-
// lifecycle and defined in the specification:
188-
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildpack-plan-toml.
189-
// It is also used to return a set of refinements to the plan at the end of the
190-
// build phase.
191-
type BuildpackPlan struct {
192-
// Entries is a list of BuildpackPlanEntry fields that are declared in the
193-
// buildpack plan TOML file.
194-
Entries []BuildpackPlanEntry `toml:"entries"`
195-
}
196-
197-
// BuildpackPlanEntry is a representation of a single buildpack plan entry
198-
// specified by the lifecycle.
199-
type BuildpackPlanEntry struct {
200-
// Name is the name of the dependency the the buildpack should provide.
201-
Name string `toml:"name"`
202-
203-
// Metadata is an unspecified field allowing buildpacks to communicate extra
204-
// details about their requirement. Examples of this type of metadata might
205-
// include details about what source was used to decide the version
206-
// constraint for a requirement.
207-
Metadata map[string]interface{} `toml:"metadata"`
208-
}
209-
21083
// Build is an implementation of the build phase according to the Cloud Native
21184
// Buildpacks specification. Calling this function with a BuildFunc will
21285
// perform the build phase process.
@@ -223,8 +96,9 @@ func Build(f BuildFunc, options ...Option) {
22396
}
22497

22598
var (
226-
layersPath = config.args[1]
227-
planPath = config.args[3]
99+
layersPath = config.args[1]
100+
platformPath = config.args[2]
101+
planPath = config.args[3]
228102
)
229103

230104
pwd, err := os.Getwd()
@@ -264,7 +138,10 @@ func Build(f BuildFunc, options ...Option) {
264138
}
265139

266140
result, err := f(BuildContext{
267-
CNBPath: cnbPath,
141+
CNBPath: cnbPath,
142+
Platform: Platform{
143+
Path: platformPath,
144+
},
268145
Stack: os.Getenv("CNB_STACK_ID"),
269146
WorkingDir: pwd,
270147
Plan: plan,

build_metadata.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package packit
2+
3+
// BuildMetadata represents the build metadata details persisted in the
4+
// build.toml file according to the buildpack lifecycle specification:
5+
// https://github.com/buildpacks/spec/blob/main/buildpack.md#buildtoml-toml.
6+
type BuildMetadata struct {
7+
// BOM is the Bill-of-Material entries containing information about the
8+
// dependencies provided to the build environment.
9+
BOM []BOMEntry `toml:"bom"`
10+
11+
// Unmet is a list of unmet entries from the build process that it was unable
12+
// to provide.
13+
Unmet []UnmetEntry `toml:"unmet"`
14+
}

build_plan.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package packit
2+
3+
// BuildPlan is a representation of the Build Plan as specified in the
4+
// specification:
5+
// https://github.com/buildpacks/spec/blob/main/buildpack.md#build-plan-toml.
6+
// The BuildPlan allows buildpacks to indicate what dependencies they provide
7+
// or require.
8+
type BuildPlan struct {
9+
// Provides is a list of BuildPlanProvisions that are provided by this
10+
// buildpack.
11+
Provides []BuildPlanProvision `toml:"provides"`
12+
13+
// Requires is a list of BuildPlanRequirements that are required by this
14+
// buildpack.
15+
Requires []BuildPlanRequirement `toml:"requires"`
16+
17+
// Or is a list of additional BuildPlans that may be selected by the
18+
// lifecycle
19+
Or []BuildPlan `toml:"or,omitempty"`
20+
}
21+
22+
// BuildPlanProvision is a representation of a dependency that can be provided
23+
// by a buildpack.
24+
type BuildPlanProvision struct {
25+
// Name is the identifier whereby buildpacks can coordinate that a dependency
26+
// is provided or required.
27+
Name string `toml:"name"`
28+
}
29+
30+
type BuildPlanRequirement struct {
31+
// Name is the identifier whereby buildpacks can coordinate that a dependency
32+
// is provided or required.
33+
Name string `toml:"name"`
34+
35+
// Metadata is an unspecified field allowing buildpacks to communicate extra
36+
// details about their requirement. Examples of this type of metadata might
37+
// include details about what source was used to decide the version
38+
// constraint for a requirement.
39+
Metadata interface{} `toml:"metadata"`
40+
}

0 commit comments

Comments
 (0)