forked from shipwright-io/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildstrategy_buildpacks-v3_namespaced_cr.yaml
122 lines (105 loc) · 3.6 KB
/
buildstrategy_buildpacks-v3_namespaced_cr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
apiVersion: shipwright.io/v1alpha1
kind: BuildStrategy
metadata:
name: buildpacks-v3
spec:
volumes:
- name: platform-env
emptyDir: {}
parameters:
- name: platform-api-version
description: The referenced version is the minimum version that all relevant buildpack implementations support.
default: "0.4"
buildSteps:
- name: prepare
image: docker.io/paketobuildpacks/builder:full
imagePullPolicy: Always
securityContext:
runAsUser: 0
capabilities:
add:
- CHOWN
command:
- chown
args:
- -R
- "1000:1000"
- /tekton/home
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 65Mi
- name: build-and-push
image: docker.io/paketobuildpacks/builder:full
imagePullPolicy: Always
securityContext:
runAsUser: 1000
runAsGroup: 1000
env:
- name: CNB_PLATFORM_API
value: $(params.platform-api-version)
- name: PARAM_SOURCE_CONTEXT
value: $(params.shp-source-context)
- name: PARAM_OUTPUT_IMAGE
value: $(params.shp-output-image)
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
echo "> Processing environment variables..."
ENV_DIR="/platform/env"
envs=($(env))
# Denying the creation of non required files from system environments.
# The creation of a file named PATH (corresponding to PATH system environment)
# caused failure for python source during pip install (https://github.com/Azure-Samples/python-docs-hello-world)
block_list=("PATH" "HOSTNAME" "PWD" "_" "SHLVL" "HOME" "")
for env in "${envs[@]}"; do
blocked=false
IFS='=' read -r key value string <<< "$env"
for str in "${block_list[@]}"; do
if [[ "$key" == "$str" ]]; then
blocked=true
break
fi
done
if [ "$blocked" == "false" ]; then
path="${ENV_DIR}/${key}"
echo -n "$value" > "$path"
fi
done
LAYERS_DIR=/tmp/layers
CACHE_DIR=/tmp/cache
mkdir "$CACHE_DIR" "$LAYERS_DIR"
function anounce_phase {
printf "===> %s\n" "$1"
}
anounce_phase "DETECTING"
/cnb/lifecycle/detector -app="${PARAM_SOURCE_CONTEXT}" -layers="$LAYERS_DIR"
anounce_phase "ANALYZING"
/cnb/lifecycle/analyzer -layers="$LAYERS_DIR" -cache-dir="$CACHE_DIR" "${PARAM_OUTPUT_IMAGE}"
anounce_phase "RESTORING"
/cnb/lifecycle/restorer -cache-dir="$CACHE_DIR"
anounce_phase "BUILDING"
/cnb/lifecycle/builder -app="${PARAM_SOURCE_CONTEXT}" -layers="$LAYERS_DIR"
exporter_args=( -layers="$LAYERS_DIR" -report=/tmp/report.toml -cache-dir="$CACHE_DIR" -app="${PARAM_SOURCE_CONTEXT}")
grep -q "buildpack-default-process-type" "$LAYERS_DIR/config/metadata.toml" || exporter_args+=( -process-type web )
anounce_phase "EXPORTING"
/cnb/lifecycle/exporter "${exporter_args[@]}" "${PARAM_OUTPUT_IMAGE}"
# 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
memory: 1Gi
requests:
cpu: 250m
memory: 65Mi