Skip to content

Commit

Permalink
Merge pull request #906 from shahulsonhal/prepare-platform-env
Browse files Browse the repository at this point in the history
Extend the Buildpack strategy to work with the environment variables
  • Loading branch information
openshift-merge-robot authored Oct 20, 2021
2 parents c86cbcd + afb462c commit 3d6ec4c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
securityContext:
runAsUser: 0
capabilities:
add:
add:
- CHOWN
command:
- chown
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
securityContext:
runAsUser: 0
capabilities:
add:
add:
- CHOWN
command:
- chown
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
securityContext:
runAsUser: 0
capabilities:
add:
add:
- CHOWN
command:
- chown
Expand Down Expand Up @@ -39,6 +39,19 @@ spec:
- |
set -euo pipefail
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
mkdir /tmp/cache /tmp/layers
/cnb/lifecycle/creator \
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/data/build_buildpacks-v3_golang_cr_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: shipwright.io/v1alpha1
kind: Build
metadata:
name: buildpack-golang-build
spec:
source:
url: https://github.com/shipwright-io/sample-go
contextDir: source-build-with-package
env:
- name: BP_GO_TARGETS
value: "main-package"
strategy:
name: buildpacks-v3
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
20 changes: 20 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ 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")

// create the build definition
build = createBuild(
testBuild,
testID,
"test/data/build_buildpacks-v3_golang_cr_env.yaml",
)
})

It("successfully runs a build", func() {
buildRun, err = buildRunTestData(testBuild.Namespace, testID, "test/data/buildrun_buildpacks-v3_golang_cr.yaml")
Expect(err).ToNot(HaveOccurred(), "Error retrieving buildrun test data")

validateBuildRunToSucceed(testBuild, buildRun)
})
})

Context("when a build uses the build-run-deletion annotation", func() {

BeforeEach(func() {
Expand Down

0 comments on commit 3d6ec4c

Please sign in to comment.