Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
Bumps buildpack spec api to 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and arjun024 committed Oct 22, 2021
1 parent a2c9fc9 commit 60e0643
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 263 deletions.
24 changes: 12 additions & 12 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/scribe"
)

//go:generate faux --interface InstallProcess --output fakes/install_process.go
Expand All @@ -16,7 +17,7 @@ type InstallProcess interface {

//go:generate faux --interface EntryResolver --output fakes/entry_resolver.go
type EntryResolver interface {
Resolve([]packit.BuildpackPlanEntry) packit.BuildpackPlanEntry
Resolve(name string, entries []packit.BuildpackPlanEntry, priorities []interface{}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry)
}

//go:generate faux --interface ScriptWriter --output fakes/script_writer.go
Expand All @@ -30,7 +31,7 @@ func Build(
bpYMLParser BpYMLParser,
scriptWriter ScriptWriter,
entryResolver EntryResolver,
logger LogEmitter,
logger scribe.Emitter,
clock chronos.Clock,
) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
Expand All @@ -42,27 +43,27 @@ func Build(
return packit.BuildResult{}, fmt.Errorf("failed to parse buildpack.yml: %v", err)
}

staticfileLayer, err := context.Layers.Get(LayerNameStaticfile)
layer, err := context.Layers.Get(LayerNameStaticfile)
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to get layer: %v", err)
}

entry := entryResolver.Resolve(context.Plan.Entries)
entry, _ := entryResolver.Resolve(StaticfileDependency, context.Plan.Entries, nil)

staticfileLayer, err = staticfileLayer.Reset()
layer, err = layer.Reset()
if err != nil {
return packit.BuildResult{}, err
}

staticfileLayer.Launch = entry.Metadata["launch"] == true
layer.Launch = entry.Metadata["launch"] == true

logger.Process("Writing profile.d scripts")
err = scriptWriter.WriteInitScript(filepath.Join(staticfileLayer.Path, "profile.d"))
err = scriptWriter.WriteInitScript(filepath.Join(layer.Path, "profile.d"))
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to write init script: %v", err)
}

err = scriptWriter.WriteStartLoggingScript(filepath.Join(staticfileLayer.Path, "profile.d"))
err = scriptWriter.WriteStartLoggingScript(filepath.Join(layer.Path, "profile.d"))
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to write start_logging script: %v", err)
}
Expand All @@ -80,12 +81,11 @@ func Build(
logger.Action("Completed in %s", duration.Round(time.Millisecond))
logger.Break()

staticfileLayer.SharedEnv.Default("APP_ROOT", context.WorkingDir)
logger.Environment(staticfileLayer.SharedEnv)
layer.SharedEnv.Default("APP_ROOT", context.WorkingDir)
logger.EnvironmentVariables(layer)

return packit.BuildResult{
Plan: context.Plan,
Layers: []packit.Layer{staticfileLayer},
Layers: []packit.Layer{layer},
}, nil
}
}
20 changes: 6 additions & 14 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-community/staticfile"
"github.com/paketo-community/staticfile/fakes"
"github.com/sclevine/spec"
Expand Down Expand Up @@ -59,7 +60,6 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
}

buffer = bytes.NewBuffer(nil)
logEmitter := staticfile.NewLogEmitter(buffer)

timeStamp = time.Now()
clock = chronos.NewClock(func() time.Time {
Expand All @@ -71,7 +71,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
bpYMLParser,
scriptWriter,
entryResolver,
logEmitter,
scribe.NewEmitter(buffer),
clock,
)
})
Expand Down Expand Up @@ -116,16 +116,6 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {

Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(packit.BuildResult{
Plan: packit.BuildpackPlan{
Entries: []packit.BuildpackPlanEntry{
{
Name: "staticfile",
Metadata: map[string]interface{}{
"launch": true,
},
},
},
},
Layers: []packit.Layer{
{
Name: "staticfile",
Expand All @@ -143,7 +133,8 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
},
}))

Expect(entryResolver.ResolveCall.Receives.BuildpackPlanEntrySlice).To(Equal([]packit.BuildpackPlanEntry{
Expect(entryResolver.ResolveCall.Receives.Name).To(Equal("staticfile"))
Expect(entryResolver.ResolveCall.Receives.Entries).To(Equal([]packit.BuildpackPlanEntry{
{
Name: "staticfile",
Metadata: map[string]interface{}{
Expand All @@ -166,7 +157,8 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
Expect(buffer.String()).To(ContainSubstring("Parsing buildpack.yml for nginx config"))
Expect(buffer.String()).To(ContainSubstring("Writing profile.d scripts"))
Expect(buffer.String()).To(ContainSubstring("Executing build process"))
Expect(buffer.String()).To(ContainSubstring("Configuring environment"))
Expect(buffer.String()).To(ContainSubstring("Configuring build environment"))
Expect(buffer.String()).To(ContainSubstring("Configuring launch environment"))
})
})

Expand Down
7 changes: 2 additions & 5 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
api = "0.4"
api = "0.5"

[buildpack]
homepage = "https://github.com/paketo-community/staticfile"
id = "paketo-community/staticfile"
name = "Staticfile Buildpack"
version = "0.0.2"

[metadata]
include-files = ["bin/build", "bin/detect", "bin/run", "buildpack.toml", "server_configs/nginx.conf"]
pre-package = "./scripts/build.sh"

[[stacks]]
id = "org.cloudfoundry.stacks.cflinuxfs3"

[[stacks]]
id = "io.buildpacks.stacks.bionic"
4 changes: 1 addition & 3 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Detect(bpYMLParser BpYMLParser) packit.DetectFunc {
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{
Name: StaticfileDependency,
},
{Name: StaticfileDependency},
},
Requires: []packit.BuildPlanRequirement{
{
Expand Down
12 changes: 6 additions & 6 deletions fakes/bp_yml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type BpYMLParser struct {
ParseCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -20,7 +20,7 @@ type BpYMLParser struct {
Stub func(string) (staticfile.Config, error)
}
ValidConfigCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -34,8 +34,8 @@ type BpYMLParser struct {
}

func (f *BpYMLParser) Parse(param1 string) (staticfile.Config, error) {
f.ParseCall.Lock()
defer f.ParseCall.Unlock()
f.ParseCall.mutex.Lock()
defer f.ParseCall.mutex.Unlock()
f.ParseCall.CallCount++
f.ParseCall.Receives.Path = param1
if f.ParseCall.Stub != nil {
Expand All @@ -44,8 +44,8 @@ func (f *BpYMLParser) Parse(param1 string) (staticfile.Config, error) {
return f.ParseCall.Returns.Config, f.ParseCall.Returns.Err
}
func (f *BpYMLParser) ValidConfig(param1 string) (bool, error) {
f.ValidConfigCall.Lock()
defer f.ValidConfigCall.Unlock()
f.ValidConfigCall.mutex.Lock()
defer f.ValidConfigCall.mutex.Unlock()
f.ValidConfigCall.CallCount++
f.ValidConfigCall.Receives.Path = param1
if f.ValidConfigCall.Stub != nil {
Expand Down
28 changes: 18 additions & 10 deletions fakes/entry_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ import (

type EntryResolver struct {
ResolveCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
BuildpackPlanEntrySlice []packit.BuildpackPlanEntry
Name string
Entries []packit.BuildpackPlanEntry
Priorities []interface {
}
}
Returns struct {
BuildpackPlanEntry packit.BuildpackPlanEntry
BuildpackPlanEntry packit.BuildpackPlanEntry
BuildpackPlanEntrySlice []packit.BuildpackPlanEntry
}
Stub func([]packit.BuildpackPlanEntry) packit.BuildpackPlanEntry
Stub func(string, []packit.BuildpackPlanEntry, []interface {
}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry)
}
}

func (f *EntryResolver) Resolve(param1 []packit.BuildpackPlanEntry) packit.BuildpackPlanEntry {
f.ResolveCall.Lock()
defer f.ResolveCall.Unlock()
func (f *EntryResolver) Resolve(param1 string, param2 []packit.BuildpackPlanEntry, param3 []interface {
}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry) {
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
f.ResolveCall.CallCount++
f.ResolveCall.Receives.BuildpackPlanEntrySlice = param1
f.ResolveCall.Receives.Name = param1
f.ResolveCall.Receives.Entries = param2
f.ResolveCall.Receives.Priorities = param3
if f.ResolveCall.Stub != nil {
return f.ResolveCall.Stub(param1)
return f.ResolveCall.Stub(param1, param2, param3)
}
return f.ResolveCall.Returns.BuildpackPlanEntry
return f.ResolveCall.Returns.BuildpackPlanEntry, f.ResolveCall.Returns.BuildpackPlanEntrySlice
}
6 changes: 3 additions & 3 deletions fakes/install_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type InstallProcess struct {
ExecuteCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Context packit.BuildContext
Expand All @@ -23,8 +23,8 @@ type InstallProcess struct {
}

func (f *InstallProcess) Execute(param1 packit.BuildContext, param2 staticfile.Config) error {
f.ExecuteCall.Lock()
defer f.ExecuteCall.Unlock()
f.ExecuteCall.mutex.Lock()
defer f.ExecuteCall.mutex.Unlock()
f.ExecuteCall.CallCount++
f.ExecuteCall.Receives.Context = param1
f.ExecuteCall.Receives.TemplConfig = param2
Expand Down
12 changes: 6 additions & 6 deletions fakes/script_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type ScriptWriter struct {
WriteInitScriptCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
ProfileDPath string
Expand All @@ -15,7 +15,7 @@ type ScriptWriter struct {
Stub func(string) error
}
WriteStartLoggingScriptCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
ProfileDPath string
Expand All @@ -28,8 +28,8 @@ type ScriptWriter struct {
}

func (f *ScriptWriter) WriteInitScript(param1 string) error {
f.WriteInitScriptCall.Lock()
defer f.WriteInitScriptCall.Unlock()
f.WriteInitScriptCall.mutex.Lock()
defer f.WriteInitScriptCall.mutex.Unlock()
f.WriteInitScriptCall.CallCount++
f.WriteInitScriptCall.Receives.ProfileDPath = param1
if f.WriteInitScriptCall.Stub != nil {
Expand All @@ -38,8 +38,8 @@ func (f *ScriptWriter) WriteInitScript(param1 string) error {
return f.WriteInitScriptCall.Returns.Error
}
func (f *ScriptWriter) WriteStartLoggingScript(param1 string) error {
f.WriteStartLoggingScriptCall.Lock()
defer f.WriteStartLoggingScriptCall.Unlock()
f.WriteStartLoggingScriptCall.mutex.Lock()
defer f.WriteStartLoggingScriptCall.mutex.Unlock()
f.WriteStartLoggingScriptCall.CallCount++
f.WriteStartLoggingScriptCall.Receives.ProfileDPath = param1
if f.WriteStartLoggingScriptCall.Stub != nil {
Expand Down
2 changes: 0 additions & 2 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ func TestUnit(t *testing.T) {
suite("BuildpackYAMLParser", testBuildpackYAMLParser)
suite("ConfigInstaller", testConfigInstaller)
suite("Detect", testDetect)
suite("LogEmitter", testLogEmitter)
suite("ProfileDWriter", testProfileDWriter)
suite("PlanEntryResolver", testPlanEntryResolver)
suite.Run(t)
}
41 changes: 4 additions & 37 deletions integration/init_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package integration

import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/paketo-buildpacks/packit/pexec"
"github.com/onsi/gomega/format"
"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
Expand All @@ -23,6 +21,7 @@ var (
)

func TestIntegration(t *testing.T) {
format.MaxLength = 0
Expect := NewWithT(t).Expect

var config struct {
Expand All @@ -37,18 +36,15 @@ func TestIntegration(t *testing.T) {

Expect(json.NewDecoder(file).Decode(&config)).To(Succeed())

version, err := GetGitVersion()
Expect(err).NotTo(HaveOccurred())

buildpackStore := occam.NewBuildpackStore()

buildpack, err = buildpackStore.Get.
WithVersion(version).
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())

nginxBuildpack, err = buildpackStore.Get.
Execute(config.Nginx)
Execute(config.Nginx)
Expect(err).NotTo(HaveOccurred())

SetDefaultEventuallyTimeout(5 * time.Second)
Expand All @@ -58,32 +54,3 @@ func TestIntegration(t *testing.T) {
suite("Logging", testLogging)
suite.Run(t)
}

func GetGitVersion() (string, error) {
gitExec := pexec.NewExecutable("git")
revListOut := bytes.NewBuffer(nil)

err := gitExec.Execute(pexec.Execution{
Args: []string{"rev-list", "--tags", "--max-count=1"},
Stdout: revListOut,
})

if revListOut.String() == "" {
return "0.0.0", nil
}

if err != nil {
return "", err
}

stdout := bytes.NewBuffer(nil)
err = gitExec.Execute(pexec.Execution{
Args: []string{"describe", "--tags", strings.TrimSpace(revListOut.String())},
Stdout: stdout,
})
if err != nil {
return "", err
}

return strings.TrimSpace(strings.TrimPrefix(stdout.String(), "v")), nil
}
Loading

0 comments on commit 60e0643

Please sign in to comment.