Skip to content

Commit 7e1a64a

Browse files
committed
Modernize PHP buildpack packaging to use Go-based buildpack-packager
Replace deprecated Ruby gem-based packaging with Go-based buildpack-packager, bringing the PHP buildpack in line with all other Cloud Foundry buildpacks. Changes: - Add buildpack-packager::install function to scripts/.util/tools.sh - Refactor scripts/package.sh to use Go-based packager - Delete obsolete cf.Gemfile and cf.Gemfile.lock - Update README.md with modernized packaging instructions - Remove cf.Gemfile references from manifest.yml exclude_files - Modernize scripts/brats.sh to use Go-based packager - Enable buildpack-packager install in scripts/integration.sh (consistent with other buildpacks) - Remove newrelic from default_versions in manifest.yml The newrelic removal is required because the Go-based packager correctly validates semantic versions and rejects 4-part versions (10.21.0.11). NewRelic remains fully functional at runtime via compile-extensions fallback mechanism that automatically selects the single available version from the dependencies section. This change eliminates Docker and Ruby dependencies for packaging while maintaining complete backward compatibility at runtime. Stats: 8 files changed, 52 insertions(+), 99 deletions(-)
1 parent 0747055 commit 7e1a64a

8 files changed

Lines changed: 52 additions & 99 deletions

File tree

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Official buildpack documentation can be found here: [php buildpack docs](http://
1313
#### Option 1: Using the `package.sh` script
1414
1. Run `./scripts/package.sh [ --uncached | --cached ] [ --stack=STACK ]`
1515

16-
This requires that you have `docker` installed on your local machine, as it
17-
will run packaging setup within a `ruby` image.
16+
This script automatically installs the Go-based `buildpack-packager` and builds the buildpack.
1817

1918
#### Option 2: Manually use the `buildpack-packager`
2019
1. Make sure you have fetched submodules
@@ -29,16 +28,16 @@ will run packaging setup within a `ruby` image.
2928
git checkout v4.4.2 # or whatever version you want, see releases page for available versions
3029
```
3130

32-
1. Get latest buildpack dependencies, this will require having Ruby 3.0 or running in a Ruby 3.0 container image
31+
1. Install the Go-based buildpack-packager
3332

3433
```shell
35-
BUNDLE_GEMFILE=cf.Gemfile bundle
34+
go install github.com/cloudfoundry/libbuildpack/packager/buildpack-packager@latest
3635
```
3736

38-
1. Build the buildpack. Please note that the PHP buildpack still uses the older Ruby based buildpack packager. This is different than most of the other buildpacks which use a newer Golang based buildpack packager. You must use the Ruby based buildpack packager with the PHP buildpack.
37+
1. Build the buildpack
3938

4039
```shell
41-
BUNDLE_GEMFILE=cf.Gemfile bundle exec buildpack-packager [ --uncached | --cached ] [ --any-stack | --stack=STACK ]
40+
buildpack-packager build [ -uncached | -cached ] [ -any-stack | -stack=STACK ]
4241
```
4342

4443
1. Use in Cloud Foundry

cf.Gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

cf.Gemfile.lock

Lines changed: 0 additions & 43 deletions
This file was deleted.

manifest.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ exclude_files:
99
- ".bin/"
1010
- log/
1111
- tests/
12-
- cf.Gemfile
13-
- cf.Gemfile.lock
1412
- bin/package
1513
- buildpack-packager/
1614
- requirements.txt
@@ -20,8 +18,6 @@ default_versions:
2018
version: 8.1.32
2119
- name: httpd
2220
version: 2.4.63
23-
- name: newrelic
24-
version: 10.21.0.11
2521
- name: nginx
2622
version: 1.27.5
2723
- name: composer

scripts/.util/tools.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ function util::tools::ginkgo::install() {
4545
fi
4646
}
4747

48+
function util::tools::buildpack-packager::install() {
49+
local dir
50+
while [[ "${#}" != 0 ]]; do
51+
case "${1}" in
52+
--directory)
53+
dir="${2}"
54+
shift 2
55+
;;
56+
57+
*)
58+
util::print::error "unknown argument \"${1}\""
59+
esac
60+
done
61+
62+
mkdir -p "${dir}"
63+
util::tools::path::export "${dir}"
64+
65+
if [[ ! -f "${dir}/buildpack-packager" ]]; then
66+
util::print::title "Installing buildpack-packager"
67+
68+
pushd /tmp > /dev/null || return
69+
GOBIN="${dir}" \
70+
go install \
71+
github.com/cloudfoundry/libbuildpack/packager/buildpack-packager@latest
72+
popd > /dev/null || return
73+
fi
74+
}
75+
4876
function util::tools::jq::install() {
4977
local dir
5078
while [[ "${#}" != 0 ]]; do

scripts/brats.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ function main() {
1818
source "${ROOTDIR}/scripts/.util/tools.sh"
1919

2020
util::tools::ginkgo::install --directory "${ROOTDIR}/.bin"
21-
22-
# set up buildpack-packager
23-
# apt-get install ruby
24-
gem install bundler
25-
export BUNDLE_GEMFILE=cf.Gemfile
26-
bundle install
27-
21+
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
2822

2923
GINKGO_NODES=${GINKGO_NODES:-3}
3024
GINKGO_ATTEMPTS=${GINKGO_ATTEMPTS:-1}

scripts/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function main() {
8989
)
9090
fi
9191

92-
#util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
92+
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
9393
util::tools::cf::install --directory "${ROOTDIR}/.bin"
9494

9595
for row in "${matrix[@]}"; do

scripts/package.sh

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ set -o pipefail
77
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
88
readonly ROOTDIR
99

10-
## shellcheck source=SCRIPTDIR/.util/tools.sh
11-
#source "${ROOTDIR}/scripts/.util/tools.sh"
12-
#
10+
# shellcheck source=SCRIPTDIR/.util/tools.sh
11+
source "${ROOTDIR}/scripts/.util/tools.sh"
12+
1313
# shellcheck source=SCRIPTDIR/.util/print.sh
1414
source "${ROOTDIR}/scripts/.util/print.sh"
1515

@@ -92,43 +92,27 @@ function package::buildpack() {
9292
echo "${version}" > "${ROOTDIR}/VERSION"
9393
fi
9494

95+
mkdir -p "$(dirname "${output}")"
96+
97+
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
98+
99+
echo "Building buildpack (version: ${version}, stack: ${stack}, cached: ${cached}, output: ${output})"
100+
95101
local stack_flag
96102
stack_flag="--any-stack"
97103
if [[ "${stack}" != "any" ]]; then
98104
stack_flag="--stack=${stack}"
99105
fi
100106

101-
local cached_flag
102-
cached_flag="--uncached"
103-
if [[ "${cached}" == "true" ]]; then
104-
cached_flag="--cached"
105-
fi
106-
107-
pushd "${ROOTDIR}" &> /dev/null
108-
cat <<EOF > Dockerfile
109-
FROM ruby:3.0
110-
RUN apt-get update && apt-get install -y zip
111-
ADD cf.Gemfile .
112-
ADD cf.Gemfile.lock .
113-
ENV BUNDLE_GEMFILE=cf.Gemfile
114-
RUN bundle install
115-
ENTRYPOINT ["bundle", "exec", "buildpack-packager"]
116-
EOF
117-
docker build -t buildpack-packager . &> /dev/null
107+
local file
108+
file="$(
109+
buildpack-packager build \
110+
"--version=${version}" \
111+
"--cached=${cached}" \
112+
"${stack_flag}" \
113+
| xargs -n1 | grep -e '\.zip$'
114+
)"
118115

119-
docker run --rm -v "${ROOTDIR}":/buildpack -w /buildpack buildpack-packager "${stack_flag}" ${cached_flag} &> /dev/null
120-
121-
popd &> /dev/null
122-
123-
rm -f "${ROOTDIR}/Dockerfile"
124-
125-
file="$(ls "${ROOTDIR}" | grep -i 'php.*zip' )"
126-
if [[ -z "${file}" ]]; then
127-
util::print::error "failed to find zip file in ${ROOTDIR}"
128-
fi
129-
130-
mkdir -p "$(dirname "${output}")"
131-
echo "Moving ${file} to ${output}"
132116
mv "${file}" "${output}"
133117
}
134118

0 commit comments

Comments
 (0)