<commit_before>---
title: Stack Association 
owner: Buildpacks
---

This topic describes the stack association feature for <%= vars.first_product_name %> buildpacks. 

<p class="note"><strong>Note</strong>: This functionality is supported as of CAPI <a href="https://github.com/cloudfoundry/capi-release/releases/tag/1.58.0">v1.58.0</a> and cf CLI  <a href="https://github.com/cloudfoundry/cli/releases/tag/v6.39.0">v6.39.0</a>.</p>

<p class="note warning"><strong>Warning</strong>: To avoid security exposure, ensure that you migrate your apps and custom buildpacks to use the <code>cflinuxfs3</code> stack based on Ubuntu 18.04 (Bionic Beaver). <code>cflinuxfs2</code> is based on Ubuntu 14.04 (Trusty Tahr), which reaches end of general support (EOGS) in April 2019. </p>

## <a id='overview'></a> Overview ##

Each buildpack in your <%= vars.product_name %> deployment is associated with a stack. You can see this when you run `cf buildpacks`: there is a `stack` column in the output that shows a corresponding stack for each buildpack. See the following example: 

<pre class="terminal">
$ cf buildpacks
Getting buildpacks...

buildpack                position   enabled   locked   filename                                             stack
staticfile_buildpack     1          true      false    staticfile_buildpack-cached-cflinuxfs3-v1.4.29.zip   cflinuxfs3
java_buildpack_offline   2          true      false    java-buildpack-offline-cflinuxfs3-v4.12.1.zip        cflinuxfs3
ruby_buildpack           3          true      false    ruby_buildpack-cached-cflinuxfs3-v1.7.21.zip         cflinuxfs3
. . . 
</pre>

Because of this stack association, buildpacks do not have to be uniquely named. This helps in managing similar buildpacks that are compatible with different stacks. 

The [buildpack packager](https://github.com/cloudfoundry/libbuildpack/tree/master/packager) includes a `-stack` option. If you use this option and upload a buildpack to <%= vars.product_name %>, the Cloud Controller detects the stack association and creates a stack record for the buildpack. 

## <a id='no-stack-record'></a> Buildpacks without a Stack Record ##

Some buildpacks may have a missing stack record. For example, if you uploaded a custom buildpack before <%= vars.product_name %> introduced stack association. The output of `cf buildpacks` shows a blank `stack` column if the buildpack does not have a stack record. 

In this case, you must manually assign a stack to the buildpack. To do this, run `cf update-buildpack BUILDPACK-NAME --assign-stack stack`.

Buildpacks with a missing stack record will continue to work, but are more manageable when the stack record is present. 

Consider the following behavior when pushing apps to a deployment that has buildpacks with a missing stack record:

* If you push an app and specify a stack with `cf push app-name -s stack`, <%= vars.product_name %> uses that stack. Otherwise, it uses the system default, `cflinuxfs3`. 
* You may see additional logging in the buildpack detection output of the `cf push` command when <%= vars.product_name %> detects buildpacks without a stack record. 

## <a id='stack-cli'></a> Managing Stack Association with the cf CLI ##

The cf CLI commands for managing buildpacks include functionality to support association between buildpacks and stacks. The `update-buildpack`, `rename-buildpack`, and `delete-buildpack` commands all include a `-s` flag for specifying a stack. 

<p class="note"><strong></strong>: In cf CLI v7, the <code>rename-buildpack</code> command is removed in favor of <code>cf update-buildpack --rename</code>.</p>

When operating on buildpacks with the cf CLI, consider the following:

* You cannot upload a buildpack with `cf create-buildpack` if a buildpack of the same name already exists and it has a missing stack record. 
* When using `cf create-buildpack`, you may inadvertently create a duplicate buildpack with a `nil` stack. `cf create-buildpack` does not disallow creation of buildpacks with no stack association.
* The `-s` flag is required when there are two buildpacks with the same name. If you are operating on a uniquely named buildpack, you do not need to specify its stack. 
* If you have two buildpacks of the same name, one with a stack record and one without, running cf CLI commands without `-s` operates on the buildpack with the missing stack record. <commit_msg>makes note consistent with other topics[#166200641]<commit_after>---
title: Stack Association 
owner: Buildpacks
---

This topic describes the stack association feature for <%= vars.first_product_name %> buildpacks. 

<p class="note"><strong>Note</strong>: This functionality is supported as of CAPI <a href="https://github.com/cloudfoundry/capi-release/releases/tag/1.58.0">v1.58.0</a> and cf CLI  <a href="https://github.com/cloudfoundry/cli/releases/tag/v6.39.0">v6.39.0</a>.</p>

<p class="note warning"><strong>Warning</strong>: To avoid security exposure, ensure that you migrate your apps and custom buildpacks to use the <code>cflinuxfs3</code> stack based on Ubuntu 18.04 (Bionic Beaver). <code>cflinuxfs2</code> is based on Ubuntu 14.04 (Trusty Tahr), which reaches end of general support (EOGS) in April 2019. </p>

## <a id='overview'></a> Overview ##

Each buildpack in your <%= vars.product_name %> deployment is associated with a stack. You can see this when you run `cf buildpacks`: there is a `stack` column in the output that shows a corresponding stack for each buildpack. See the following example: 

<pre class="terminal">
$ cf buildpacks
Getting buildpacks...

buildpack                position   enabled   locked   filename                                             stack
staticfile_buildpack     1          true      false    staticfile_buildpack-cached-cflinuxfs3-v1.4.29.zip   cflinuxfs3
java_buildpack_offline   2          true      false    java-buildpack-offline-cflinuxfs3-v4.12.1.zip        cflinuxfs3
ruby_buildpack           3          true      false    ruby_buildpack-cached-cflinuxfs3-v1.7.21.zip         cflinuxfs3
. . . 
</pre>

Because of this stack association, buildpacks do not have to be uniquely named. This helps in managing similar buildpacks that are compatible with different stacks. 

The [buildpack packager](https://github.com/cloudfoundry/libbuildpack/tree/master/packager) includes a `-stack` option. If you use this option and upload a buildpack to <%= vars.product_name %>, the Cloud Controller detects the stack association and creates a stack record for the buildpack. 

## <a id='no-stack-record'></a> Buildpacks without a Stack Record ##

Some buildpacks may have a missing stack record. For example, if you uploaded a custom buildpack before <%= vars.product_name %> introduced stack association. The output of `cf buildpacks` shows a blank `stack` column if the buildpack does not have a stack record. 

In this case, you must manually assign a stack to the buildpack. To do this, run `cf update-buildpack BUILDPACK-NAME --assign-stack stack`.

Buildpacks with a missing stack record will continue to work, but are more manageable when the stack record is present. 

Consider the following behavior when pushing apps to a deployment that has buildpacks with a missing stack record:

* If you push an app and specify a stack with `cf push app-name -s stack`, <%= vars.product_name %> uses that stack. Otherwise, it uses the system default, `cflinuxfs3`. 
* You may see additional logging in the buildpack detection output of the `cf push` command when <%= vars.product_name %> detects buildpacks without a stack record. 

## <a id='stack-cli'></a> Managing Stack Association with the cf CLI ##

The cf CLI commands for managing buildpacks include functionality to support association between buildpacks and stacks. The `update-buildpack`, `rename-buildpack`, and `delete-buildpack` commands all include a `-s` flag for specifying a stack. 

<p class="note"><strong>Note</strong>: cf CLI v7 removes the <code>cf rename-buildpack</code> command in favor of a <code>--rename</code> option for <code>cf update-buildpack</code>.</p>

When operating on buildpacks with the cf CLI, consider the following:

* You cannot upload a buildpack with `cf create-buildpack` if a buildpack of the same name already exists and it has a missing stack record. 
* When using `cf create-buildpack`, you may inadvertently create a duplicate buildpack with a `nil` stack. `cf create-buildpack` does not disallow creation of buildpacks with no stack association.
* The `-s` flag is required when there are two buildpacks with the same name. If you are operating on a uniquely named buildpack, you do not need to specify its stack. 
* If you have two buildpacks of the same name, one with a stack record and one without, running cf CLI commands without `-s` operates on the buildpack with the missing stack record. 
{'fraction_non_alphanumeric': 0.08269230769230769, 'fraction_numerical': 0.013009049773755657, 'mean_word_length': 3.892639734366353, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '751148', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2371, 'n_words': 1103}