Creating accelerators

This topic describes how to create an accelerator in Tanzu Application Platform GUI. An accelerator contains your enterprise-conformant code and configurations that developers can use to create new projects that by default follow the standards defined in your accelerators.

Prerequisites

The following prerequisites are required to create an accelerator:

  • Application Accelerator is installed. For information about installing Application Accelerator, see Installing Application Accelerator for VMware Tanzu
  • You can access Tanzu Application Platform GUI from a browser. For more information, see the “Tanzu Application Platform GUI” section in the most recent release for Tanzu Application Platform documentation
  • kubectl v1.20 and later. The Kubernetes command line tool (kubectl) is installed and authenticated with admin rights for your target cluster.

Getting started

You can use any Git repository to create an accelerator. You need the URL for the repository to create an accelerator.

For this example, the Git repository is public and contains a README.md file. These are options available when you create repositories on GitHub.

Use the following procedure to create an accelerator based on this Git repository:

  1. Clone your Git repository.

  2. Create a file named accelerator.yaml in the root directory of this Git repository.

  3. Add the following content to the accelerator.yaml file:

    accelerator:
      displayName: Simple Accelerator
      description: Contains just a README
      iconUrl: https://images.freecreatives.com/wp-content/uploads/2015/05/smiley-559124_640.jpg
      tags:
      - simple
      - getting-started
    

    Feel free to use a different icon if it uses a reachable URL.

  4. Add the new accelerator.yaml file, commit this change, and push to your Git repository.

Publishing the new accelerator

  1. To publish your new accelerator, run this command in your terminal:

    tanzu accelerator create simple --git-repository YOUR-GIT-REPOSITORY-URL --git-branch YOUR-GIT-BRANCH
    

    Where:

    • YOUR-GIT-REPOSITORY-URL is the URL for your Git repository.
    • YOUR-GIT-BRANCH is the name of the branch where you pushed the new accelerator.yaml file.
  2. Refresh Tanzu Application Platform GUI to reveal the newly published accelerator.

    Screenshot showing the new Simple Accelerator included in Tanzu Application Platform GUI.

    Note

    It might take a few seconds for Tanzu Application Platform GUI to refresh the catalog and add an entry for your new accelerator.

An alternative to using the Tanzu CLI is to create a separate manifest file and apply it to the cluster:

  1. Create a simple-manifest.yaml file and add the following content, filling in with your Git repository and branch values.

    apiVersion: accelerator.apps.tanzu.vmware.com/v1alpha1
    kind: Accelerator
    metadata:
      name: simple
      namespace: accelerator-system
    spec:
      git:
        url: YOUR-GIT-REPOSITORY-URL
        ref:
          branch: YOUR-GIT-BRANCH
    
  2. To apply the simple-manifest.yaml, run this command in your terminal in the directory where you created this file:

    tanzu accelerator apply -f simple-manifest.yaml
    

Using local-path for publishing accelerators

You can publish an accelerator directly from a local directory on your system. This helps when authoring accelerators and allows you to avoid having to commit every small change to a remote Git repository.

Note

You can also specify --interval so the accelerator is reconciled quicker when we push new changes.

tanzu accelerator create simple --local-path PATH-TO-THE-ACCELERATOR --source-image YOUR-SOURCE-IMAGE-REPO --interval 10s

Where:

  • PATH-TO-THE-ACCELERATOR is the path to the accelerator source. It can be fully qualified or a relative path. If your current directory is already the directory where your source is, then use “.”.
  • YOUR-SOURCE-IMAGE-REPO is the name of the OCI image repository where you want to push the new accelerator source. If using Docker Hub, use something such as docker.io/YOUR-DOCKER_ID/simple-accelerator-source.

After you have made any additional changes you can push the latest to the same OCI image repository using:

tanzu accelerator push --local-path PATH-TO-THE-ACCELERATOR --source-image YOUR-SOURCE-IMAGE-REPO

The accelerator now reflects the new content after approximately a 10 second wait since we specified that as the interval when we created the accelerator above.

Using accelerator fragments

Accelerator fragments are reusable accelerator components that can provide options, files or transforms. They may be imported to accelerators using an import entry and the transforms from the fragment may be referenced in an InvokeFragment transform in the accelerator that is declaring the import. For additional details see InvokeFragment transform.

The accelerator samples include three fragments - java-version, tap-initialize, and live-update. See the vmware-tanzu/application-accelerator-samples/fragments Git repository for the content of these fragments.

To discover what fragments are available to use, you can run the following command:

tanzu accelerator fragment list

Look a the java-version fragment as an example. It contains the following accelerator.yaml file:

accelerator:
  options:
  - name: javaVersion
    inputType: select
    label: Java version to use
    choices:
    - value: "1.8"
      text: Java 8
    - value: "11"
      text: Java 11
    - value: "17"
      text: Java 17
    defaultValue: "11"
    required: true

engine:
  merge:
    - include: [ "pom.xml" ]
      chain:
      - type: ReplaceText
        regex:
          pattern: "<java.version>.*<"
          with: "'<java.version>' + #javaVersion + '<'"
    - include: [ "build.gradle" ]
      chain:
      - type: ReplaceText
        regex:
          pattern: "sourceCompatibility = .*"
          with: "'sourceCompatibility = ''' + #javaVersion + ''''"
    - include: [ "config/workload.yaml" ]
      chain:
      - type: ReplaceText
        condition: "#javaVersion == '17'"
        substitutions:
          - text: "spec:"
            with: "'spec:\n  build:\n    env:\n    - name: BP_JVM_VERSION\n      value: \"17\"'"

This fragment contributes the following to any accelerator that imports it:

  1. An option named javaVersion with three choices Java 8, Java 11, and Java 17
  2. Three ReplaceText transforms:
    • if the accelerator has a pom.xml file then what is specified for <java.version> is replaced with the chosen version.
    • if the accelerator has a build.gradle file then what is specified for sourceCompatibility is replaced with the chosen version.
    • if the accelerator has a config/workload.yaml file and the user selected “Java 17” then a build environment entry of BP_JVM_VERSION is inserted into the spec: section.

Deploying accelerator fragments

To deploy new fragments to the accelerator system you can use the new tanzu accelerator fragment create CLI command or you can apply a custom resource manifest file with either kubectl apply or the tanzu accelerator apply commands.

The resource manifest for the java-version fragment looks like this:

apiVersion: accelerator.apps.tanzu.vmware.com/v1alpha1
kind: Fragment
metadata:
  name: java-version
  namespace: accelerator-system
spec:
  displayName: Select Java Version
  git:
    ref:
      tag: tap-1.3
    url: https://github.com/vmware-tanzu/application-accelerator-samples.git
    subPath: fragments/java-version

To create the fragment (we can save the above manifest in a java-version.yaml file) and use:

tanzu accelerator apply -f ./java-version.yaml
Note

The accelerator apply command can be used to apply both Accelerator and Fragment resources.

To avoid having to create a separate manifest file, you can use the following command instead:

tanzu accelerator fragment create java-version \
  --git-repo https://github.com/vmware-tanzu/application-accelerator-samples.git \
  --git-tag tap-1.3 \
  --git-sub-path fragments/java-version

Now you can use this java-version fragment in an accelerator:

accelerator:
  displayName: Hello Fragment
  description: A sample app
  tags:
  - java
  - spring
  - cloud
  - tanzu

  imports:
  - name: java-version

engine:
  merge:
    - include: ["**/*"]
    - type: InvokeFragment
      reference: java-version

The earlier acelerator imports the java-version which, as seen earlier, provides an option to select the Java version to use for the project. It then instructs the engine to invoke the transforms provided in the fragment that updates the Java version used in pom.xml or build.gradle files from the accelerator.

For more detail on the use of fragments, see InvokeFragment transform.

Next steps

Learn how to:

check-circle-line exclamation-circle-line close-line
Scroll to top icon