Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the Buildpack strategy to work with the environment variables #906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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