Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildpack create command to generate new buildpack scaffolding #1025

Merged
merged 49 commits into from
Mar 4, 2021

Conversation

jkutner
Copy link
Member

@jkutner jkutner commented Jan 19, 2021

Summary

Generates the basic files needed for a buildpack written in Bash:

  • buildpack.toml
  • bin/build
  • bin/detect

Output

Before

N/A

After

$ pack buildpack new foobar
    create buildpack.toml
    create bin/build
    create bin/detect
Successfully created foobar

Documentation

  • Should this change be documented?
    • Yes, see #___
    • No

Related

Resolves #82 (finally! 😄 )
buildpacks/rfcs#136

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@ekcasey
Copy link
Member

ekcasey commented Jan 19, 2021

@jkutner I assume this is scaffolding for a Bash buildpack? I worry somewhat that he existence of this command will encourage folks to write complex buildpacks in Bash, which may not be a pleasant experience in the long run.

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner
Copy link
Member Author

jkutner commented Jan 19, 2021

@ekcasey no, there's a --language option, which can support Golang. I've been looking at golang buildpacks to try and figure out what an opinionated scaffold would look like, but I'd love to get some help from people who actually right buildpacks in Go.

Sidenote: I disagree about bash "not be a pleasant experience in the long run". Many buildpacks v2 are written in bash and have been successful and well maintained for years.

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner force-pushed the jkutner/new-buildpack-toml-keys branch from bb5df64 to f638c0e Compare January 19, 2021 16:56
@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

Merging #1025 (c638eb8) into main (658dec2) will decrease coverage by 0.18%.
The diff coverage is 68.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1025      +/-   ##
==========================================
- Coverage   80.56%   80.39%   -0.17%     
==========================================
  Files         131      133       +2     
  Lines        8050     8156     +106     
==========================================
+ Hits         6485     6556      +71     
- Misses       1147     1171      +24     
- Partials      418      429      +11     
Flag Coverage Δ
os_linux ?
os_macos 77.34% <71.96%> (-0.07%) ⬇️
os_windows 80.33% <68.87%> (-0.15%) ⬇️
unit 77.34% <71.96%> (-2.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
create_buildpack.go Outdated Show resolved Hide resolved
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner marked this pull request as ready for review January 21, 2021 18:17
@jkutner jkutner requested a review from a team as a code owner January 21, 2021 18:17
@dfreilich dfreilich added this to the 0.17.0 milestone Jan 22, 2021
@dfreilich dfreilich added the type/enhancement Issue that requests a new feature or improvement. label Jan 22, 2021
internal/commands/buildpack.go Outdated Show resolved Hide resolved
internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
return createBashBuildpack(opts.Path, c)
}

func createBashBuildpack(path string, c *Client) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if we don't need the rest of the client, does it make more sense to just pass the logger?

new_buildpack.go Outdated Show resolved Hide resolved
new_buildpack.go Outdated Show resolved Hide resolved
new_buildpack.go Outdated Show resolved Hide resolved
new_buildpack_test.go Show resolved Hide resolved
jkutner and others added 7 commits January 22, 2021 09:33
Signed-off-by: Joe Kutner <jpkutner@gmail.com>

Co-authored-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>

Co-authored-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>

Co-authored-by: David Freilich <dfreilich@vmware.com>
…s exist

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner requested a review from dfreilich February 18, 2021 14:53
}

path := filepath.Join(flags.Path, dirName)
if len(path) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be flag.Path? Otherwise, assuming they're passing in a string, I don't see how this if block can be reached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9e20ac0

internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
jkutner and others added 3 commits February 19, 2021 09:05
Signed-off-by: Joe Kutner <jpkutner@gmail.com>

Co-authored-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner requested review from dfreilich and jromero February 19, 2021 15:28
internal/commands/buildpack_new.go Outdated Show resolved Hide resolved
@jkutner jkutner requested a review from jromero February 20, 2021 00:10
@jromero
Copy link
Member

jromero commented Mar 3, 2021

@jkutner found a few oddities when trying to use this command. Would you mind addressing them?

⚠️ Acceptance

⚠️ pack help buildpacks new

For the --api flag, it states "Platform API" when it should be "Buildpack API"

pack-dev help buildpack new
buildpack new generates the basic scaffolding of a buildpack repository. It creates a new directory `name` in the current directory (or at `path`, if passed as a flag), and initializes a buildpack.toml, and two executable bash scripts, `bin/detect` and `bin/build`.

Usage:
  pack buildpack new <id> [flags]

Examples:
pack buildpack new sample/my-buildpack

Flags:
  -a, --api string       Platform API compatibility of the generated buildpack (default "0.4")
  -h, --help             Help for 'new'
  -p, --path string      Path to generate the buildpack
  -s, --stacks strings   Stack(s) this buildpack will be compatible with
                         Repeat for each stack in order, or supply once by comma-separated list (default [io.buildpacks.stacks.bionic])
  -V, --version string   Version of the generated buildpack (default "1.0.0")

Global Flags:
      --no-color     Disable color output
  -q, --quiet        Show less output
      --timestamps   Enable timestamps in output
  -v, --verbose      Show more output

⚠️ pack buildpacks new -p ...

I would have expected the path flag (--path) to allow me to rename the final directory. This doesn't seem to be the case.

In the example below I expected the buildpack to be created at my-bp-folder not my-bp-folder/my-bp

❯ ls -1

/tmp on ☁️ rjavier@vmware.com
❯ pack-dev buildpack new my-bp -p my-bp-folder
    create  buildpack.toml
    create  bin/build
    create  bin/detect
Successfully created my-bp

/tmp on ☁️ rjavier@vmware.com
❯ ls -1
my-bp-folder/

/tmp on ☁️ rjavier@vmware.com
❯ ls -1 my-bp-folder/
my-bp/

/tmp on ☁️ rjavier@vmware.com
❯ ls -1 my-bp-folder/my-bp/
bin/
buildpack.toml

⚠️ pack buildpacks new (to existing directory)

When an directory is present that collides with the name of the buildpack nothing is created and no message is provided.

Expected:

  • If directory is empty, for the buildpack to be created.
  • If directory has files, for it to output an error message.
/tmp/test-1026 on ☁️ rjavier@vmware.com
❯ mkdir my-bp

/tmp/test-1026 on ☁️ rjavier@vmware.com
❯ pack-dev buildpack new my-bp

/tmp/test-1026 on ☁️ rjavier@vmware.com
❯ ls -1
my-bp/

/tmp/test-1026 on ☁️ rjavier@vmware.com
❯ ls -1 my-bp/

jkutner added 5 commits March 3, 2021 11:33
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner
Copy link
Member Author

jkutner commented Mar 3, 2021

@jromero fixed all three issues

@jromero
Copy link
Member

jromero commented Mar 3, 2021

@jkutner, verified issues above were resolved. Left a single nitpick but feel free to merge.

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner merged commit f708917 into main Mar 4, 2021
@jkutner jkutner deleted the jkutner/new-buildpack-toml-keys branch March 4, 2021 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a buildpack scaffold command
5 participants