Search code examples
cloud-foundrybuildpackdelivery-pipelinediego

Cloud Foundry app built with PHP buildpack - custom extention disappears after deploy


I have a CIO Blumix Cloud Foundry PHP app developed that needs some additional components.

I used https://github.com/cloudfoundry/php-buildpack for the build. I read in its documentation that I can add my own extension. I did that and added a tar.tgz and added instructions in the extention.py how to install it.

The target location is: /home/vcap/. I see the installation running okay, and I see the folder during deploy stage (in DevOps Pipelines deployment stage log&history).

But when deployment passes and I read with a deployed php page the folder, I see that it is not there. I read "container destroyed successfully" message in the log of the deploy. Maybe the whole installation environment goes destroyed? Where is a safe place in the deployment file structure where I can install components so they remain after the deployment passes?

I'm using the def compile(install): to place my unix commands. Example: os.system('ls') to list the installation folders content. They work properly.

Thx in advance!


Solution

  • There are two totally different environments used by your app: staging and runtime. Staging is where the buildpack runs & runtime is where the product of staging (i.e. your app) is run.

    Unfortunately, paths are not the same in staging and runtime. At runtime your app lives under /app or /home/vcap/app (the former is a symlink to the latter). Staging is different. There is a /home/vcap directory but it's not used for anything.

    Instead, the buildpack scripts are fed paths to use via cli arguments. This is all documented here.

    As a PHP buildpack extension, you can access the cli args, and many other things, by looking at the context that is maintained by the buildpack. This gets passed directly into the buildpack extension methods like service_environment & service_commands. The compile buildpack extension method is slightly different as the argument passed in is not the content, but that argument does have a reference to the context (it's install.builder._ctx).

    Having said all that, I would not recommend using PHP buildpack extensions at this point. The buildpack is being rewritten and that functionality is being dropped. It's not going to have a direct replacement, but the closest thing would be Composer's ability to execute scripts. My suggestion would be to see if you can use the Composer functionality. It'll be more portable as it won't depend on buildpack specific behavior.