Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Adds template for Cloud Native Buildpacks (#67)
Browse files Browse the repository at this point in the history
* Add Cloud Native Buildpacks build-template

Signed-off-by: Emily Casey <ecasey@pivotal.io>

* Update CNB build template to use updated lifecycle and v3alpaha2 images

Signed-off-by: Emily Casey <ecasey@pivotal.io>

* Fixes buildpacks/README-CF.md

Signed-off-by: Emily Casey <ecasey@pivotal.io>

* Writes group.toml and plan.toml in layers dir

Signed-off-by: Emily Casey <ecasey@pivotal.io>

* Chown app dir in prepare step

Signed-off-by: Emily Casey <ecasey@pivotal.io>
  • Loading branch information
ekcasey authored and knative-prow-robot committed Mar 6, 2019
1 parent b296278 commit 0091c3b
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 11 deletions.
4 changes: 2 additions & 2 deletions buildpack/README.md → buildpacks/README-CF.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the resulting application image to a Docker registry under the provided name.
## Create the template

```
kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/buildpack/buildpack.yaml
kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/buildpacks/cf.yaml
```

## Parameters
Expand Down Expand Up @@ -43,7 +43,7 @@ spec:
url: https://github.com/my-user/my-repo
revision: master
template:
name: buildpack
name: buildpacks-cloudfoundry
arguments:
- name: IMAGE
value: us.gcr.io/my-project/my-app
Expand Down
48 changes: 48 additions & 0 deletions buildpacks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Buildpack V3

This build template builds source into a container image using [Cloud Native Buildpacks](https://buildpacks.io).

The Cloud Native Buildpacks website describes v3 buildpacks as:

> ... pluggable, modular tools that translate source code into container-ready artifacts
> such as OCI images. They replace Dockerfiles in the app development lifecycle with a higher level
> of abstraction. ... Cloud Native Buildpacks embrace modern container standards, such as the OCI
> image format. They take advantage of the latest capabilities of these standards, such as remote
> image layer rebasing on Docker API v2 registries.
**Note**: The current Cloud Foundry buildpacks are available in the [CF template](README-CF.md).

## Create the template

```
kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/buildpacks/cnb.yaml
```

## Parameters

* **IMAGE:** The image you wish to create. For example, "repo/example", or "example.com/repo/image". (_required_)
* **RUN_IMAGE:** The run image buildpacks will use as the base for IMAGE. (_default:_ `packs/run:v3alpha2`)
* **BUILDER_IMAGE** The image on which builds will run. ( default: `packs/samples:v3alpha2`)
* **USE_CRED_HELPERS:** Use Docker credential helpers. Set to `"true"` or `"false"` as string values. (_default:_ `"true"`)
* **CACHE** The name of the persistent app cache volume (_default:_ an empty directory -- effectively no cache)
* **USER_ID** The user ID of the builder image user (_default:_ 1000)
* **GROUP_ID** The group ID of the builder image user (_default:_ 1000)

## Usage

```
apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
name: cnb-example-build
spec:
source:
git:
url: https://github.com/my-user/my-repo
revision: master
template:
name: buildpacks-cnb
arguments:
- name: IMAGE
value: us.gcr.io/my-project/my-app
```
2 changes: 1 addition & 1 deletion buildpack/buildpack.yaml → buildpacks/cf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: build.knative.dev/v1alpha1
kind: BuildTemplate
metadata:
name: buildpack
name: buildpacks-cloudfoundry
spec:
parameters:
- name: IMAGE
Expand Down
95 changes: 95 additions & 0 deletions buildpacks/cnb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
apiVersion: build.knative.dev/v1alpha1
kind: BuildTemplate
metadata:
name: buildpacks-cnb
spec:
parameters:
- name: IMAGE
description: The image you wish to create. For example, "repo/example", or "example.com/repo/image".
- name: RUN_IMAGE
description: The run image buildpacks will use as the base for IMAGE.
default: packs/run:v3alpha2
- name: BUILDER_IMAGE
description: The builder image (must include v3 lifecycle and compatible buildpacks).
default: packs/samples:v3alpha2
- name: USE_CRED_HELPERS
description: Use Docker credential helpers for Google's GCR, Amazon's ECR, or Microsoft's ACR.
default: 'true'
- name: CACHE
description: The name of the persistent app cache volume
default: empty-dir
- name: USER_ID
description: The user ID of the builder image user
default: "1000"
- name: GROUP_ID
description: The group ID of the builder image user
default: "1000"

steps:
- name: prepare
image: alpine
command: ["/bin/sh"]
args:
- "-c"
- >
chown -R "${USER_ID}:${GROUP_ID}" "/builder/home" &&
chown -R "${USER_ID}:${GROUP_ID}" /layers &&
chown -R "${USER_ID}:${GROUP_ID}" /workspace
volumeMounts:
- name: "${CACHE}"
mountPath: /layers
imagePullPolicy: Always
- name: detect
image: ${BUILDER_IMAGE}
command: ["/lifecycle/detector"]
args:
- "-app=/workspace"
- "-group=/layers/group.toml"
- "-plan=/layers/plan.toml"
volumeMounts:
- name: "${CACHE}"
mountPath: /layers
imagePullPolicy: Always
- name: analyze
image: ${BUILDER_IMAGE}
command: ["/lifecycle/analyzer"]
args:
- "-layers=/layers"
- "-helpers=${USE_CRED_HELPERS}"
- "-group=/layers/group.toml"
- "${IMAGE}"
volumeMounts:
- name: "${CACHE}"
mountPath: /layers
imagePullPolicy: Always
- name: build
image: ${BUILDER_IMAGE}
command: ["/lifecycle/builder"]
args:
- "-layers=/layers"
- "-app=/workspace"
- "-group=/layers/group.toml"
- "-plan=/layers/plan.toml"
volumeMounts:
- name: "${CACHE}"
mountPath: /layers
imagePullPolicy: Always
- name: export
image: ${BUILDER_IMAGE}
command: ["/lifecycle/exporter"]
args:
- "-layers=/layers"
- "-helpers=${USE_CRED_HELPERS}"
- "-app=/workspace"
- "-image=${RUN_IMAGE}"
- "-group=/layers/group.toml"
- "${IMAGE}"
volumeMounts:
- name: "${CACHE}"
mountPath: /layers
imagePullPolicy: Always

volumes:
- name: empty-dir
emptyDir: {}
14 changes: 14 additions & 0 deletions test/build-cf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
name: cf-build
spec:
source:
git:
url: https://github.com/my-user/my-repo
revision: v1.0
template:
name: buildpacks-cloudfoundry
arguments:
- name: IMAGE
value: us.gcr.io/my-project/my-app
4 changes: 2 additions & 2 deletions test/build-buildpack.yaml → test/build-cnb.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
name: buildpack-build
name: cnb-build
spec:
source:
git:
url: https://github.com/my-user/my-repo
revision: v1.0
template:
name: buildpack
name: buildpacks-cnb
arguments:
- name: IMAGE
value: us.gcr.io/my-project/my-app
29 changes: 23 additions & 6 deletions test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,34 @@ source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/e2e-tests.s

# Helper functions.

function run_buildpack_test() {
subheader "Running buildpack test"
function run_cloudfoundry_buildpacks_test() {
subheader "Running cloudfoundry test"
echo "Installing template:"
kubectl apply -f buildpack/buildpack.yaml || return 1
kubectl apply -f buildpacks/cf.yaml || return 1
echo "Checking that template is installed:"
kubectl get buildtemplates || return 1
echo "Creating build:"
kubectl apply -f test/build-buildpack.yaml || return 1
kubectl apply -f test/build-cf.yaml || return 1
# Wait 5s for processing to start
sleep 5
echo "Checking that build was started:"
kubectl get build buildpack-build -oyaml
kubectl get build cf-build -oyaml
# TODO(adrcunha): Add proper verification.
}


function run_cloud_native_buildpacks_test() {
subheader "Running cloud native buildpacks test"
echo "Installing template:"
kubectl apply -f buildpacks/cnb.yaml || return 1
echo "Checking that template is installed:"
kubectl get buildtemplates || return 1
echo "Creating build:"
kubectl apply -f test/build-cnb.yaml || return 1
# Wait 5s for processing to start
sleep 5
echo "Checking that build was started:"
kubectl get build cnb-build -oyaml
# TODO(adrcunha): Add proper verification.
}

Expand All @@ -54,6 +70,7 @@ fi
header "Running tests"

# TODO(adrcunha): Add more tests.
run_buildpack_test || fail_test
run_cloudfoundry_buildpacks_test || fail_test
run_cloud_native_buildpacks_test || fail_test

success

0 comments on commit 0091c3b

Please sign in to comment.