0

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!

Andr
  • 88
  • 1
  • 10

1 Answers1

1

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.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • thx for your answer. It's very helpful. Can you maybe give direction also for delivery pipelnie.. where I can add additional jobs .. example to Build stage. Just added one (before I read your response).. and there I also can unpack a zip and run an install... and I see that the install installed the app into /pipeline/.. With my running web app.. I still don't see the installed up. Must have been deleted. Maybe you also can give advise how to write that job? Or how to set its parameters - example output dir I can set.. – Andr Jul 20 '18 at 09:10
  • I stopped use of custom extension of the build-pack as you recommended and run the same script in the pipelines build stage added job. But still don't see this installed up after release. – Andr Jul 20 '18 at 09:13
  • 1
    Sorry, I don't understand your follow up question. If the script is running outside of staging, like on your CI/CD system you need to push *everything*. If your script is running through Composer during staging, anything you want included in the droplet needs to go into the deps directory, see the `supply` script notes here https://docs.cloudfoundry.org/buildpacks/understand-buildpacks.html#buildpack-scripts. If you put it into the deps folder, it'll be included in the droplet and available to your app at runtime. – Daniel Mikusa Jul 20 '18 at 20:20
  • I'm using IBM CIO Delivery Pipeline added to my Cloud Foundry PHP app. As I want to have a service that is not listed in the Bluemix Chatalog I have to install it somehow myself. The service is sold as a product arrives in a tar.gz. I can upload this tar.gz and unpack. I also can run the install using either the script window of the build stage and also in the deploy stage. I know this is try and failure method but I'm a beginner. If I knew what tool I can use to install this product so it remains on the system.. that would be helpfull.(I found a copy path that remained .. but its not working) – Andr Jul 23 '18 at 08:31
  • 1
    I would not recommend trying to run a service inside the same container as your app. Run your app and run your service separately. If it makes sense to run your app on Cloud Foundry, you can push it separate as it's own app. If it's a pre-compiled app, you might be able to do it easily enough with the binary buildpack (the buildpack does nothing, which is perfect for running pre-compiled binaries). If it doesn't make sense to run on CF, maybe it stores persistent data, then run it in a VM elsewhere and pass the connection info into your app (maybe with a user provided service). – Daniel Mikusa Jul 23 '18 at 11:41
  • Understand. Thank you!! – Andr Jul 23 '18 at 11:48