buildpacks / tekton-integration

Buildpacks + Tekton
22 stars 3 forks source link

Make builpacks task Chains compliant #34

Closed rgreinho closed 2 years ago

rgreinho commented 2 years ago

Adds the Chains type hinting to the task to ensure it can be used by Chains.

This problem came up based on the following issue in the Chains repository https://github.com/tektoncd/chains/issues/273#issuecomment-956411302.

jromero commented 2 years ago

Diff between 0.3 and 0.4

diff --git a/./task/buildpacks/0.3/README.md b/./task/buildpacks/0.4/README.md
index 2b1617d..ac1b11e 100644
--- a/./task/buildpacks/0.3/README.md
+++ b/./task/buildpacks/0.4/README.md
@@ -43,6 +43,7 @@ kubectl apply -f https://raw.githubusercontent.com/buildpacks/tekton-integration
 ## Results

  - **`APP_IMAGE_DIGEST`**: The digest of the built `APP_IMAGE`.
+ - **`APP_IMAGE_URL`**: The URL of the built `APP_IMAGE`.

 ## Builders

@@ -100,4 +101,4 @@ For support of previous [Platform API][platform-api]s use a previous version of
 | [0.2](../0.2/) | [0.3][platform-api-0.3]

 [platform-api]: https://buildpacks.io/docs/reference/spec/platform-api/
-[platform-api-0.3]: https://github.com/buildpacks/spec/blob/platform/0.3/platform.md
\ No newline at end of file
+[platform-api-0.3]: https://github.com/buildpacks/spec/blob/platform/0.3/platform.md
diff --git a/./task/buildpacks/0.3/README.tpl.md b/./task/buildpacks/0.4/README.tpl.md
index f20a8da..44283de 100644
--- a/./task/buildpacks/0.3/README.tpl.md
+++ b/./task/buildpacks/0.4/README.tpl.md
@@ -59,4 +59,4 @@ For support of previous [Platform API][platform-api]s use a previous version of
 | [0.2](../0.2/) | [0.3][platform-api-0.3]

 [platform-api]: https://buildpacks.io/docs/reference/spec/platform-api/
-[platform-api-0.3]: https://github.com/buildpacks/spec/blob/platform/0.3/platform.md
\ No newline at end of file
+[platform-api-0.3]: https://github.com/buildpacks/spec/blob/platform/0.3/platform.md
diff --git a/./task/buildpacks/0.3/buildpacks.yaml b/./task/buildpacks/0.4/buildpacks.yaml
index 4ccc867..b919360 100644
--- a/./task/buildpacks/0.3/buildpacks.yaml
+++ b/./task/buildpacks/0.4/buildpacks.yaml
@@ -4,7 +4,7 @@ kind: Task
 metadata:
   name: buildpacks
   labels:
-    app.kubernetes.io/version: "0.3"
+    app.kubernetes.io/version: "0.4"
   annotations:
     tekton.dev/categories: Image Build
     tekton.dev/pipelines.minVersion: "0.17.0"
@@ -60,6 +60,8 @@ spec:
   results:
     - name: APP_IMAGE_DIGEST
       description: The digest of the built `APP_IMAGE`.
+    - name: APP_IMAGE_URL
+      description: The URL of the built `APP_IMAGE`.

   stepTemplate:
     env:
@@ -105,7 +107,7 @@ spec:
         mkdir -p "$ENV_DIR"

         for env in "${envs[@]}"; do
-            IFS='=' read -r key value string <<< "$env"
+            IFS='=' read -r key value <<< "$env"
             if [[ "$key" != "" && "$value" != "" ]]; then
                 path="${ENV_DIR}/${key}"
                 echo "--> Writing ${path}..."
@@ -152,7 +154,11 @@ spec:
       script: |
         #!/usr/bin/env bash
         set -e
-        cat /layers/report.toml | grep "digest" | cut -d'"' -f2 | cut -d'"' -f2 | tr -d '\n' | tee $(results.APP_IMAGE_DIGEST.path)
+        grep "digest" /layers/report.toml | cut -d'"' -f2 | cut -d'"' -f2 | tr -d '\n' | tee "$(results.APP_IMAGE_DIGEST.path)"
+
+        # Disable shellcheck here since $() is use for variable substitution and not command execution.
+        # shellcheck disable=SC2005
+        echo "$(params.APP_IMAGE)" | tee "$(results.APP_IMAGE_URL.path)"
       volumeMounts:
         - name: layers-dir
           mountPath: /layers
jromero commented 2 years ago

Thank you @rgreinho for the great work here. Very much appreciated.

jjbustamante commented 2 years ago

Great work @rgreinho! thanks for the contribution.