-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.go
75 lines (62 loc) · 1.81 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
66
67
68
69
70
71
72
73
74
75
package thin
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/fs"
"github.com/paketo-buildpacks/packit/v2/scribe"
)
func Build(logger scribe.Emitter) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
rackConfigFilepath := filepath.Join(context.WorkingDir, "config.ru")
thinConfigFilepath := os.Getenv("BP_THIN_CONFIG_LOCATION")
if thinConfigFilepath != "" {
if !filepath.IsAbs(thinConfigFilepath) {
thinConfigFilepath = filepath.Join(context.WorkingDir, thinConfigFilepath)
}
thinConfigFilepathExists, err := fs.Exists(thinConfigFilepath)
if err != nil {
return packit.BuildResult{}, err
}
if !thinConfigFilepathExists {
return packit.BuildResult{}, packit.Fail.WithMessage("thin config file does not exist at: %s", thinConfigFilepath)
}
} else {
thinConfigFilepath = filepath.Join(context.WorkingDir, "thin.yml")
}
args := "bundle exec thin"
exists, err := fs.Exists(thinConfigFilepath)
if err != nil {
return packit.BuildResult{}, err
}
if exists {
args = args + fmt.Sprintf(" -C %s", thinConfigFilepath)
}
exists, err = fs.Exists(rackConfigFilepath)
if err != nil {
return packit.BuildResult{}, err
}
if exists {
args = args + fmt.Sprintf(" -R %s", rackConfigFilepath)
}
// 3000 is the default thin port
args = args + ` -p "${PORT:-3000}" start`
processes := []packit.Process{
{
Type: "web",
Command: "bash",
Args: []string{"-c", args},
Default: true,
Direct: true,
},
}
logger.LaunchProcesses(processes)
return packit.BuildResult{
Launch: packit.LaunchMetadata{
Processes: processes,
},
}, nil
}
}