From 5861e2db1e69793efb8bc2c101d7c83367e00be9 Mon Sep 17 00:00:00 2001 From: trisberg Date: Mon, 11 Nov 2024 12:02:32 -0500 Subject: [PATCH] Add service instance and service binding to spring-music --- spring-music/README.md | 76 ++++--------------- spring-music/accelerator.axl | 30 ++++++++ .../.tanzu/config/spring-music-binding.yml | 30 ++++++++ .../config/spring-music-mongodb-instance.yml | 6 ++ .../config/spring-music-mysql-instance.yml | 6 ++ .../spring-music-postgresql-instance.yml | 6 ++ .../config/spring-music-redis-instance.yml | 6 ++ 7 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 spring-music/deploy/tpfork8s/.tanzu/config/spring-music-binding.yml create mode 100644 spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mongodb-instance.yml create mode 100644 spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mysql-instance.yml create mode 100644 spring-music/deploy/tpfork8s/.tanzu/config/spring-music-postgresql-instance.yml create mode 100644 spring-music/deploy/tpfork8s/.tanzu/config/spring-music-redis-instance.yml diff --git a/spring-music/README.md b/spring-music/README.md index 600b06548..5239a6a4e 100644 --- a/spring-music/README.md +++ b/spring-music/README.md @@ -171,48 +171,24 @@ tanzu deploy ``` -### Create the service and bind it to the app - -You can deploy a Redis instance using a provided service type. -To list available service types use: - -```shell -tanzu services type list -``` - -Then, create the service instance using: - -```shell -tanzu services create RedisCluster/music -``` +### Check the status of the service bound to the app -When prompted, bind the service to your deployed app. +The deployment includes a Redis instance using a provided service type. +The instance is bound to the app. -You can list the services you have created using: +You can list the services created using: ```shell tanzu services list ``` -### Create the service and bind it to the app - -You can deploy a mongoDB instance using a provided service type. -To list available service types use: - -```shell -tanzu services type list -``` - -Then, create the service instance using: - -```shell -tanzu services create MongoDBInstance/music -``` +### Check the status of the service bound to the app -When prompted, bind the service to your deployed app. +The deployment includes a MongoDB instance using a provided service type. +The instance is bound to the app. -You can list the services you have created using: +You can list the services created using: ```shell tanzu services list @@ -229,22 +205,10 @@ No service binding is necessary. -You can deploy a MySQL instance using a provided service type. -To list available service types use: - -```shell -tanzu services type list -``` - -Create a MySQL database service instance using: - -```shell -tanzu services create MySQLInstance/music -``` - -When prompted, bind the service to your deployed app. +The deployment includes a MySQL instance using a provided service type. +The instance is bound to the app. -You can list the services you have created using: +You can list the services created using: ```shell tanzu services list @@ -252,22 +216,10 @@ tanzu services list -You can deploy a PostgreSQL instance using a provided service type. -To list available service types use: - -```shell -tanzu services type list -``` - -Create a PostgreSQL database service instance using: - -```shell -tanzu services create PostgreSQLInstance/music -``` - -When prompted, bind the service to your deployed app. +The deployment includes a PostgreSQL instance using a provided service type. +The instance is bound to the app. -You can list the services you have created using: +You can list the services created using: ```shell tanzu services list diff --git a/spring-music/accelerator.axl b/spring-music/accelerator.axl index 477195db9..f5af7df53 100644 --- a/spring-music/accelerator.axl +++ b/spring-music/accelerator.axl @@ -16,6 +16,36 @@ engine { ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '.yml') } + if ((#persistenceType == 'jpa' && #databaseType != 'h2') || #persistenceType == 'mongodb' || #persistenceType == 'redis') { + applyTo("deploy/tpfork8s/.tanzu/config/spring-music-binding.yml") { + ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) + RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '-binding.yml') + } + } + if (#persistenceType == 'jpa' && #databaseType == 'mysql') { + applyTo("deploy/tpfork8s/.tanzu/config/spring-music-mysql-instance.yml") { + ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) + RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '-mysql-instance.yml') + } + } + if (#persistenceType == 'jpa' && #databaseType == 'postgres') { + applyTo("deploy/tpfork8s/.tanzu/config/spring-music-postgresql-instance.yml") { + ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) + RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '-postgresql-instance.yml') + } + } + if (#persistenceType == 'mongodb') { + applyTo("deploy/tpfork8s/.tanzu/config/spring-music-mongodb-instance.yml") { + ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) + RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '-mongodb-instance.yml') + } + } + if (#persistenceType == 'redis') { + applyTo("deploy/tpfork8s/.tanzu/config/spring-music-redis-instance.yml") { + ReplaceText({{text: "spring-music", with: #artifactId.toLowerCase()}}) + RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '-redis-instance.yml') + } + } select(!"deploy/**") } } diff --git a/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-binding.yml b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-binding.yml new file mode 100644 index 000000000..4712be089 --- /dev/null +++ b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-binding.yml @@ -0,0 +1,30 @@ +apiVersion: services.tanzu.vmware.com/v1 +kind: ServiceBinding +metadata: + generateName: music- +spec: + alias: music + serviceRef: + apiGroup: bitnami.database.tanzu.vmware.com +#IF(#persistenceType == 'jpa') + #IF(#databaseType != 'h2') + #IF(#databaseType == 'mysql') + kind: MySQLInstance + #ENDIF + #IF(#databaseType == 'postgres') + kind: PostgreSQLInstance + #ENDIF + #ENDIF +#ELSE + #IF(#persistenceType == 'mongodb') + kind: MongoDBInstance + #ENDIF + #IF(#persistenceType == 'redis') + kind: RedisCluster + #ENDIF +#ENDIF + name: music + targetRef: + apiGroup: apps.tanzu.vmware.com + kind: ContainerApp + name: spring-music diff --git a/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mongodb-instance.yml b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mongodb-instance.yml new file mode 100644 index 000000000..f61ee0b45 --- /dev/null +++ b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mongodb-instance.yml @@ -0,0 +1,6 @@ +apiVersion: bitnami.database.tanzu.vmware.com/v1alpha1 +kind: MongoDBInstance +metadata: + name: music +spec: + storageGB: 1 diff --git a/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mysql-instance.yml b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mysql-instance.yml new file mode 100644 index 000000000..7f7a8fb7a --- /dev/null +++ b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-mysql-instance.yml @@ -0,0 +1,6 @@ +apiVersion: bitnami.database.tanzu.vmware.com/v1alpha1 +kind: MySQLInstance +metadata: + name: music +spec: + storageGB: 1 diff --git a/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-postgresql-instance.yml b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-postgresql-instance.yml new file mode 100644 index 000000000..8264ecfb5 --- /dev/null +++ b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-postgresql-instance.yml @@ -0,0 +1,6 @@ +apiVersion: bitnami.database.tanzu.vmware.com/v1alpha1 +kind: PostgreSQLInstance +metadata: + name: music +spec: + storageGB: 1 diff --git a/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-redis-instance.yml b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-redis-instance.yml new file mode 100644 index 000000000..142f832ea --- /dev/null +++ b/spring-music/deploy/tpfork8s/.tanzu/config/spring-music-redis-instance.yml @@ -0,0 +1,6 @@ +apiVersion: bitnami.database.tanzu.vmware.com/v1alpha1 +kind: RedisCluster +metadata: + name: music +spec: + storageGB: 1