forked from paketo-buildpacks/php-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
65 lines (54 loc) · 2.12 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
59
60
61
62
63
64
65
package phpnginx
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 default Nginx configuration file and incorporates
// any user configurations.
type ConfigWriter interface {
Write(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 Nginx configuration, configure default Nginx
// settings, incorporate other configuration sources, and make the
// configuration available at both build-time and
// launch-time.
func Build(nginxConfigWriter ConfigWriter, nginxFpmConfigWriter 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 Nginx configuration")
phpNginxLayer, err := context.Layers.Get(PhpNginxConfigLayer)
if err != nil {
return packit.BuildResult{}, err
}
logger.Debug.Subprocess(phpNginxLayer.Path)
logger.Debug.Break()
phpNginxLayer, err = phpNginxLayer.Reset()
if err != nil {
return packit.BuildResult{}, err
}
logger.Process("Setting up the Nginx configuration file")
nginxConfigPath, err := nginxConfigWriter.Write(context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
logger.Break()
logger.Process("Setting up the Nginx-specific FPM configuration file")
_, err = nginxFpmConfigWriter.Write(context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
logger.Break()
planner := draft.NewPlanner()
phpNginxLayer.Launch, phpNginxLayer.Build = planner.MergeLayerTypes(PhpNginxConfig, context.Plan.Entries)
phpNginxLayer.SharedEnv.Default("PHP_NGINX_PATH", nginxConfigPath)
logger.EnvironmentVariables(phpNginxLayer)
return packit.BuildResult{
Layers: []packit.Layer{phpNginxLayer},
}, nil
}
}