@@ -12,6 +12,11 @@ import (
12
12
"github.com/paketo-buildpacks/packit/internal"
13
13
)
14
14
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
+
15
20
// BuildContext provides the contextual details that are made available by the
16
21
// buildpack lifecycle during the build phase. This context is populated by the
17
22
// Build function and passed to BuildFunc during execution.
@@ -25,6 +30,10 @@ type BuildContext struct {
25
30
// files included in the buildpack.
26
31
CNBPath string
27
32
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
+
28
37
// Layers provides access to layers managed by the buildpack. It can be used
29
38
// to create new layers or retrieve cached layers from previous builds.
30
39
Layers Layers
@@ -43,11 +52,6 @@ type BuildContext struct {
43
52
WorkingDir string
44
53
}
45
54
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
-
51
55
// BuildResult allows buildpack authors to indicate the result of the build
52
56
// phase for a given buildpack. This result, returned in a BuildFunc callback,
53
57
// will be parsed and persisted by the Build function and returned to the
@@ -76,137 +80,6 @@ type BuildResult struct {
76
80
Build BuildMetadata
77
81
}
78
82
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
-
210
83
// Build is an implementation of the build phase according to the Cloud Native
211
84
// Buildpacks specification. Calling this function with a BuildFunc will
212
85
// perform the build phase process.
@@ -223,8 +96,9 @@ func Build(f BuildFunc, options ...Option) {
223
96
}
224
97
225
98
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 ]
228
102
)
229
103
230
104
pwd , err := os .Getwd ()
@@ -264,7 +138,10 @@ func Build(f BuildFunc, options ...Option) {
264
138
}
265
139
266
140
result , err := f (BuildContext {
267
- CNBPath : cnbPath ,
141
+ CNBPath : cnbPath ,
142
+ Platform : Platform {
143
+ Path : platformPath ,
144
+ },
268
145
Stack : os .Getenv ("CNB_STACK_ID" ),
269
146
WorkingDir : pwd ,
270
147
Plan : plan ,
0 commit comments