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

Added support for inline buildpacks #1166

Merged
merged 12 commits into from
Jul 11, 2021
Merged

Added support for inline buildpacks #1166

merged 12 commits into from
Jul 11, 2021

Conversation

jkutner
Copy link
Member

@jkutner jkutner commented May 7, 2021

Summary

This is an implementation of Inline Buildpacks described in RFC-0048.

Output

Give an app with a project.toml containing:

[project]
id = "my-app"

[[build.buildpacks]]
id = "my/inline"

  [build.buildpacks.script]
  api = "0.4"
  inline = "echo 'hello!'"

Before

$ pack build inline-test
...
ERROR: failed to build: invalid buildpack string my/inline@

After

$ pack build inline-test
...
===> DETECTING
my/inline 0.0.0
===> ANALYZING
===> RESTORING
===> BUILDING
hello!
...
Successfully built image inline-test

Documentation

@jkutner jkutner requested a review from a team as a code owner May 7, 2021 14:52
@github-actions github-actions bot added this to the 0.19.0 milestone May 7, 2021
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label May 7, 2021
@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #1166 (63df5b4) into main (f3d6be6) will decrease coverage by 0.08%.
The diff coverage is 64.45%.

❗ Current head 63df5b4 differs from pull request most recent head 0671626. Consider uploading reports for the commit 0671626 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1166      +/-   ##
==========================================
- Coverage   80.96%   80.89%   -0.07%     
==========================================
  Files         136      136              
  Lines        8316     8369      +53     
==========================================
+ Hits         6732     6769      +37     
- Misses       1158     1167       +9     
- Partials      426      433       +7     
Flag Coverage Δ
os_linux 80.51% <66.16%> (-0.01%) ⬇️
os_macos 78.04% <66.16%> (+0.01%) ⬆️
os_windows 80.80% <64.45%> (-0.07%) ⬇️
unit 80.51% <66.16%> (-0.06%) ⬇️

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

new_buildpack.go Outdated Show resolved Hide resolved
build.go Outdated
if err != nil {
return nil, nil, errors.Wrap(err, "Could not create temporary inline buildpack")
}
println(pathToInlineBuildpack)
Copy link
Member

Choose a reason for hiding this comment

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

What is this? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

code gnomes put that there

@jkutner jkutner requested a review from jromero May 8, 2021 13:55
shell = "/bin/sh"
}

binBuild := fmt.Sprintf(`#!%s
Copy link
Contributor

Choose a reason for hiding this comment

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

#! looks like it could cause problems on windows machines. And might be useful to have an integration test with one of these inline buildpacks just to show things do work in both envs.

Copy link
Member Author

Choose a reason for hiding this comment

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

do you mean windows as the host machine, or windows containers (or both)?

Copy link
Contributor

@dwillist dwillist May 14, 2021

Choose a reason for hiding this comment

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

I'm thinking windows containers. #! will just comment out the first line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we have a different default shell for windows containers?

Copy link
Member

Choose a reason for hiding this comment

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

Should we have a different default shell for windows containers?

Technically, Windows doesn't need an explicit shell chosen, nor a shebang line, instead it needs an appropriate file suffix (detect.bat / build.bat) since cmd.Start() will automatically call the all .bat files with cmd.exe. If the suffix is .ps1, they would be called with powershell (if it's present).

Unfortunately though, the #! will be treated as invalid syntax, not as a comment (which are :: or REM in .bat files)

If it's possible to detect the container/daemon OS here, I think it's fine to assume the syntax is .bat when Windows. If it's not possible to detect, I'd also feel ok with a special case like shell = "cmd.exe" triggering the Windows behavior (add .bat suffixes, remove shebang).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that would work. I wrote a hybrid buildpack that does just that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll think about it. that would mean writing either an invalid build or build.bat in every case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this to create the hybrid buildpack (both build and build.bat)

Copy link
Member

Choose a reason for hiding this comment

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

@jkutner I think that we would still need to remove the shebang in the windows case. https://github.com/buildpacks/pack/pull/1166/files#r634567908

Copy link
Member Author

Choose a reason for hiding this comment

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

@dfreilich fixed in 81c66ff

@dfreilich dfreilich modified the milestones: 0.19.0, 0.20.0 Jun 15, 2021
@jkutner jkutner requested a review from dwillist June 24, 2021 19:32
@jkutner
Copy link
Member Author

jkutner commented Jun 24, 2021

@jromero most of the codecov warning are from error cases where I'm not checking some error from the file system (like creating a file). How should I handle that?

@dfreilich
Copy link
Member

@jkutner We disregard codecov/patch in most cases, as long as there are appropriate tests.

shell = "/bin/sh"
}

binBuild := fmt.Sprintf(`#!%s
Copy link
Member

Choose a reason for hiding this comment

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

@jkutner I think that we would still need to remove the shebang in the windows case. https://github.com/buildpacks/pack/pull/1166/files#r634567908

build_test.go Outdated Show resolved Hide resolved
new_buildpack.go Show resolved Hide resolved
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

Looks great for me! The UA you have in the initial post is perfect :D

Can someone with access to Windows do UA for that? @micahyoung ?

@aemengo
Copy link
Contributor

aemengo commented Jul 2, 2021

Looks great for me! The UA you have in the initial post is perfect :D

Can someone with access to Windows do UA for that? @micahyoung ?

I'll try to get this done.


EDIT:

Looks great to me! 👍🏾

pr-1166-acceptance-windows.mov

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
…to accept URI buildpacks

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>
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 and others added 2 commits July 11, 2021 22:48
Signed-off-by: Joe Kutner <jpkutner@gmail.com>

Co-authored-by: David Freilich <freilich.david@gmail.com>
Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@dfreilich dfreilich merged commit c942b25 into main Jul 11, 2021
@dfreilich dfreilich deleted the jkutner/rfc-0048 branch July 11, 2021 20:01
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.

None yet

6 participants