Sample supply buildpack for Cloud Foundry sidecars
Go to file
Dr Nic Williams 55cc2b2c6d update ffi to 1.11.1; 1.11.0 was yanked 2019-05-22 10:15:48 +10:00
bin config-server should be executable 2019-05-18 12:42:19 +10:00
fixtures/rubyapp update ffi to 1.11.1; 1.11.0 was yanked 2019-05-22 10:15:48 +10:00
README.md link to part 1 article + repo 2019-05-22 10:01:19 +10:00

README.md

Part 2 - Supply buildpack for Cloud Foundry sidecars

Cloud Foundry sidecars are an additional process running inside your application container (see blog post). Cloud Foundry buildpacks allow the installation of additional software within your application container.

In this sample project, we use a buildpack to create a dummy executable config-server, and the application runs it as a sidecar.

Run through the demonstration below, and then see the highlights of parts of this repo/buildpack.

Part 1?

If this is "Part 2", where is "Part 1"?

I consider Tim Downey's post How to Push an App to Cloud Foundry with Sidecars to be "Part 1" in a series of articles and companion repositories. The companion repo for Tim's article is https://github.com/cloudfoundry-samples/capi-sidecar-samples which contains a Ruby application and a sidecar application.

Requirements

This demonstration of sidecars requires a Cloud Foundry running capi-release 1.79.0 or greater (for example cf-deployment v7.11.0 or higher).

At time of writing, unfortunately Cloud Foundry running locally with CFDev (cf dev start) does not yet have Sidecar support.

Fortunately, we can fix our CFDev with this script. Hurray!

cf dev start
eval "$(cf dev bosh env)"
curl -sS https://gist.githubusercontent.com/drnic/777e344bb34e32e102b67f2eb2e79bc1/raw/344696301f133622044082fd321a75093d123951/update-cf-capi.sh | bash -

cf login -a https://api.dev.cfdev.sh --skip-ssl-validation -u user -p pass

Demonstration

cf v3-create-app app-using-config-server
cf v3-apply-manifest -f fixtures/rubyapp/manifest.yml
cf v3-push app-using-config-server -p fixtures/rubyapp

If you view the logs you'll see the sidecar's output and the ruby app's output:

$ cf logs app-using-config-server --recent
...
[APP/PROC/WEB/SIDECAR/CONFIG-SERVER/0] OUT Starting dummy config-server...
[APP/PROC/WEB/0] ERR [2019-05-18 02:53:35] INFO  WEBrick 1.3.1
[APP/PROC/WEB/0] ERR [2019-05-18 02:53:35] INFO  ruby 2.4.6 (2019-04-01) [x86_64-linux]
[APP/PROC/WEB/0] ERR [2019-05-18 02:53:35] INFO  WEBrick::HTTPServer#start: pid=16 port=8080

Highlights

This project is first-and-foremostly a supply buildpack, which also includes an application for dev/testing/demonstration.

A supply buildpack can be used in addition to a normal buildpack to inject additional software/libraries/executables/files into the application droplet and runtime containers.

A supply buildpack needs:

  • a bin/supply file
  • to be included in an application's manifest.yml list of buildpacks, but cannot be the last in that list.

Our sample application's manifest.yml specifies this buildpack as the first in the list. It references the buildpack by its HTTPS URI to the git repository. It could have also referenced an HTTPS URI to a .zip file, or the name of a pre-uploaded buildpack (as found in cf buildpacks list).

  buildpacks:
  - https://github.com/starkandwayne/part2-sidecar-buildpack
  - ruby_buildpack

The bin/supply can create/install files into a specific folder. This folder is provided as the first argument when bin/supply is executed during staging.

In our bin/supply script we stored this first argument in the $BUILD_DIR environment variable; which is a more meaningful name than $1.

BUILD_DIR=$1

Our silly demonstration buildpack created a silly demonstration script config-server, and set it as an executable (chmod +x). Our application cannot interact with this silly sidecar; because its just silliness.

In our next sample buildpack we will package up some real software that our application can interact with.

Thanks

The sample app in fixtures/rubyapp and its example of running a fictional config-server sidecar originate from https://github.com/cloudfoundry-samples/capi-sidecar-samples/tree/master/sidecar-dependent-app.