-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.go
58 lines (48 loc) · 1.91 KB
/
build.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
package phphttpd
import (
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/draft"
"github.com/paketo-buildpacks/packit/v2/scribe"
)
//go:generate faux --interface ConfigWriter --output fakes/config_writer.go
// ConfigWriter sets up the HTTPD configuration file with defaults, and adds in
// user-set environment variables.
type ConfigWriter interface {
Write(layerPath, workingDir string) (string, error)
}
// Build will return a packit.BuildFunc that will be invoked during the build
// phase of the buildpack lifecycle.
//
// Build will create a layer dedicated to PHP HTTPD configuration, configure default HTTPD
// settings, incorporate other configuration sources, and make the
// configuration available at both build-time and
// launch-time.
func Build(config ConfigWriter, logger scribe.Emitter) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
logger.Debug.Process("Getting the layer associated with the HTTPD configuration")
phpHttpdLayer, err := context.Layers.Get(PhpHttpdConfigLayer)
if err != nil {
return packit.BuildResult{}, err
}
logger.Debug.Subprocess(phpHttpdLayer.Path)
logger.Debug.Break()
phpHttpdLayer, err = phpHttpdLayer.Reset()
if err != nil {
return packit.BuildResult{}, err
}
logger.Process("Setting up the HTTPD configuration file")
httpdConfigPath, err := config.Write(phpHttpdLayer.Path, context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
logger.Break()
planner := draft.NewPlanner()
phpHttpdLayer.Launch, phpHttpdLayer.Build = planner.MergeLayerTypes(PhpHttpdConfig, context.Plan.Entries)
phpHttpdLayer.SharedEnv.Default("PHP_HTTPD_PATH", httpdConfigPath)
logger.EnvironmentVariables(phpHttpdLayer)
return packit.BuildResult{
Layers: []packit.Layer{phpHttpdLayer},
}, nil
}
}