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

feat: s2i builder with preliminary node support #923

Merged
merged 24 commits into from
Apr 5, 2022

Conversation

lkingland
Copy link
Member

@lkingland lkingland commented Mar 30, 2022

Changes

  • 🎁 Source-to-Image Builder implementation which can be specified with --builder=s2i
  • 🎁 Adds preliminary support for building Node.js Functions with the s2i builder.

/kind enhancement

First step towards accomplishing #908

@knative-prow knative-prow bot added kind/enhancement size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 30, 2022
@knative-prow
Copy link

knative-prow bot commented Mar 30, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 30, 2022
@lkingland lkingland marked this pull request as draft March 30, 2022 02:45
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 30, 2022
@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #923 (ed0f767) into main (739cded) will increase coverage by 2.22%.
The diff coverage is 44.30%.

@@            Coverage Diff             @@
##             main     #923      +/-   ##
==========================================
+ Coverage   43.85%   46.07%   +2.22%     
==========================================
  Files          55       56       +1     
  Lines        5163     7395    +2232     
==========================================
+ Hits         2264     3407    +1143     
- Misses       2576     3660    +1084     
- Partials      323      328       +5     
Impacted Files Coverage Δ
client.go 61.94% <0.00%> (+2.01%) ⬆️
cmd/completion_util.go 0.00% <0.00%> (ø)
docker/docker_client.go 82.52% <ø> (+0.57%) ⬆️
s2i/builder.go 32.69% <32.69%> (ø)
cmd/build.go 60.49% <70.83%> (+0.86%) ⬆️
cmd/root.go 72.28% <100.00%> (+1.66%) ⬆️
cmd/list.go 56.25% <0.00%> (-3.40%) ⬇️
cmd/info.go 24.77% <0.00%> (-2.38%) ⬇️
function_buildtype.go 92.30% <0.00%> (-2.14%) ⬇️
cmd/run.go 71.42% <0.00%> (-1.30%) ⬇️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a4cebb...ed0f767. Read the comment docs.

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 31, 2022
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 31, 2022
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2022
@matejvasek
Copy link
Contributor

@lkingland why the changes to the node/go templates?

@lkingland
Copy link
Member Author

@lkingland why the changes to the node/go templates?

Builders are no longer defined in a template's manifest, because a Function can be built with either a Buildpack or an S2I builder, and thus the default is dependant on the builder chosen at build time.

These defaults should have been in the code from the beginning, and this is the forcing function.

@matejvasek
Copy link
Contributor

These defaults should have been in the code from the beginning, and this is the forcing function.

I think we had defaults in code and then removed it.

@matejvasek
Copy link
Contributor

matejvasek commented Apr 4, 2022

But the defaults are only for embedded templates. We will have to update manifest.yaml structure latter before 1.0.

@matejvasek
Copy link
Contributor

@lkingland s2i build is not working with podman.
Probably ok for now, but we should put it into documentation.

openshift/source-to-image#1082

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 4, 2022
@matejvasek
Copy link
Contributor

containers/podman#13770

@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 4, 2022
s2i/builder.go Outdated Show resolved Hide resolved
s2i/builder.go Outdated Show resolved Hide resolved
Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

Looks like a great first step into s2i builds. There are some things I think we'll want to consider in the long run, such as how we deal with chained builds (important to avoid having 500MB application images), and perhaps other things of a similar nature. A few questions within, but overall lgtm.

// DefaultBuilderImages for Pack builders indexed by Runtime Language
var DefaultBuilderImages = map[string]string{
"node": "gcr.io/paketo-buildpacks/builder:base",
"go": "gcr.io/paketo-buildpacks/builder:base",
Copy link
Member

Choose a reason for hiding this comment

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

This won't really work for Go functions though, will it? They need the scaffolding that is in the buildpack as well, right?

Copy link
Member Author

@lkingland lkingland Apr 5, 2022

Choose a reason for hiding this comment

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

It is my understanding that the base is the same, but the buildpack builder will still apply any buildpacks defined, which include ghcr.io/boson-project/go-function-buildpack:tip, which has the scaffolding. The S2I builder, when updated to support Go, will of course ignore that and use its own method, which I presume will be a single builder image that includes everything required.

Copy link
Member

Choose a reason for hiding this comment

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

It is my understanding that the base is the same, but the buildpack builder will still apply any buildpacks defined, which include ghcr.io/boson-project/go-function-buildpack:tip, which has the scaffolding.

Yes, this is the case, if it is explicitly provided, for example in a func.yaml file in the buildpacks field. Is that what you are expecting? Without that, the scaffold isn't there.

}

cmd.Flags().StringP("builder", "b", "", "Buildpack builder, either an as a an image name or a mapping name.\nSpecified value is stored in func.yaml for subsequent builds.")
cmd.Flags().StringP("builder", "b", "pack", "builder to use when creating the underlying image. Currently supported builders are 'pack' and 's2i'.")
cmd.Flags().StringP("builder-image", "", "", "builder image, either an as a an image name or a mapping name.\nSpecified value is stored in func.yaml for subsequent builds. ($FUNC_BUILDER_IMAGE)")
Copy link
Member

Choose a reason for hiding this comment

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

It strikes me as clumsy that there is both a builder and build-image flag. I wonder if it should rather be something like strategy and build-image (or build), where strategy is a fixed set (buildpack, s2i, etc) and build-image or build is an image address.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. We should try to consolidate this a little bit. I wouldn't block this PR on this though. But it is something we should try to tackle as soon as possilbe. To provide consistency and more clarity for users.

Copy link
Member Author

Choose a reason for hiding this comment

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

In order to not block this PR, I have opened a new issue to discuss better flag naming: #942

go.mod Show resolved Hide resolved
s2i/builder.go Show resolved Hide resolved
return errors.New("Unable to build via the s2i builder.")
}

builder, _, err := strategies.Strategy(client, cfg, build.Overrides{})
Copy link
Member

Choose a reason for hiding this comment

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

Am I correct to understand this is the "docker" build strategy? One of the other build strategies that s2i uses is "binary" which we may consider leveraging for push-to-cluster-my-function-and-build-it-there, since that's exactly what it does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is my understanding this is the Docker method. I am not familiar with the binary strategy, but I will look into it.

)
defer cleanup()

run(t, bin, prefix, "create", "-v", "--language=node", cwd)
Copy link
Member

Choose a reason for hiding this comment

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

Did you test with typescript? I don't know if s2i can seamlessly do that or not, but it sure would be nice

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 have not run a typescript test yet, but I am hopeful as well.

@matejvasek
Copy link
Contributor

matejvasek commented Apr 4, 2022

/lgtm

@matejvasek
Copy link
Contributor

matejvasek commented Apr 4, 2022

/hold
for others

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 4, 2022
Copy link
Contributor

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Apr 5, 2022
@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 5, 2022
@matejvasek
Copy link
Contributor

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Apr 5, 2022
@lkingland lkingland removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 5, 2022
@knative-prow knative-prow bot merged commit a91bcc5 into knative:main Apr 5, 2022
@lance lance mentioned this pull request Apr 6, 2022
@lkingland lkingland deleted the lkingland/s2i-node-builder branch September 20, 2022 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/enhancement lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants