Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
Remove ioutil usage, and switch to using `t.Setenv`. Remove specific stacks in favor of wildcard stack.

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Feb 11, 2024
1 parent f2b2ac1 commit 804b202
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 55 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# `gcr.io/paketo-buildpacks/dist-zip`

The Paketo Buildpack for DistZip is a Cloud Native Buildpack that contributes a Process Type for DistZip-style applications.

## Behavior

This buildpack will participate all the following conditions are met

* Exactly one file matching `<APPLICATION_ROOT>/$BP_APPLICATION_SCRIPT` exists
Expand All @@ -16,12 +18,14 @@ When `$BP_LIVE_RELOAD_ENABLE` is true:
* Contributes `reload` process type

## Configuration

| Environment Variable | Description |
| ------------------------- | ------------------------------------------------------------------------------------------------- |
| `$BP_APPLICATION_SCRIPT` | Configures the application start script, using [Bash Pattern Matching][b]. Defaults to `*/bin/*`. |
| `$BP_LIVE_RELOAD_ENABLED` | Enable live process reloading. Defaults to false. |

## License

This buildpack is released under version 2.0 of the [Apache License][a].

[a]: http://www.apache.org/licenses/LICENSE-2.0
Expand Down
8 changes: 1 addition & 7 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2020 the original author or authors.
# Copyright 2018-2024 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,12 +27,6 @@ api = "0.7"
type = "Apache-2.0"
uri = "https://github.com/paketo-buildpacks/dist-zip/blob/main/LICENSE"

[[stacks]]
id = "io.buildpacks.stacks.bionic"

[[stacks]]
id = "io.paketo.stacks.tiny"

[[stacks]]
id = "*"

Expand Down
18 changes: 4 additions & 14 deletions distzip/build_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@ package distzip_test
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -43,7 +42,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
var err error

ctx.Application.Path, err = ioutil.TempDir("", "build-application")
ctx.Application.Path = t.TempDir()
Expect(err).NotTo(HaveOccurred())

ctx.Buildpack.Metadata = map[string]interface{}{
Expand All @@ -61,17 +60,12 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
}}
sbomScanner = mocks.SBOMScanner{}
sbomScanner.On("ScanLaunch", ctx.Application.Path, libcnb.SyftJSON, libcnb.CycloneDXJSON).Return(nil)

})

it.After(func() {
Expect(os.RemoveAll(ctx.Application.Path)).To(Succeed())
})

context("DistZip exists", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "test-script"), []byte{}, 0755))
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "test-script"), []byte{}, 0755))
})

it("contributes processes", func() {
Expand All @@ -88,11 +82,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("$BP_LIVE_RELOAD_ENABLED is true", func() {
it.Before(func() {
Expect(os.Setenv("BP_LIVE_RELOAD_ENABLED", "true")).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("BP_LIVE_RELOAD_ENABLED")).To(Succeed())
t.Setenv("BP_LIVE_RELOAD_ENABLED", "true")
})

it("contributes reloadable process type", func() {
Expand Down
23 changes: 7 additions & 16 deletions distzip/detect_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -45,7 +44,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
var err error

ctx.Application.Path, err = ioutil.TempDir("", "dist-zip")
ctx.Application.Path = t.TempDir()
Expect(err).NotTo(HaveOccurred())

ctx.Buildpack.Metadata = map[string]interface{}{
Expand All @@ -62,10 +61,6 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Logger: bard.NewLoggerWithOptions(io.Discard, bard.WithDebug(buf))}
})

it.After(func() {
Expect(os.RemoveAll(ctx.Application.Path)).To(Succeed())
})

context("application script not found", func() {
it("requires jvm-application-package", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Expand All @@ -90,8 +85,8 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
context("multiple application scripts", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-1"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-2"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-1"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-2"), []byte{}, 0755)).To(Succeed())
})

it("requires jvm-application-package", func() {
Expand Down Expand Up @@ -121,7 +116,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
context("single application script", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
})

it("requires and provides jvm-application-package", func() {
Expand All @@ -147,14 +142,10 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {

context("$BP_LIVE_RELOAD_ENABLED is set", func() {
it.Before(func() {
Expect(os.Setenv("BP_LIVE_RELOAD_ENABLED", "true")).To(Succeed())
t.Setenv("BP_LIVE_RELOAD_ENABLED", "true")

Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("BP_LIVE_RELOAD_ENABLED")).To(Succeed())
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
})

it("requires watchexec", func() {
Expand Down
27 changes: 9 additions & 18 deletions distzip/script_resolver_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -43,7 +42,7 @@ func testScriptResolver(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
var err error

r.ApplicationPath, err = ioutil.TempDir("", "script-resolver")
r.ApplicationPath = t.TempDir()
Expect(err).NotTo(HaveOccurred())

r.ConfigurationResolver = libpak.ConfigurationResolver{Configurations: []libpak.BuildpackConfiguration{
Expand All @@ -54,14 +53,10 @@ func testScriptResolver(t *testing.T, context spec.G, it spec.S) {
}}
})

it.After(func() {
Expect(os.RemoveAll(r.ApplicationPath)).To(Succeed())
})

it("returns script", func() {
Expect(os.MkdirAll(filepath.Join(r.ApplicationPath, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha.sh"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha.bat"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha.sh"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha.bat"), []byte{}, 0755)).To(Succeed())

s, ok, err := r.Resolve()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -72,17 +67,13 @@ func testScriptResolver(t *testing.T, context spec.G, it spec.S) {

context("$BP_APPLICATION_SCRIPT", func() {
it.Before(func() {
Expect(os.Setenv("BP_APPLICATION_SCRIPT", filepath.Join("bin", "*.bat"))).To(Succeed())
})

it.After(func() {
Expect(os.Unsetenv("BP_APPLICATION_SCRIPT")).To(Succeed())
t.Setenv("BP_APPLICATION_SCRIPT", filepath.Join("bin", "*.bat"))
})

it("returns script from $BP_APPLICATION_SCRIPT", func() {
Expect(os.MkdirAll(filepath.Join(r.ApplicationPath, "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "bin", "alpha.sh"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "bin", "alpha.bat"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "bin", "alpha.sh"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "bin", "alpha.bat"), []byte{}, 0755)).To(Succeed())

s, ok, err := r.Resolve()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -104,8 +95,8 @@ func testScriptResolver(t *testing.T, context spec.G, it spec.S) {
r.Logger = bard.NewLoggerWithOptions(io.Discard, bard.WithDebug(buf))

Expect(os.MkdirAll(filepath.Join(r.ApplicationPath, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "bravo"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "alpha"), []byte{}, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(r.ApplicationPath, "app", "bin", "bravo"), []byte{}, 0755)).To(Succeed())

_, _, err := r.Resolve()

Expand Down

0 comments on commit 804b202

Please sign in to comment.