Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ HELP.md
.idea
out/
.tmp/

kaniko/
layers/config/
layers/group.toml
layers/kaniko/
layers/plan.toml
layers/samples_curl/
18 changes: 18 additions & 0 deletions builders/bionic/builder.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Buildpacks to include in builder
[[buildpacks]]
id = "samples/curl"
version = "0.0.1"
uri = "../../extensions/curl"
Copy link

@cmoulliard cmoulliard Oct 11, 2021

Choose a reason for hiding this comment

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

If the extensions uri is part of the [[buildpacks]] block, how the builder tool will be able to package within the image, the buildpacks containing the bin/detect, bin/build vs extensions as the existing uri parameter is used to fetch buildpacks content only ?

Why don't we package the extensions part of a separate block [[extensions]].
Why such a proposition:

  • To be able to resolve the problem reported in my previous remark when the builder tool is creating an image,
  • To allow to add new extensions when new builder images are created independently of the existing buildpacks
  • To make the extension independent of the buildpacks*

*: If the buildpack detects that a tool, package is needed (curl, maven, java, ...), then it can report (maven 3.x is needed), then the extension phase-step could then be called to install the corresponding tool/command (e.g curl, java, maven, ... ) for the suggested version before the build phase is called.

REMARK: That implies that an extension is designed as a kind of module to install according to the name of the extension, what the name refers instead of zillions of packages

Copy link
Member

Choose a reason for hiding this comment

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

Strongly agree -- let's add a separate [[extensions]] table.

Also, can we do the same with [[order]] and create a separate [[order-ext]] table?

Choose a reason for hiding this comment

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

Also, can we do the same with [[order]] and create a separate [[order-ext]] table?

I think that we need such an order table but how will it be possible to it them easily as ideally the extensions should be independent.

Will the builder be able to understand that java should be installed before maven, that curl should be the first ....

Instead of defining a specific order I would prefer to delegate to the detect phase of the buikldpack the responsibility to report to the extension phase (= optional step taking place before the build phase if extensions exist) what it is needed and required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Submitted a PR for this change: #115.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is an interesting question about the order. My understanding is from the RFC is that extensions should always come first in the order. The separate [[order-ext]] table is a bit confusing to me, as what would happen if multiple groups are defined there? This would change the lifecycle implementation (detect would happen separately for extensions vs. buildpacks).


[[buildpacks]]
id = "samples/rebasable"
version = "0.0.1"
uri = "../../extensions/rebasable"

[[buildpacks]]
id = "samples/java-maven"
version = "0.0.1"
Expand All @@ -19,6 +29,14 @@ uri = "docker://cnbs/sample-package:hello-universe"

# Order used for detection
[[order]]
[[order.group]]
id = "samples/curl"
version = "0.0.1"

[[order.group]]
id = "samples/rebasable"
version = "0.0.1"

[[order.group]]
id = "samples/java-maven"
version = "0.0.1"
Expand Down
8 changes: 8 additions & 0 deletions cnb/buildpacks/samples_use_curl/0.0.1/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo "Running 'curl google.com' ......"
echo
echo
echo
echo
curl google.com
3 changes: 3 additions & 0 deletions cnb/buildpacks/samples_use_curl/0.0.1/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exit 0
9 changes: 9 additions & 0 deletions cnb/buildpacks/samples_use_curl/0.0.1/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
api = "0.7"

[buildpack]
id = "samples/use_curl"
version = "0.0.1"
name = "Buildpack using curl"

[[stacks]]
id = "*"
36 changes: 36 additions & 0 deletions cnb/ext/samples_curl/0.0.1/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eo pipefail

# INPUT ARGUMENTS
platform_dir=$2
env_dir=${platform_dir}/env
output_dir=$1
plan_path=$3

# Create Dockerfile
cat << EOF > ${output_dir}/Dockerfile
ARG base_image
FROM \${base_image}

ARG some_arg
RUN echo \${some_arg} > /opt/arg.txt

ARG build_id=0
RUN echo \${build_id}

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
EOF

# Create build.toml
cat << EOF > ${output_dir}/build.toml
[[args]]
name = "some_arg"
value = "some-arg-build-value"
EOF

# Create launch.toml
cat << EOF > ${output_dir}/launch.toml
[[args]]
name = "some_arg"
value = "some-arg-launch-value"
EOF
5 changes: 5 additions & 0 deletions cnb/ext/samples_curl/0.0.1/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail

# Always detect
exit 0
8 changes: 8 additions & 0 deletions cnb/ext/samples_curl/0.0.1/extension.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.7"

[extension]
id = "samples/curl"
name = "Curl Extension"
version = "0.0.1"
homepage = "https://github.com/buildpacks/samples/tree/main/extensions/curl"
description = "This extension always installs the latest version of curl."
9 changes: 9 additions & 0 deletions cnb/ext/samples_rebasable/0.0.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG base_image
FROM ${base_image}
ARG build_id=0

LABEL io.buildpacks.rebasable=true

# TODO: replace with real package
RUN echo
# RUN curl -L https://example.com/mypkg-install | sh # installs to /opt
8 changes: 8 additions & 0 deletions cnb/ext/samples_rebasable/0.0.1/extension.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.7"

[extension]
id = "samples/rebasable"
name = "Rebasable Extension"
version = "0.0.1"
homepage = "https://github.com/buildpacks/samples/tree/main/extensions/rebasable"
description = "This extension is rebasable because it creates a single directory under /opt."
36 changes: 36 additions & 0 deletions extensions/curl/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eo pipefail

# INPUT ARGUMENTS
platform_dir=$2
env_dir=${platform_dir}/env
output_dir=$1
plan_path=$3

# Create Dockerfile
cat << EOF > ${output_dir}/Dockerfile
ARG base_image
FROM \${base_image}

ARG some_arg
RUN echo \${some_arg} > /opt/arg.txt

ARG build_id=0
RUN echo \${build_id}

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
EOF

# Create build.toml
cat << EOF > ${output_dir}/build.toml
[[args]]
name = "some_arg"
value = "some-arg-build-value"
EOF

# Create launch.toml
cat << EOF > ${output_dir}/launch.toml
[[args]]
name = "some_arg"
value = "some-arg-launch-value"
EOF
5 changes: 5 additions & 0 deletions extensions/curl/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail

# Always detect
exit 0
8 changes: 8 additions & 0 deletions extensions/curl/extension.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.7"

[extension]
id = "samples/curl"
name = "Curl Extension"
version = "0.0.1"
homepage = "https://github.com/buildpacks/samples/tree/main/extensions/curl"
description = "This extension always installs the latest version of curl."
8 changes: 8 additions & 0 deletions extensions/rebasable/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG base_image
FROM ${base_image}
ARG build_id=0

LABEL io.buildpacks.rebasable=true

# TODO: replace with real package
RUN curl -L https://example.com/mypkg-install | sh # installs to /opt
8 changes: 8 additions & 0 deletions extensions/rebasable/extension.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.7"

[extension]
id = "samples/rebasable"
name = "Rebasable Extension"
version = "0.0.1"
homepage = "https://github.com/buildpacks/samples/tree/main/extensions/rebasable"
description = "This extension is rebasable because it creates a single directory under /opt."
Empty file added layers/empty-plan.toml
Empty file.
18 changes: 18 additions & 0 deletions layers/order.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[order]]
[[order.group]]
id = "samples/curl"
version = "0.0.1"
extension = true
optional = true

[[order.group]]
id = "samples/rebasable"
version = "0.0.1"
extension = true
optional = true

[[order.group]]
id = "samples/use_curl"
version = "0.0.1"
extension = false
optional = false
5 changes: 4 additions & 1 deletion stacks/bionic/run/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ ARG stack_id
LABEL io.buildpacks.stack.id="${stack_id}"

# Set user and group (as declared in base image)
USER ${CNB_USER_ID}:${CNB_GROUP_ID}
USER ${CNB_USER_ID}:${CNB_GROUP_ID}

# TODO: add genpkgs
COPY genpkgs /cnb/image/genpkgs