-
Notifications
You must be signed in to change notification settings - Fork 113
/
buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml
110 lines (93 loc) · 3.53 KB
/
buildstrategy_buildpacks-v3-heroku_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
---
apiVersion: shipwright.io/v1beta1
kind: BuildStrategy
metadata:
name: buildpacks-v3-heroku
spec:
volumes:
- name: platform-env
emptyDir: {}
parameters:
- name: operating-system
description: The target operating system for the buildpacks build.
default: "linux"
- name: system-architecture
description: The target system architecture for the buildpacks build.
default: "x86_64"
- name: platform-api-version
description: The referenced version is the minimum version that all relevant buildpack implementations support.
default: "0.12"
steps:
- name: build-and-push
image: heroku/builder:22
env:
- name: CNB_TARGET_OS
value: $(params.operating-system)
- name: CNB_TARGET_ARCH
value: $(params.system-architecture)
- 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/.shp/layers
CACHE_DIR=/tmp/.shp/cache
mkdir -p "$CACHE_DIR" "$LAYERS_DIR"
function announce_phase {
printf "===> %s\n" "$1"
}
announce_phase "ANALYZING"
/cnb/lifecycle/analyzer -layers="$LAYERS_DIR" "${PARAM_OUTPUT_IMAGE}"
announce_phase "DETECTING"
/cnb/lifecycle/detector -app="${PARAM_SOURCE_CONTEXT}" -layers="$LAYERS_DIR"
announce_phase "RESTORING"
/cnb/lifecycle/restorer -cache-dir="$CACHE_DIR" -layers="$LAYERS_DIR"
announce_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 )
announce_phase "EXPORTING"
/cnb/lifecycle/exporter "${exporter_args[@]}" "${PARAM_OUTPUT_IMAGE}"
# Store the image digest
grep digest /tmp/report.toml | tail -n 1 | 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
securityContext:
runAsUser: 1000
runAsGroup: 1000