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.
The following prerequisites are required to create an accelerator:
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:
Clone your Git repository.
Create a file named accelerator.yaml
in the root directory of this Git repository.
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.
Add the new accelerator.yaml
file, commit this change, and push to your Git repository.
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.Refresh Tanzu Application Platform GUI to reveal the newly published accelerator.
NoteIt 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:
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
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
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.
NoteYou 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.
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:
javaVersion
with three choices Java 8
, Java 11
, and Java 17
ReplaceText
transforms:
pom.xml
file then what is specified for <java.version>
is replaced with the chosen version.build.gradle
file then what is specified for sourceCompatibility
is replaced with the chosen version.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.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
NoteThe
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.
Learn how to: