Skip to content

Commit 5074091

Browse files
Sophie Wigmorebrayanhenao
Sophie Wigmore
andauthored
BYO python and introduce cflinuxfs4 support (#815)
* BYO Python on cflinuxfs4 Co-authored-by: Brayan Henao <[email protected]> Signed-off-by: Brayan Henao <[email protected]> * reduce number of python2 installations during staging Signed-off-by: Brayan Henao <[email protected]> * append onto LD_LIBRARY_PATH instead of overwrite --------- Signed-off-by: Brayan Henao <[email protected]> Co-authored-by: Brayan Henao <[email protected]>
1 parent 511274e commit 5074091

File tree

9 files changed

+249
-8
lines changed

9 files changed

+249
-8
lines changed

bin/detect

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
# build pack needs to do anything to bootstrap the
2222
# python scripts, like install Python.
2323
BP=$(dirname $(dirname $0))
24+
25+
# Install python if stack is cflinuxfs4 so its available during staging
26+
if [ "$CF_STACK" == "cflinuxfs4" ]; then
27+
PYTHON_DIR="/tmp/python"
28+
mkdir -p "${PYTHON_DIR}"
29+
source "$BP/bin/install-python" "$PYTHON_DIR" "$BP" &> /dev/null
30+
fi
31+
2432
export PYTHONPATH=$BP/lib
2533
VERSION=`cat $BP/VERSION`
2634
python2 $BP/scripts/detect.py $1 $VERSION

bin/finalize

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ set -e
2121
# python script. However, this is here in case the
2222
# build pack needs to do anything to bootstrap the
2323
# python scripts, like install Python.
24-
BP=$(dirname $(dirname $0))
2524

25+
BP=$(dirname $(dirname $0))
2626
BUILD_DIR=${1:-}
2727
CACHE_DIR=${2:-}
2828
DEPS_DIR=${3:-}
2929
DEPS_IDX=${4:-}
3030
PROFILE_DIR=${5:-}
3131

32+
# Install python if stack is cflinuxfs4 so its available during staging and build
33+
if [ "$CF_STACK" == "cflinuxfs4" ]; then
34+
source "$BP/bin/install-python" "$DEPS_DIR/$DEPS_IDX" "$BP"
35+
fi
36+
3237
BUILDPACK_PATH=$BP
3338
export BUILDPACK_PATH
3439
source $BP/compile-extensions/lib/common

bin/install-python

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
set -e
3+
shopt -s expand_aliases
4+
5+
function main() {
6+
install_dir="$1"
7+
buildpack_dir="$2"
8+
9+
if [ ! -d "/tmp/python/bin" ]; then
10+
python_dep_name=$(get_python_from_manifest "$buildpack_dir")
11+
echo "-------> Providing Python $(echo $python_dep_name | cut -d'_' -f 2) (required by the buildpack to run in cflinuxfs4)"
12+
13+
if [ ! -d "$buildpack_dir/dependencies" ]; then
14+
setup_online "$python_dep_name" "$install_dir" "$buildpack_dir"
15+
else
16+
setup_offline "$python_dep_name" "$install_dir" "$buildpack_dir"
17+
fi
18+
elif [ $install_dir != "/tmp/python" ]; then
19+
cp -r "/tmp/python/." "$install_dir"
20+
fi
21+
22+
export LD_LIBRARY_PATH="$install_dir/lib:${LD_LIBRARY_PATH:-}"
23+
export PATH="$install_dir/bin:${PATH:-}"
24+
alias python2=python2.7
25+
}
26+
27+
function setup_offline() {
28+
python_dep_name="$1"
29+
install_dir="$2"
30+
buildpack_dir="$3"
31+
32+
tar -xzf "$buildpack_dir/dependencies/https___buildpacks.cloudfoundry.org_dependencies_python_$python_dep_name" -C "$install_dir"
33+
}
34+
35+
function setup_online(){
36+
python_dep_name="$1"
37+
install_dir="$2"
38+
buildpack_dir="$3"
39+
40+
curl -Ls "https://buildpacks.cloudfoundry.org/dependencies/python/$python_dep_name" | tar -xzf - -C "$install_dir"
41+
}
42+
43+
function get_python_from_manifest() {
44+
buildpack_dir="$1"
45+
python_dep_info=$(cat "$buildpack_dir/manifest.yml" | grep -A 3 "name: python" | grep "uri:" | awk '{print $2}' | cut -d'/' -f 6)
46+
echo "$python_dep_info"
47+
}
48+
49+
main "${@:-}"

bin/release

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
# Licensed to the Apache Software Foundation (ASF) under one or more
45
# contributor license agreements. See the NOTICE file distributed with
@@ -21,6 +22,15 @@
2122
# build pack needs to do anything to bootstrap the
2223
# python scripts, like install Python.
2324
BP=$(dirname $(dirname $0))
25+
26+
# Install python if stack is cflinuxfs4 so its available during staging
27+
if [ "$CF_STACK" == "cflinuxfs4" ]; then
28+
PYTHON_DIR="/tmp/python"
29+
mkdir -p "${PYTHON_DIR}"
30+
source "$BP/bin/install-python" "$PYTHON_DIR" "$BP" &> /dev/null
31+
fi
32+
33+
2434
export PYTHONPATH=$BP/lib
2535

2636
python2 $BP/scripts/release.py $1

cf.Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
ruby '~> 2.3'
3+
ruby '~> 3.0'
44

5-
gem 'buildpack-packager', git: 'https://github.com/cloudfoundry/buildpack-packager', tag: 'v2.3.22'
5+
gem 'buildpack-packager', git: 'https://github.com/cloudfoundry/buildpack-packager', tag: 'v2.3.23'

cf.Gemfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
GIT
22
remote: https://github.com/cloudfoundry/buildpack-packager
3-
revision: 080f6fb773bf151dfae87a22d6852749d6be968a
4-
tag: v2.3.22
3+
revision: f88bfee41cf46d5b6ea487d6c30a99ed7c0e51eb
4+
tag: v2.3.23
55
specs:
6-
buildpack-packager (2.3.22)
6+
buildpack-packager (2.3.23)
77
activesupport (~> 4.1)
88
kwalify (~> 0)
99
semantic
@@ -37,7 +37,7 @@ DEPENDENCIES
3737
buildpack-packager!
3838

3939
RUBY VERSION
40-
ruby 2.3.1p112
40+
ruby 3.0.5p211
4141

4242
BUNDLED WITH
43-
2.1.4
43+
2.2.33

manifest.yml

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ dependency_deprecation_dates:
5555
link: http://php.net/supported-versions.php
5656
match: 8.2.\d+
5757
dependencies:
58+
- name: python
59+
version: 2.7.18
60+
uri: https://buildpacks.cloudfoundry.org/dependencies/python/python_2.7.18_linux_x64_cflinuxfs4_4454dcd.tgz
61+
sha256: 4454dcd542031cdc3b839def90f5cad06ac2ed2cacddf3a209b3c0ab13904fc3
62+
cf_stacks:
63+
- cflinuxfs4
64+
source_sha256: 4454dcd542031cdc3b839def90f5cad06ac2ed2cacddf3a209b3c0ab13904fc3
5865
- name: appdynamics
5966
version: 22.12.1-677
6067
uri: https://download.run.pivotal.io/appdynamics-php/appdynamics-22.12.1-677.tar.bz2
@@ -95,6 +102,7 @@ dependencies:
95102
sha256: '0095809b1a7e405d5aac675661df837a399d605bb9e515e1ce8c7e255279b9a3'
96103
cf_stacks:
97104
- cflinuxfs3
105+
- cflinuxfs4
98106
osl: https://docs.newrelic.com/docs/licenses/license-information/agent-licenses/java-agent-licenses
99107
- name: nginx
100108
version: 1.22.1

scripts/.util/print.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
function util::print::title() {
7+
local blue reset message
8+
blue="\033[0;34m"
9+
reset="\033[0;39m"
10+
message="${1}"
11+
12+
echo -e "\n${blue}${message}${reset}" >&2
13+
}
14+
15+
function util::print::info() {
16+
local message
17+
message="${1}"
18+
19+
echo -e "${message}" >&2
20+
}
21+
22+
function util::print::error() {
23+
local message red reset
24+
message="${1}"
25+
red="\033[0;31m"
26+
reset="\033[0;39m"
27+
28+
echo -e "${red}${message}${reset}" >&2
29+
exit 1
30+
}
31+
32+
function util::print::success() {
33+
local message green reset
34+
message="${1}"
35+
green="\033[0;32m"
36+
reset="\033[0;39m"
37+
38+
echo -e "${green}${message}${reset}" >&2
39+
exitcode="${2:-0}"
40+
exit "${exitcode}"
41+
}
42+
43+
function util::print::warn() {
44+
local message yellow reset
45+
message="${1}"
46+
yellow="\033[0;33m"
47+
reset="\033[0;39m"
48+
49+
echo -e "${yellow}${message}${reset}" >&2
50+
exit 0
51+
}
52+

scripts/package.sh

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8+
readonly ROOTDIR
9+
10+
## shellcheck source=SCRIPTDIR/.util/tools.sh
11+
#source "${ROOTDIR}/scripts/.util/tools.sh"
12+
#
13+
# shellcheck source=SCRIPTDIR/.util/print.sh
14+
source "${ROOTDIR}/scripts/.util/print.sh"
15+
16+
function main() {
17+
local stack version cached output
18+
stack="any"
19+
cached="false"
20+
output="${ROOTDIR}/build/buildpack.zip"
21+
22+
while [[ "${#}" != 0 ]]; do
23+
case "${1}" in
24+
--stack)
25+
stack="${2}"
26+
shift 2
27+
;;
28+
29+
--cached)
30+
cached="true"
31+
shift 1
32+
;;
33+
34+
--uncached)
35+
cached="false"
36+
shift 1
37+
;;
38+
39+
--help|-h)
40+
shift 1
41+
usage
42+
exit 0
43+
;;
44+
45+
"")
46+
# skip if the argument is empty
47+
shift 1
48+
;;
49+
50+
*)
51+
util::print::error "unknown argument \"${1}\""
52+
esac
53+
done
54+
55+
package::buildpack "${cached}" "${stack}"
56+
}
57+
58+
59+
function usage() {
60+
cat <<-USAGE
61+
package.sh [OPTIONS]
62+
Packages the buildpack into a .zip file.
63+
OPTIONS
64+
--help -h prints the command usage
65+
--cached packages the buildpack as a cached buildpack
66+
--uncached packages the buildpack as an uncached buildpack (default)
67+
--stack the stack to package the buildpack for (default: any)
68+
USAGE
69+
}
70+
71+
function package::buildpack() {
72+
local cached stack
73+
cached="${1}"
74+
stack="${2}"
75+
76+
77+
local stack_flag
78+
stack_flag="--any-stack"
79+
if [[ "${stack}" != "any" ]]; then
80+
stack_flag="--stack=${stack}"
81+
fi
82+
83+
local cached_flag
84+
cached_flag="--uncached"
85+
if [[ "${cached}" == "true" ]]; then
86+
cached_flag="--cached"
87+
fi
88+
89+
pushd "${ROOTDIR}" &> /dev/null
90+
cat <<EOF > Dockerfile
91+
FROM ruby:3.0
92+
RUN apt-get update && apt-get install -y zip
93+
ADD cf.Gemfile .
94+
ADD cf.Gemfile.lock .
95+
ENV BUNDLE_GEMFILE=cf.Gemfile
96+
RUN bundle install
97+
ENTRYPOINT ["bundle", "exec", "buildpack-packager"]
98+
EOF
99+
docker build -t buildpack-packager . &> /dev/null
100+
101+
echo "Running buildpack-packager with flags: ${stack_flag} ${cached_flag}"
102+
docker run --rm -v ${ROOTDIR}:/buildpack -w /buildpack buildpack-packager ${stack_flag} ${cached_flag} &> /dev/null
103+
util::print::success "Buildpack packaged successfully"
104+
105+
rm Dockerfile
106+
popd &> /dev/null
107+
}
108+
109+
main "${@:-}"

0 commit comments

Comments
 (0)