PHP Cloud Native Buildpacks Now in the Official Builder
In my previous post, I talked about how to use the PHP Cloud Native buildpacks. It was not super tricky but required some manual work to set up. This is because the PHP CNBs were not, at the time, part of an official builder.
What’s a builder? It’s basically an image containing a bunch of CNBs, all ready for your use. See this link for more details.
If you are to run pack suggest-builders
, then you will see the list of official builders. At the time of writing, that is Heroku, Cloud Foundry (bionic) and Cloud Foundry (cflinuxfs3).
$ pack suggest-builders
Suggested builders:
Heroku: heroku/buildpacks:18 heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP
Cloud Foundry: cloudfoundry/cnb:bionic Ubuntu bionic base image with buildpacks for Java, NodeJS and Golang
Cloud Foundry: cloudfoundry/cnb:cflinuxfs3 cflinuxfs3 base image with buildpacks for Java, NodeJS, Python, Golang, PHP, HTTPD and NGINX
Tip: Learn more about a specific builder with: pack inspect-builder [builder image]
Notice how PHP is now included in the Cloud Foundry cflinuxfs3 builder.
So now, instead of all the work I had you doing in my last post, you can just run pack build --builder "cloudfoundry/cnb:cflinuxfs3"
. The builder will automatically select the PHP CNBs, because it sees you’re trying to build a PHP app. The result will be an image you can run with docker run -it -e PORT=8080 -p 8080:8080 image-name
, just like in my previous post.
That’s it! If you’d like to understand the output a bit more, keep reading. Otherwise go and enjoy!
If you’re curious about the output, the interesting new bit is the DETECTING phase. In the previous post, we manually specified just the PHP CNBs, so that’s all you’d see in the output. Now, we see many CNBs running, but only the PHP CNBs will be selected and actually run at build time.
===> DETECTING
[detector] ======== Results ========
[detector] skip: [email protected]
[detector] pass: [email protected]
[detector] skip: [email protected]
[detector] pass: [email protected]
[detector] pass: [email protected]
[detector] pass: [email protected]
[detector] pass: [email protected]
[detector] skip: [email protected]
[detector] skip: [email protected]
[detector] skip: [email protected]
[detector] skip: [email protected]
[detector] skip: [email protected]
[detector] skip: [email protected]
[detector] pass: [email protected]
[detector] Resolving plan... (try #1)
[detector] fail: [email protected] requires jvm-application
[detector] Resolving plan... (try #2)
[detector] fail: [email protected] requires openjdk-jre
[detector] Resolving plan... (try #3)
[detector] fail: [email protected] requires jvm-application
[detector] ======== Output: [email protected] ========
[detector] no "yarn.lock" found at: /workspace/yarn.lock
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] fail: [email protected]
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] fail: [email protected]
[detector] ======== Output: [email protected] ========
[detector] no Pipfile found
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] skip: [email protected]
[detector] pass: [email protected]
[detector] Resolving plan... (try #1)
[detector] fail: [email protected] requires requirements
[detector] ======== Results ========
[detector] fail: [email protected]
[detector] ======== Output: [email protected] ========
[detector] *.runtimeconfig.json file not found
[detector] ======== Results ========
[detector] fail: [email protected]
[detector] ======== Output: [email protected] ========
[detector] no "go.mod" found at: /workspace/go.mod
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] fail: [email protected]
[detector] ======== Output: [email protected] ========
[detector] failed detection: no Gopkg.toml found at root level
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] fail: [email protected]
[detector] ======== Output: [email protected] ========
[detector] no "composer.json" found in the following locations: [/workspace/composer.json /workspace/htdocs/composer.json]
[detector] ======== Results ========
[detector] pass: [email protected]
[detector] skip: [email protected]
[detector] pass: [email protected]
[detector] pass: [email protected]
[detector] Resolving plan... (try #1)
[detector] skip: [email protected] provides unused httpd
[detector] Success! (2)
See how they all fail, until you get down to the PHP CNBs. Then you see Success!
.
Then just like the last time, we see the PHP CNBs running during the BUILD phase.
===> BUILDING
[builder]
[builder] PHP Buildpack 0.0.28
[builder] PHP 7.2.22: Contributing to layer
[builder] Downloading from https://buildpacks.cloudfoundry.org/dependencies/php/php7-7.2.22-linux-x64-cflinuxfs3-c9315fce.tgz
[builder] Verifying checksum
[builder] Expanding to /layers/org.cloudfoundry.php-dist/php-binary
[builder] Writing PATH to shared
[builder] Writing MIBDIRS to shared
[builder] Writing PHP_HOME to shared
[builder] Writing PHP_EXTENSION_DIR to shared
[builder] Writing PHP_API to shared
[builder]
[builder] PHP Web Buildpack 0.0.18
[builder] Configuring PHP Script
[builder] PHP Web 173b6da1f1b7b7a59af0c2ebcfe1c4ea4b183063a90b92f1f2ae6d8a9ebb0bfd: Contributing to layer
[builder] Writing PHPRC to shared
[builder] Writing PHP_INI_SCAN_DIR to shared
[builder] WARNING: `app.php` start script not found. App will not start unless you specify a custom start command.
[builder] Process types:
[builder] task: php /workspace/app.php
[builder] web: php /workspace/app.php
That’s all there is too it.