From 886b6a2902f44a9a1d5922a04c4674c1116fcc47 Mon Sep 17 00:00:00 2001 From: David Freilich Date: Mon, 13 Jul 2020 17:33:19 -0400 Subject: [PATCH 1/3] Rename buildpacks-v3 task to buildpacks The suffix v3 was a piece of buildpacks history, stemming from the initial start of the buildpacks concept, but isn't relevant to current consumers of the buildpacks task. To simplify it, and to fit with other task styles, we are removing v3 Additionally, we are updating the list of suggested builders, to reflect the current status of pack builders. NOTE: Paketo builders currently have a bug and don't work in Tekton, and until that issue is resolved, we aren't adding them in the list. Signed-off-by: David Freilich --- task/{buildpacks-v3 => buildpacks}/0.1/OWNERS | 0 .../0.1/README.md | 25 ++++++++----------- .../0.1/buildpacks.yaml} | 4 +-- .../0.1/tests/pre-apply-task-hook.sh | 0 .../0.1/tests/resources.yaml | 0 .../0.1/tests/run.yaml | 4 +-- 6 files changed, 15 insertions(+), 18 deletions(-) rename task/{buildpacks-v3 => buildpacks}/0.1/OWNERS (100%) rename task/{buildpacks-v3 => buildpacks}/0.1/README.md (82%) rename task/{buildpacks-v3/0.1/buildpacks-v3.yaml => buildpacks/0.1/buildpacks.yaml} (98%) rename task/{buildpacks-v3 => buildpacks}/0.1/tests/pre-apply-task-hook.sh (100%) rename task/{buildpacks-v3 => buildpacks}/0.1/tests/resources.yaml (100%) rename task/{buildpacks-v3 => buildpacks}/0.1/tests/run.yaml (96%) diff --git a/task/buildpacks-v3/0.1/OWNERS b/task/buildpacks/0.1/OWNERS similarity index 100% rename from task/buildpacks-v3/0.1/OWNERS rename to task/buildpacks/0.1/OWNERS diff --git a/task/buildpacks-v3/0.1/README.md b/task/buildpacks/0.1/README.md similarity index 82% rename from task/buildpacks-v3/0.1/README.md rename to task/buildpacks/0.1/README.md index 1166b638e6..d5c77a6407 100644 --- a/task/buildpacks-v3/0.1/README.md +++ b/task/buildpacks/0.1/README.md @@ -3,7 +3,7 @@ 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: +The Cloud Native Buildpacks website describes buildpacks as: > ... pluggable, modular tools that translate source code into container-ready > artifacts such as OCI images. They replace Dockerfiles in the app development @@ -15,21 +15,19 @@ The Cloud Native Buildpacks website describes v3 buildpacks as: ## Install the Task ``` -kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/buildpacks-v3/0.1/buildpacks-v3.yaml +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/buildpacks/0.1/buildpacks.yaml ``` > **NOTE:** This task is currently only compatible with Tekton **v0.11.0** and above, and CNB Platform API 0.3 (lifecycle v0.7.0 and above). For previous Platform API versions, [see below](#previous-platform-api-versions). ## Parameters -* **`BUILDER_IMAGE`**: The image on which builds will run. (must include v3 lifecycle and compatible buildpacks; _required_) +* **`BUILDER_IMAGE`**: The image on which builds will run. (must include lifecycle and compatible buildpacks; _required_) -* **`CACHE`**: The name of the persistent app cache volume. (_default:_ an empty - directory -- effectively no cache) +* **`CACHE`**: The name of the persistent app cache volume. (_default:_ an empty directory -- effectively no cache) * **`PLATFORM_DIR`**: A directory containing platform provided configuration, such as environment variables. - Files of the format `/platform/env/MY_VAR` with content `my-value` will be translated by the lifecycle into - environment variables provided to buildpacks. For more information, see the [buildpacks spec](https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-platform). (_default:_ an empty directory) + Files of the format `/platform/env/MY_VAR` with content `my-value` will be translated by the lifecycle into environment variables provided to buildpacks. For more information, see the [buildpacks spec](https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-platform). (_default:_ an empty directory) * **`USER_ID`**: The user ID of the builder image user, as a string value. (_default:_ `"1000"`) @@ -50,7 +48,7 @@ The `source` workspace holds the source to build. See `SOURCE_SUBPATH` above if ## Usage -This `TaskRun` will use the `buildpacks-v3` task to build the source code, then publish a container image. +This `TaskRun` will use the `buildpacks` task to build the source code, then publish a container image. ``` apiVersion: tekton.dev/v1beta1 @@ -59,7 +57,7 @@ metadata: name: example-run spec: taskRef: - name: buildpacks-v3 + name: buildpacks podTemplate: volumes: # Uncomment the lines below to use an existing cache @@ -97,12 +95,11 @@ spec: ### Example builders -Cloud Foundry: - - `cloudfoundry/cnb:bionic` - - `cloudfoundry/cnb:cflinuxfs3` - Heroku: - - `heroku/buildpacks:18` + - `heroku/buildpacks:18` → heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP + +Google: + - `gcr.io/buildpacks/builder:v1` → Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, and Python ## Previous Platform API Versions diff --git a/task/buildpacks-v3/0.1/buildpacks-v3.yaml b/task/buildpacks/0.1/buildpacks.yaml similarity index 98% rename from task/buildpacks-v3/0.1/buildpacks-v3.yaml rename to task/buildpacks/0.1/buildpacks.yaml index d29fb2a2c1..dba2ddea89 100644 --- a/task/buildpacks-v3/0.1/buildpacks-v3.yaml +++ b/task/buildpacks/0.1/buildpacks.yaml @@ -2,7 +2,7 @@ apiVersion: tekton.dev/v1beta1 kind: Task metadata: - name: buildpacks-v3 + name: buildpacks labels: app.kubernetes.io/version: "0.1" annotations: @@ -22,7 +22,7 @@ spec: params: - name: BUILDER_IMAGE - description: The image on which builds will run (must include v3 lifecycle and compatible buildpacks). + description: The image on which builds will run (must include lifecycle and compatible buildpacks). - name: CACHE description: The name of the persistent app cache volume. default: empty-dir diff --git a/task/buildpacks-v3/0.1/tests/pre-apply-task-hook.sh b/task/buildpacks/0.1/tests/pre-apply-task-hook.sh similarity index 100% rename from task/buildpacks-v3/0.1/tests/pre-apply-task-hook.sh rename to task/buildpacks/0.1/tests/pre-apply-task-hook.sh diff --git a/task/buildpacks-v3/0.1/tests/resources.yaml b/task/buildpacks/0.1/tests/resources.yaml similarity index 100% rename from task/buildpacks-v3/0.1/tests/resources.yaml rename to task/buildpacks/0.1/tests/resources.yaml diff --git a/task/buildpacks-v3/0.1/tests/run.yaml b/task/buildpacks/0.1/tests/run.yaml similarity index 96% rename from task/buildpacks-v3/0.1/tests/run.yaml rename to task/buildpacks/0.1/tests/run.yaml index c20554de46..40921ea9c0 100644 --- a/task/buildpacks-v3/0.1/tests/run.yaml +++ b/task/buildpacks/0.1/tests/run.yaml @@ -23,9 +23,9 @@ spec: value: "" - name: deleteExisting value: "true" - - name: buildpacks-v3 + - name: buildpacks taskRef: - name: buildpacks-v3 + name: buildpacks runAfter: - fetch-repository workspaces: From 8ca247f68fecf7f91262779fe8c1cc3786a6f746 Mon Sep 17 00:00:00 2001 From: David Freilich Date: Thu, 16 Jul 2020 10:48:40 -0400 Subject: [PATCH 2/3] Update Buildpacks task to use Creator binary, in place of calling individual phases With the release of Platform API 0.3 (implemented in github.com/buildpacks/lifecycle v0.7.0), there is a creator binary that simplifies the CNB experience; calling it runs all of the individual lifecycle phases, and minimizes the number of separate containers needed for the process. As such, we moved the buildpacks task to use it. At the same time, it is also helpful, in some scenarios, to run the individual phases; it allows for greater control of secrets, amongst other things. As such, we moved the original task to buildpacks-separate-phases to allow users the choice. This commit also updates the READMEs, making them a bit clearer about what CNBs are and what the tasks do, as well as adding in the Paketo builders to the example builders. Signed-off-by: David Freilich --- task/buildpacks-separate-phases/0.1/OWNERS | 20 +++ task/buildpacks-separate-phases/0.1/README.md | 122 ++++++++++++++ .../0.1/buildpacks-separate-phases.yaml | 158 ++++++++++++++++++ .../0.1/tests/pre-apply-task-hook.sh | 8 + .../0.1/tests/resources.yaml | 31 ++++ .../0.1/tests/run.yaml | 65 +++++++ task/buildpacks/0.1/README.md | 23 ++- task/buildpacks/0.1/buildpacks.yaml | 104 ++++-------- 8 files changed, 453 insertions(+), 78 deletions(-) create mode 100644 task/buildpacks-separate-phases/0.1/OWNERS create mode 100644 task/buildpacks-separate-phases/0.1/README.md create mode 100644 task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml create mode 100755 task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh create mode 100644 task/buildpacks-separate-phases/0.1/tests/resources.yaml create mode 100644 task/buildpacks-separate-phases/0.1/tests/run.yaml diff --git a/task/buildpacks-separate-phases/0.1/OWNERS b/task/buildpacks-separate-phases/0.1/OWNERS new file mode 100644 index 0000000000..aed476af2b --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/OWNERS @@ -0,0 +1,20 @@ +approvers: +- jkutner +- hone +- nebhale +- sclevine +- ekcasey +- jromero +- ameyer-pivotal +- simonjjones + +reviewers: +- vdemeester +- ImJasonH +- jkutner +- hone +- sclevine +- ekcasey +- jromero +- ameyer-pivotal +- simonjjones \ No newline at end of file diff --git a/task/buildpacks-separate-phases/0.1/README.md b/task/buildpacks-separate-phases/0.1/README.md new file mode 100644 index 0000000000..8c2952bbaa --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/README.md @@ -0,0 +1,122 @@ +# Cloud Native Buildpacks + +This build template builds source into a container image using [Cloud Native +Buildpacks](https://buildpacks.io). To do that, it uses [builders](https://buildpacks.io/docs/concepts/components/builder/#what-is-a-builder) to run buildpacks against your application. + +Cloud Native Buildpacks are pluggable, modular tools that transform application source code into OCI images. They replace Dockerfiles in the app development lifecycle, and enable for swift rebasing of images and modular control over images (through the use of builders), among other benefits. This command uses a builder to construct the image, and pushes it to the registry provided. + +See also [`buildpacks`](../buildpacks) for the combined version of this task, which uses the [creator binary](https://github.com/buildpacks/spec/blob/platform/0.3/platform.md#operations), to run all of the [lifecycle phases](https://buildpacks.io/docs/concepts/components/lifecycle/#phases). This task, in contrast, runs all of the phases separately. + +## Install the Task + +``` +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml +``` + +> **NOTE:** This task is currently only compatible with Tekton **v0.11.0** and above, and CNB Platform API 0.3 (lifecycle v0.7.0 and above). For previous Platform API versions, [see below](#previous-platform-api-versions). + +## Parameters + +* **`BUILDER_IMAGE`**: The image on which builds will run. (must include lifecycle and compatible buildpacks; _required_) + +* **`CACHE`**: The name of the persistent app cache volume. (_default:_ an empty directory -- effectively no cache) + +* **`PLATFORM_DIR`**: A directory containing platform provided configuration, such as environment variables. + Files of the format `/platform/env/MY_VAR` with content `my-value` will be translated by the lifecycle into environment variables provided to buildpacks. For more information, see the [buildpacks spec](https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-platform). (_default:_ an empty directory) + +* **`USER_ID`**: The user ID of the builder image user, as a string value. (_default:_ `"1000"`) + +* **`GROUP_ID`**: The group ID of the builder image user, as a string value. (_default:_ `"1000"`) + +* **`PROCESS_TYPE`**: The default process type to set on the image. (_default:_ `"web"`) + +* **`SOURCE_SUBPATH`**: A subpath within the `source` input where the source to build is located. (_default:_ `""`) + +### Outputs + +* **`image`**: An `image`-type `PipelineResource` specifying the image that should + be built. + +## Workspaces + +The `source` workspace holds the source to build. See `SOURCE_SUBPATH` above if source is located within a subpath of this input. + +## Usage + +This `TaskRun` will use the `buildpacks` task to build the source code, then publish a container image. + +``` +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: example-run +spec: + taskRef: + name: buildpacks-separate-phases + podTemplate: + volumes: +# Uncomment the lines below to use an existing cache +# - name: my-cache +# persistentVolumeClaim: +# claimName: my-cache-pvc +# Uncomment the lines below to provide a platform directory +# - name: my-platform-dir +# persistentVolumeClaim: +# claimName: my-platform-dir-pvc + params: + - name: SOURCE_SUBPATH + value: + - name: BUILDER_IMAGE + value: +# Uncomment the lines below to use an existing cache +# - name: CACHE +# value: my-cache +# Uncomment the lines below to provide a platform directory +# - name: PLATFORM_DIR +# value: my-platform-dir + resources: + outputs: + - name: image + resourceSpec: + type: image + params: + - name: url + value: + workspaces: + - name: source + persistentVolumeClaim: + claimName: my-source-pvc +``` + +### Example builders +Paketo: +- `gcr.io/paketo-buildpacks/builder:base` → Ubuntu bionic base image with buildpacks for Java, NodeJS and Golang +- `gcr.io/paketo-buildpacks/builder:tiny` → Tiny base image (bionic build image, distroless run image) with buildpacks for Golang +- `gcr.io/paketo-buildpacks/builder:full-cf` → cflinuxfs3 base image with buildpacks for Java, .NET, NodeJS, Golang, PHP, HTTPD and NGINX +> NOTE: The `gcr.io/paketo-buildpacks/builder:full-cf` requires setting the USER_ID and GROUP_ID parameters to 2000, in order to work. + +Heroku: + - `heroku/buildpacks:18` → heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP + +Google: + - `gcr.io/buildpacks/builder:v1` → Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, and Python + +## Previous Platform API Versions + +Use one of the following commands to install a previous version of this task. Be sure to also supply a compatible builder image (`BUILDER_IMAGE` input) when running the task (i.e. one that has a lifecycle implementing the expected platform API). + +### CNB Platform API 0.2 + +Commit: [8c34055](https://github.com/tektoncd/catalog/tree/8c34055ea728413fb72af061e7bcbf1859a9fbd6/buildpacks#inputs) + +``` +kubectl -f https://raw.githubusercontent.com/tektoncd/catalog/8c34055ea728413fb72af061e7bcbf1859a9fbd6/buildpacks/buildpacks-v3.yaml +``` + +### CNB Platform API 0.1 + +Commit: [5c2ab7d6](https://github.com/tektoncd/catalog/tree/5c2ab7d6c3b2507d43b49577d7f1bee9c49ed8ab/buildpacks#inputs) + +``` +kubectl -f https://raw.githubusercontent.com/tektoncd/catalog/5c2ab7d6c3b2507d43b49577d7f1bee9c49ed8ab/buildpacks/buildpacks-v3.yaml +``` diff --git a/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml b/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml new file mode 100644 index 0000000000..964da3f921 --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml @@ -0,0 +1,158 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: buildpacks-separate-phases + labels: + app.kubernetes.io/version: "0.1" + annotations: + tekton.dev/pipelines.minVersion: "0.12.1" + tekton.dev/tags: image-build + tekton.dev/displayName: "buildpacks-separate-phases" +spec: + description: >- + The Buildpacks-Separate-Phases task builds source into a container image and pushes it to + a registry, using Cloud Native Buildpacks. This command separately calls the aspects of the + Cloud Native Buildpacks lifecycle, to provide more granular control over the construction of + the image. + + Cloud Native Buildpacks are pluggable, modular tools that transform application source code + into OCI images. They replace Dockerfiles in the app development lifecycle, and allow for swift + rebasing of images, and give modular control over images through the use of builders, among other + benefits. This command uses a builder to construct the image, and pushes it to the registry provided. + + params: + - name: BUILDER_IMAGE + description: The image on which builds will run (must include lifecycle and compatible buildpacks). + - name: CACHE + description: The name of the persistent app cache volume. + default: empty-dir + - name: PLATFORM_DIR + description: The name of the platform directory. + 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" + - name: PROCESS_TYPE + description: The default process type to set on the image. + default: "web" + - name: SOURCE_SUBPATH + description: A subpath within the `source` input where the source to build is located. + default: "" + + resources: + outputs: + - name: image + type: image + + workspaces: + - name: source + + stepTemplate: + env: + - name: CNB_PLATFORM_API + value: "0.3" + + steps: + - name: prepare + image: alpine + imagePullPolicy: Always + command: ["/bin/sh"] + args: + - "-c" + - > + chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/tekton/home" && + chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/layers" && + chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/cache" && + chown -R "$(params.USER_ID):$(params.GROUP_ID)" "$(workspaces.source.path)" + volumeMounts: + - name: layers-dir + mountPath: /layers + - name: $(params.CACHE) + mountPath: /cache + securityContext: + privileged: true + + - name: detect + image: $(params.BUILDER_IMAGE) + imagePullPolicy: Always + command: ["/cnb/lifecycle/detector"] + args: + - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" + - "-group=/layers/group.toml" + - "-plan=/layers/plan.toml" + volumeMounts: + - name: layers-dir + mountPath: /layers + - name: $(params.PLATFORM_DIR) + mountPath: /platform + + - name: analyze + image: $(params.BUILDER_IMAGE) + imagePullPolicy: Always + command: ["/cnb/lifecycle/analyzer"] + args: + - "-layers=/layers" + - "-group=/layers/group.toml" + - "-cache-dir=/cache" + - "$(resources.outputs.image.url)" + volumeMounts: + - name: $(params.CACHE) + mountPath: /cache + - name: layers-dir + mountPath: /layers + + - name: restore + image: $(params.BUILDER_IMAGE) + imagePullPolicy: Always + command: ["/cnb/lifecycle/restorer"] + args: + - "-group=/layers/group.toml" + - "-layers=/layers" + - "-cache-dir=/cache" + volumeMounts: + - name: $(params.CACHE) + mountPath: /cache + - name: layers-dir + mountPath: /layers + + - name: build + image: $(params.BUILDER_IMAGE) + imagePullPolicy: Always + command: ["/cnb/lifecycle/builder"] + args: + - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" + - "-layers=/layers" + - "-group=/layers/group.toml" + - "-plan=/layers/plan.toml" + volumeMounts: + - name: layers-dir + mountPath: /layers + - name: $(params.PLATFORM_DIR) + mountPath: /platform + + - name: export + image: $(params.BUILDER_IMAGE) + imagePullPolicy: Always + command: ["/cnb/lifecycle/exporter"] + args: + - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" + - "-layers=/layers" + - "-group=/layers/group.toml" + - "-cache-dir=/cache" + - "-process-type=$(params.PROCESS_TYPE)" + - "$(resources.outputs.image.url)" + volumeMounts: + - name: layers-dir + mountPath: /layers + - name: $(params.CACHE) + mountPath: /cache + + volumes: + - name: empty-dir + emptyDir: {} + - name: layers-dir + emptyDir: {} diff --git a/task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh b/task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh new file mode 100755 index 0000000000..e39fb789ab --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Add an internal registry as sidecar to the task so we can upload it directly +# from our tests without having to go to an external registry. +add_sidecar_registry ${TMPF} + +# Add git-clone +kubectl -n ${tns} apply -f ./task/git-clone/0.1/git-clone.yaml diff --git a/task/buildpacks-separate-phases/0.1/tests/resources.yaml b/task/buildpacks-separate-phases/0.1/tests/resources.yaml new file mode 100644 index 0000000000..cbb18684ab --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/tests/resources.yaml @@ -0,0 +1,31 @@ +apiVersion: tekton.dev/v1alpha1 +kind: PipelineResource +metadata: + name: buildpacks-app-image +spec: + type: image + params: + - name: url + value: localhost:5000/buildpacks-app +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: buildpacks-source-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 500Mi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: buildpacks-cache-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 500Mi diff --git a/task/buildpacks-separate-phases/0.1/tests/run.yaml b/task/buildpacks-separate-phases/0.1/tests/run.yaml new file mode 100644 index 0000000000..7a7e9218a5 --- /dev/null +++ b/task/buildpacks-separate-phases/0.1/tests/run.yaml @@ -0,0 +1,65 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: buildpacks-separate-phases-test-pipeline +spec: + workspaces: + - name: shared-workspace + resources: + - name: build-image + type: image + tasks: + - name: fetch-repository + taskRef: + name: git-clone + workspaces: + - name: output + workspace: shared-workspace + params: + - name: url + value: https://github.com/buildpacks/samples + - name: subdirectory + value: "" + - name: deleteExisting + value: "true" + - name: buildpacks + taskRef: + name: buildpacks-separate-phases + runAfter: + - fetch-repository + workspaces: + - name: source + workspace: shared-workspace + params: + - name: SOURCE_SUBPATH + value: apps/java-maven + - name: BUILDER_IMAGE + value: cnbs/sample-builder:alpine-p0.3 + - name: CACHE + value: buildpacks-cache + resources: + outputs: + - name: image + resource: build-image +--- +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: buildpacks-test-pipeline-run +spec: + pipelineRef: + name: buildpacks-test-pipeline + workspaces: + - name: shared-workspace + persistentvolumeclaim: + claimName: buildpacks-source-pvc + resources: + - name: build-image + resourceRef: + name: buildpacks-app-image + podTemplate: + volumes: + - name: buildpacks-cache + persistentVolumeClaim: + claimName: buildpacks-cache-pvc diff --git a/task/buildpacks/0.1/README.md b/task/buildpacks/0.1/README.md index d5c77a6407..1cf47d9dd4 100644 --- a/task/buildpacks/0.1/README.md +++ b/task/buildpacks/0.1/README.md @@ -1,16 +1,10 @@ # Cloud Native Buildpacks -This build template builds source into a container image using [Cloud Native -Buildpacks](https://buildpacks.io). +This build template builds source into a container image using [Cloud Native Buildpacks](https://buildpacks.io). To do that, it uses [builders](https://buildpacks.io/docs/concepts/components/builder/#what-is-a-builder) to run buildpacks against your application. -The Cloud Native Buildpacks website describes buildpacks as: +Cloud Native Buildpacks are pluggable, modular tools that transform application source code into OCI images. They replace Dockerfiles in the app development lifecycle, and enable for swift rebasing of images and modular control over images (through the use of builders), among other benefits. This command uses a builder to construct the image, and pushes it to the registry provided. -> ... 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. +See also [`buildpacks-separate-phases`](../buildpacks-separate-phases) for the deconstructed version of this task, which runs each of the [lifecycle phases](https://buildpacks.io/docs/concepts/components/lifecycle/#phases) individually (this task uses the [creator binary](https://github.com/buildpacks/spec/blob/platform/0.3/platform.md#operations), which coordinates and runs all of the phases). ## Install the Task @@ -26,6 +20,8 @@ kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/ * **`CACHE`**: The name of the persistent app cache volume. (_default:_ an empty directory -- effectively no cache) +* **`CACHE_IMAGE`**: The name of the persistent app cache image. (_default:_ no cache image) + * **`PLATFORM_DIR`**: A directory containing platform provided configuration, such as environment variables. Files of the format `/platform/env/MY_VAR` with content `my-value` will be translated by the lifecycle into environment variables provided to buildpacks. For more information, see the [buildpacks spec](https://github.com/buildpacks/spec/blob/master/buildpack.md#provided-by-the-platform). (_default:_ an empty directory) @@ -35,6 +31,10 @@ kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/ * **`PROCESS_TYPE`**: The default process type to set on the image. (_default:_ `"web"`) +* **`SKIP_RESTORE`**: Do not write layer metadata or restore cached layers. (clear cache between each run) (_default:_ `"false"`) + +* **`RUN_IMAGE`**: Reference to a run image to use. (_default:_ run image of the builder) + * **`SOURCE_SUBPATH`**: A subpath within the `source` input where the source to build is located. (_default:_ `""`) ### Outputs @@ -94,6 +94,11 @@ spec: ``` ### Example builders +Paketo: +- `gcr.io/paketo-buildpacks/builder:base` → Ubuntu bionic base image with buildpacks for Java, NodeJS and Golang +- `gcr.io/paketo-buildpacks/builder:tiny` → Tiny base image (bionic build image, distroless run image) with buildpacks for Golang +- `gcr.io/paketo-buildpacks/builder:full-cf` → cflinuxfs3 base image with buildpacks for Java, .NET, NodeJS, Golang, PHP, HTTPD and NGINX +> NOTE: The `gcr.io/paketo-buildpacks/builder:full-cf` requires setting the USER_ID and GROUP_ID parameters to 2000, in order to work. Heroku: - `heroku/buildpacks:18` → heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP diff --git a/task/buildpacks/0.1/buildpacks.yaml b/task/buildpacks/0.1/buildpacks.yaml index dba2ddea89..a924e2df57 100644 --- a/task/buildpacks/0.1/buildpacks.yaml +++ b/task/buildpacks/0.1/buildpacks.yaml @@ -11,14 +11,13 @@ metadata: tekton.dev/displayName: "buildpacks" spec: description: >- - This build template builds source into a container image using Cloud Native Buildpacks. + The Buildpacks task builds source into a container image and pushes it to a registry, + using Cloud Native Buildpacks. - 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. + Cloud Native Buildpacks are pluggable, modular tools that transform application source code + into OCI images. They replace Dockerfiles in the app development lifecycle, and allow for swift + rebasing of images, and give modular control over images through the use of builders, among other + benefits. This command uses a builder to construct the image, and pushes it to the registry provided. params: - name: BUILDER_IMAGE @@ -26,6 +25,9 @@ spec: - name: CACHE description: The name of the persistent app cache volume. default: empty-dir + - name: CACHE_IMAGE + description: The name of the persistent app cache image. + default: "" - name: PLATFORM_DIR description: The name of the platform directory. default: empty-dir @@ -41,6 +43,15 @@ spec: - name: SOURCE_SUBPATH description: A subpath within the `source` input where the source to build is located. default: "" + - name: SKIP_RESTORE + description: Do not write layer metadata or restore cached layers + default: "false" + - name: RUN_IMAGE + description: Reference to a run image to use + default: "" + # - name: ADDITIONAL_TAGS + # description: Additional space delimited tag(s) to apply to exported image + # default: "" resources: outputs: @@ -62,11 +73,15 @@ spec: command: ["/bin/sh"] args: - "-c" - - > + - |- chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/tekton/home" && chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/layers" && chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/cache" && chown -R "$(params.USER_ID):$(params.GROUP_ID)" "$(workspaces.source.path)" + # if [ -n "$(params.ADDITIONAL_TAGS)" ]; then + # params.ADDITIONAL_TAGS=`echo $(params.ADDITIONAL_TAGS) | sed -e 's/ / -tag=/g' -e 's/^/-tag=/'` + # fi + # echo $(params.ADDITIONAL_TAGS) volumeMounts: - name: layers-dir mountPath: /layers @@ -75,80 +90,31 @@ spec: securityContext: privileged: true - - name: detect + - name: create image: $(params.BUILDER_IMAGE) imagePullPolicy: Always - command: ["/cnb/lifecycle/detector"] + command: ["/cnb/lifecycle/creator"] args: - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" - - "-group=/layers/group.toml" - - "-plan=/layers/plan.toml" - volumeMounts: - - name: layers-dir - mountPath: /layers - - name: $(params.PLATFORM_DIR) - mountPath: /platform - - - name: analyze - image: $(params.BUILDER_IMAGE) - imagePullPolicy: Always - command: ["/cnb/lifecycle/analyzer"] - args: - - "-layers=/layers" - - "-group=/layers/group.toml" - - "-cache-dir=/cache" - - "$(resources.outputs.image.url)" - volumeMounts: - - name: $(params.CACHE) - mountPath: /cache - - name: layers-dir - mountPath: /layers - - - name: restore - image: $(params.BUILDER_IMAGE) - imagePullPolicy: Always - command: ["/cnb/lifecycle/restorer"] - args: - - "-group=/layers/group.toml" - - "-layers=/layers" - "-cache-dir=/cache" - volumeMounts: - - name: $(params.CACHE) - mountPath: /cache - - name: layers-dir - mountPath: /layers - - - name: build - image: $(params.BUILDER_IMAGE) - imagePullPolicy: Always - command: ["/cnb/lifecycle/builder"] - args: - - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" - - "-layers=/layers" - - "-group=/layers/group.toml" - - "-plan=/layers/plan.toml" - volumeMounts: - - name: layers-dir - mountPath: /layers - - name: $(params.PLATFORM_DIR) - mountPath: /platform - - - name: export - image: $(params.BUILDER_IMAGE) - imagePullPolicy: Always - command: ["/cnb/lifecycle/exporter"] - args: - - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)" + - "-cache-image=$(params.CACHE_IMAGE)" + - "-gid=$(params.GROUP_ID)" - "-layers=/layers" - - "-group=/layers/group.toml" - - "-cache-dir=/cache" + - "-platform=/platform" - "-process-type=$(params.PROCESS_TYPE)" + - "-skip-restore=$(params.SKIP_RESTORE)" + - "-previous-image=$(resources.outputs.image.url)" + - "-run-image=$(params.RUN_IMAGE)" + - "-uid=$(params.USER_ID)" + # - "$(params.ADDITIONAL_TAGS)" - "$(resources.outputs.image.url)" volumeMounts: - name: layers-dir mountPath: /layers - name: $(params.CACHE) mountPath: /cache + - name: $(params.PLATFORM_DIR) + mountPath: /platform volumes: - name: empty-dir From 722aff5e326ec8e258acda264c752b4a14a0152c Mon Sep 17 00:00:00 2001 From: David Freilich Date: Thu, 16 Jul 2020 13:10:18 -0400 Subject: [PATCH 3/3] Rename buildpacks-separate-phases to buildpacks-phases, to reduce length Additionally, remove commented out references to ADDITIONAL_TAGS; that will be added as a separate issue. Signed-off-by: David Freilich --- .../0.1/OWNERS | 0 .../0.1/README.md | 4 ++-- .../0.1/buildpacks-phases.yaml} | 6 +++--- .../0.1/tests/pre-apply-task-hook.sh | 0 .../0.1/tests/resources.yaml | 0 .../0.1/tests/run.yaml | 10 +++++----- task/buildpacks/0.1/README.md | 2 +- task/buildpacks/0.1/buildpacks.yaml | 8 -------- task/buildpacks/0.1/tests/run.yaml | 2 +- 9 files changed, 12 insertions(+), 20 deletions(-) rename task/{buildpacks-separate-phases => buildpacks-phases}/0.1/OWNERS (100%) rename task/{buildpacks-separate-phases => buildpacks-phases}/0.1/README.md (97%) rename task/{buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml => buildpacks-phases/0.1/buildpacks-phases.yaml} (96%) rename task/{buildpacks-separate-phases => buildpacks-phases}/0.1/tests/pre-apply-task-hook.sh (100%) rename task/{buildpacks-separate-phases => buildpacks-phases}/0.1/tests/resources.yaml (100%) rename task/{buildpacks-separate-phases => buildpacks-phases}/0.1/tests/run.yaml (87%) diff --git a/task/buildpacks-separate-phases/0.1/OWNERS b/task/buildpacks-phases/0.1/OWNERS similarity index 100% rename from task/buildpacks-separate-phases/0.1/OWNERS rename to task/buildpacks-phases/0.1/OWNERS diff --git a/task/buildpacks-separate-phases/0.1/README.md b/task/buildpacks-phases/0.1/README.md similarity index 97% rename from task/buildpacks-separate-phases/0.1/README.md rename to task/buildpacks-phases/0.1/README.md index 8c2952bbaa..ac18302dd1 100644 --- a/task/buildpacks-separate-phases/0.1/README.md +++ b/task/buildpacks-phases/0.1/README.md @@ -10,7 +10,7 @@ See also [`buildpacks`](../buildpacks) for the combined version of this task, wh ## Install the Task ``` -kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/buildpacks-phases/0.1/buildpacks-phases.yaml ``` > **NOTE:** This task is currently only compatible with Tekton **v0.11.0** and above, and CNB Platform API 0.3 (lifecycle v0.7.0 and above). For previous Platform API versions, [see below](#previous-platform-api-versions). @@ -52,7 +52,7 @@ metadata: name: example-run spec: taskRef: - name: buildpacks-separate-phases + name: buildpacks-phases podTemplate: volumes: # Uncomment the lines below to use an existing cache diff --git a/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml b/task/buildpacks-phases/0.1/buildpacks-phases.yaml similarity index 96% rename from task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml rename to task/buildpacks-phases/0.1/buildpacks-phases.yaml index 964da3f921..5b3abf1953 100644 --- a/task/buildpacks-separate-phases/0.1/buildpacks-separate-phases.yaml +++ b/task/buildpacks-phases/0.1/buildpacks-phases.yaml @@ -2,16 +2,16 @@ apiVersion: tekton.dev/v1beta1 kind: Task metadata: - name: buildpacks-separate-phases + name: buildpacks-phases labels: app.kubernetes.io/version: "0.1" annotations: tekton.dev/pipelines.minVersion: "0.12.1" tekton.dev/tags: image-build - tekton.dev/displayName: "buildpacks-separate-phases" + tekton.dev/displayName: "buildpacks-phases" spec: description: >- - The Buildpacks-Separate-Phases task builds source into a container image and pushes it to + The Buildpacks-Phases task builds source into a container image and pushes it to a registry, using Cloud Native Buildpacks. This command separately calls the aspects of the Cloud Native Buildpacks lifecycle, to provide more granular control over the construction of the image. diff --git a/task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh b/task/buildpacks-phases/0.1/tests/pre-apply-task-hook.sh similarity index 100% rename from task/buildpacks-separate-phases/0.1/tests/pre-apply-task-hook.sh rename to task/buildpacks-phases/0.1/tests/pre-apply-task-hook.sh diff --git a/task/buildpacks-separate-phases/0.1/tests/resources.yaml b/task/buildpacks-phases/0.1/tests/resources.yaml similarity index 100% rename from task/buildpacks-separate-phases/0.1/tests/resources.yaml rename to task/buildpacks-phases/0.1/tests/resources.yaml diff --git a/task/buildpacks-separate-phases/0.1/tests/run.yaml b/task/buildpacks-phases/0.1/tests/run.yaml similarity index 87% rename from task/buildpacks-separate-phases/0.1/tests/run.yaml rename to task/buildpacks-phases/0.1/tests/run.yaml index 7a7e9218a5..0bbdfc87f8 100644 --- a/task/buildpacks-separate-phases/0.1/tests/run.yaml +++ b/task/buildpacks-phases/0.1/tests/run.yaml @@ -2,7 +2,7 @@ apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: - name: buildpacks-separate-phases-test-pipeline + name: buildpacks-phases-test-pipeline spec: workspaces: - name: shared-workspace @@ -23,9 +23,9 @@ spec: value: "" - name: deleteExisting value: "true" - - name: buildpacks + - name: buildpacks-phases taskRef: - name: buildpacks-separate-phases + name: buildpacks-phases runAfter: - fetch-repository workspaces: @@ -46,10 +46,10 @@ spec: apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: - name: buildpacks-test-pipeline-run + name: buildpacks-phases-test-pipeline-run spec: pipelineRef: - name: buildpacks-test-pipeline + name: buildpacks-phases-test-pipeline workspaces: - name: shared-workspace persistentvolumeclaim: diff --git a/task/buildpacks/0.1/README.md b/task/buildpacks/0.1/README.md index 1cf47d9dd4..d0a3e5464a 100644 --- a/task/buildpacks/0.1/README.md +++ b/task/buildpacks/0.1/README.md @@ -4,7 +4,7 @@ This build template builds source into a container image using [Cloud Native Bui Cloud Native Buildpacks are pluggable, modular tools that transform application source code into OCI images. They replace Dockerfiles in the app development lifecycle, and enable for swift rebasing of images and modular control over images (through the use of builders), among other benefits. This command uses a builder to construct the image, and pushes it to the registry provided. -See also [`buildpacks-separate-phases`](../buildpacks-separate-phases) for the deconstructed version of this task, which runs each of the [lifecycle phases](https://buildpacks.io/docs/concepts/components/lifecycle/#phases) individually (this task uses the [creator binary](https://github.com/buildpacks/spec/blob/platform/0.3/platform.md#operations), which coordinates and runs all of the phases). +See also [`buildpacks-phases`](../buildpacks-phases) for the deconstructed version of this task, which runs each of the [lifecycle phases](https://buildpacks.io/docs/concepts/components/lifecycle/#phases) individually (this task uses the [creator binary](https://github.com/buildpacks/spec/blob/platform/0.3/platform.md#operations), which coordinates and runs all of the phases). ## Install the Task diff --git a/task/buildpacks/0.1/buildpacks.yaml b/task/buildpacks/0.1/buildpacks.yaml index a924e2df57..7328f4698a 100644 --- a/task/buildpacks/0.1/buildpacks.yaml +++ b/task/buildpacks/0.1/buildpacks.yaml @@ -49,9 +49,6 @@ spec: - name: RUN_IMAGE description: Reference to a run image to use default: "" - # - name: ADDITIONAL_TAGS - # description: Additional space delimited tag(s) to apply to exported image - # default: "" resources: outputs: @@ -78,10 +75,6 @@ spec: chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/layers" && chown -R "$(params.USER_ID):$(params.GROUP_ID)" "/cache" && chown -R "$(params.USER_ID):$(params.GROUP_ID)" "$(workspaces.source.path)" - # if [ -n "$(params.ADDITIONAL_TAGS)" ]; then - # params.ADDITIONAL_TAGS=`echo $(params.ADDITIONAL_TAGS) | sed -e 's/ / -tag=/g' -e 's/^/-tag=/'` - # fi - # echo $(params.ADDITIONAL_TAGS) volumeMounts: - name: layers-dir mountPath: /layers @@ -106,7 +99,6 @@ spec: - "-previous-image=$(resources.outputs.image.url)" - "-run-image=$(params.RUN_IMAGE)" - "-uid=$(params.USER_ID)" - # - "$(params.ADDITIONAL_TAGS)" - "$(resources.outputs.image.url)" volumeMounts: - name: layers-dir diff --git a/task/buildpacks/0.1/tests/run.yaml b/task/buildpacks/0.1/tests/run.yaml index 40921ea9c0..f10c0e836f 100644 --- a/task/buildpacks/0.1/tests/run.yaml +++ b/task/buildpacks/0.1/tests/run.yaml @@ -35,7 +35,7 @@ spec: - name: SOURCE_SUBPATH value: apps/java-maven - name: BUILDER_IMAGE - value: cnbs/sample-builder:alpine-p0.3 + value: cnbs/sample-builder:alpine - name: CACHE value: buildpacks-cache resources: