From afb462c634772395dfca9383e922ad78b67c9fa7 Mon Sep 17 00:00:00 2001 From: Shahul Date: Tue, 19 Oct 2021 10:32:04 +0530 Subject: [PATCH] Extend the Buildpack environment variables script to other Buildpack files --- .../buildstrategy_buildpacks-v3-heroku_cr.yaml | 18 +++++++++++++++++- ...egy_buildpacks-v3-heroku_namespaced_cr.yaml | 18 +++++++++++++++++- .../buildstrategy_buildpacks-v3_cr.yaml | 3 +-- ...ldstrategy_buildpacks-v3_namespaced_cr.yaml | 16 ++++++++++++++++ ... => build_buildpacks-v3_golang_cr_env.yaml} | 4 ++-- test/e2e/e2e_test.go | 3 +-- 6 files changed, 54 insertions(+), 8 deletions(-) rename test/data/{build_buildpacks-v3_golang_cr+env.yaml => build_buildpacks-v3_golang_cr_env.yaml} (83%) diff --git a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_cr.yaml b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_cr.yaml index 09592e5ce..350d70589 100644 --- a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_cr.yaml +++ b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_cr.yaml @@ -10,7 +10,7 @@ spec: securityContext: runAsUser: 0 capabilities: - add: + add: - CHOWN command: - chown @@ -39,6 +39,19 @@ spec: mkdir /tmp/cache /tmp/layers + echo "> Processing environment variables..." + ENV_DIR="/platform/env" + + envs=($(env)) + + for env in "${envs[@]}"; do + IFS='=' read -r key value string <<< "$env" + if [[ "$key" != "" ]]; then + path="${ENV_DIR}/${key}" + echo -n "$value" > "$path" + fi + done + /cnb/lifecycle/creator \ '-app=$(params.shp-source-context)' \ -cache-dir=/tmp/cache \ @@ -48,6 +61,9 @@ spec: # Store the image digest grep digest /tmp/report.toml | tr -d ' \"\n' | sed s/digest=// > "$(results.shp-image-digest.path)" + volumeMounts: + - mountPath: /platform/env + name: platform-env resources: limits: cpu: 500m diff --git a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml index b26fccf74..bf388458e 100644 --- a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml +++ b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml @@ -10,7 +10,7 @@ spec: securityContext: runAsUser: 0 capabilities: - add: + add: - CHOWN command: - chown @@ -39,6 +39,19 @@ spec: mkdir /tmp/cache /tmp/layers + echo "> Processing environment variables..." + ENV_DIR="/platform/env" + + envs=($(env)) + + for env in "${envs[@]}"; do + IFS='=' read -r key value string <<< "$env" + if [[ "$key" != "" ]]; then + path="${ENV_DIR}/${key}" + echo -n "$value" > "$path" + fi + done + /cnb/lifecycle/creator \ '-app=$(params.shp-source-context)' \ -cache-dir=/tmp/cache \ @@ -48,6 +61,9 @@ spec: # Store the image digest grep digest /tmp/report.toml | tr -d ' \"\n' | sed s/digest=// > "$(results.shp-image-digest.path)" + volumeMounts: + - mountPath: /platform/env + name: platform-env resources: limits: cpu: 500m diff --git a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_cr.yaml b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_cr.yaml index 118f9e767..aaf945b51 100644 --- a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_cr.yaml +++ b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_cr.yaml @@ -46,9 +46,8 @@ spec: for env in "${envs[@]}"; do IFS='=' read -r key value string <<< "$env" - if [[ "$key" != "" && "$value" != "" ]]; then + if [[ "$key" != "" ]]; then path="${ENV_DIR}/${key}" - echo "--> Writing ${path}..." echo -n "$value" > "$path" fi done diff --git a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml index 8f6d6a9e3..5ebade828 100644 --- a/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml +++ b/samples/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml @@ -41,6 +41,19 @@ spec: mkdir /tmp/cache /tmp/layers + echo "> Processing environment variables..." + ENV_DIR="/platform/env" + + envs=($(env)) + + for env in "${envs[@]}"; do + IFS='=' read -r key value string <<< "$env" + if [[ "$key" != "" ]]; then + path="${ENV_DIR}/${key}" + echo -n "$value" > "$path" + fi + done + /cnb/lifecycle/creator \ '-app=$(params.shp-source-context)' \ -cache-dir=/tmp/cache \ @@ -50,6 +63,9 @@ spec: # Store the image digest grep digest /tmp/report.toml | tr -d ' \"\n' | sed s/digest=// > "$(results.shp-image-digest.path)" + volumeMounts: + - mountPath: /platform/env + name: platform-env resources: limits: cpu: 500m diff --git a/test/data/build_buildpacks-v3_golang_cr+env.yaml b/test/data/build_buildpacks-v3_golang_cr_env.yaml similarity index 83% rename from test/data/build_buildpacks-v3_golang_cr+env.yaml rename to test/data/build_buildpacks-v3_golang_cr_env.yaml index 6c3793bed..d600ddb89 100644 --- a/test/data/build_buildpacks-v3_golang_cr+env.yaml +++ b/test/data/build_buildpacks-v3_golang_cr_env.yaml @@ -6,10 +6,10 @@ metadata: spec: source: url: https://github.com/shipwright-io/sample-go - contextDir: source-build + contextDir: source-build-with-package env: - name: BP_GO_TARGETS - value: "target-build" + value: "main-package" strategy: name: buildpacks-v3 kind: ClusterBuildStrategy diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 9f690be94..2502e7af8 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -259,7 +259,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a Buildpacks v3 build is defined for a golang runtime with `BP_GO_TARGETS` env", func() { - BeforeEach(func() { testID = generateTestID("buildpacks-v3-golang") @@ -267,7 +266,7 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun build = createBuild( testBuild, testID, - "test/data/build_buildpacks-v3_golang_cr+env.yaml", + "test/data/build_buildpacks-v3_golang_cr_env.yaml", ) })