diff --git a/README.md b/README.adoc similarity index 58% rename from README.md rename to README.adoc index e9bd66c..8b939d9 100644 --- a/README.md +++ b/README.adoc @@ -1,14 +1,11 @@ -Integration between [Cloudfoundry](https://github.com/cloudfoundry) -and the [Spring Cloud Components](https://github.com/spring-cloud). +// Do not edit this file (go to /home/dsyer/dev/cloud/scripts/cloudfoundry/src/main/ruby/../../../src/main/asciidoc/README.adoc instead)Integration between https://github.com/cloudfoundry[Cloud Foundry] +and https://github.com/spring-cloud[Spring Cloud]. -Add this project to a Spring Boot REST service and deploy to -Cloudfoundry (and use the Actuator for maximum flexibility). It will -expose service-broker endpoints automatically (look in /mappings for -/v2/*) and you can register it with the Cloud Controller as described -here: -[http://docs.cloudfoundry.org/services/managing-service-brokers.html](http://docs.cloudfoundry.org/services/managing-service-brokers.html). -Example script to deploy and register a broker: +== Service Broker Example + + +Example script to deploy and regis#ter a broker: ``` DOMAIN=mydomain.net @@ -67,31 +64,8 @@ that through the `vcap.services.[service].credentials.uri` environment property. If your service also has a -[Eureka core](https://github.com/Netflix/eureka) dependency, and you +https://github.com/Netflix/eureka[Eureka core] dependency, and you can expose it as a Eureka service, then any service which registers -with Eureka will also become a Cloudfoundry service. Example app with -Eureka server (include jersey 1.13 to get the JAX-RS dependencies): +with Eureka will also become a Cloud Foundry service. -``` -@Configuration -@EnableAutoConfiguration -public class Application extends WebMvcConfigurerAdapter { - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - @Bean - public FilterRegistrationBean jersey() { - FilterRegistrationBean bean = new FilterRegistrationBean(); - bean.setFilter(new ServletContainer()); - bean.addInitParameter("com.sun.jersey.config.property.WebPageContentRegex", - "(/|/(flex/|images/|js/|css/|jsp/|admin/|v2/catalog|v2/service_instances).*)"); - bean.addInitParameter("com.sun.jersey.config.property.packages", - "com.sun.jersey;com.netflix"); - return bean; - } - -} - -``` diff --git a/pom.xml b/pom.xml index 16fdbde..7846547 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,39 @@ 1.7 + + + + maven-antrun-plugin + + + org.jruby + jruby-complete + 1.7.12 + + + + + readme + process-resources + + run + + false + + + + + + + + + + + + + + milestone diff --git a/src/main/asciidoc/README.adoc b/src/main/asciidoc/README.adoc new file mode 100644 index 0000000..05a865f --- /dev/null +++ b/src/main/asciidoc/README.adoc @@ -0,0 +1,6 @@ +include::intro.adoc[] + +== Service Broker Example + +include::broker-example.adoc[] + diff --git a/src/main/asciidoc/broker-example.adoc b/src/main/asciidoc/broker-example.adoc new file mode 100644 index 0000000..7b8b961 --- /dev/null +++ b/src/main/asciidoc/broker-example.adoc @@ -0,0 +1,64 @@ + +Example script to deploy and regis#ter a broker: + +``` +DOMAIN=mydomain.net +cf push app -p target/*.jar --no-start +cf env app | grep SPRING_PROFILES_ACTIVE || cf set-env app SPRING_PROFILES_ACTIVE cloud +cf env app | grep APPLICATION_DOMAIN || cf set-env app APPLICATION_DOMAIN ${DOMAIN} + +cf services | grep configserver && cf bind app configserver + +cf restart app +cf create-service-broker app user secure http://app.${DOMAIN} + +for f in `cf curl /v2/service_plans | grep '\"guid' | sed -e 's/.*: "//' -e 's/".*//'`; do + cf curl v2/service_plans/$f -X PUT -d '{"public":true}' +done + +cf create-service app free appi +``` + +At which point you have a service called "app" and a service instance called "appi": + +``` +$ cf marketplace +OK + +service plans description +app free Singleton service app +$ cf services +Getting services in org default / space development as admin... +OK + +name service plan bound apps +appi app free +``` + +Your application can define a configuration property +`application.domain` (defaults to "cfapps.io") which will be used to +construct the credentials for any app that binds to your service. Or +it can define the URI directly using +`cloudfoundry.service.definition.metadata.uri`. + +You can change some other basic metadata by setting config properties: + +* `cloudfoundry.service.definition.*` is bound to a + `ServiceDefinition` (defined in spring-boot-cf-service-broker) which + has optional setters for plans and metadata. + +* `cloudfoundry.service.broker.*` is bound to an internal bean. It has + optional setters for "name" (the service name), "description" (user + friendly description) and "prefix" (used to create a unique id from + the name). + +An app which binds to your service will get credentials that contain a +"uri" property linking to your service. A Spring Boot app can bind to +that through the `vcap.services.[service].credentials.uri` environment +property. + +If your service also has a +https://github.com/Netflix/eureka[Eureka core] dependency, and you +can expose it as a Eureka service, then any service which registers +with Eureka will also become a Cloud Foundry service. + diff --git a/src/main/asciidoc/intro.adoc b/src/main/asciidoc/intro.adoc new file mode 100644 index 0000000..50d538a --- /dev/null +++ b/src/main/asciidoc/intro.adoc @@ -0,0 +1,3 @@ +Integration between https://github.com/cloudfoundry[Cloud Foundry] +and https://github.com/spring-cloud[Spring Cloud]. + diff --git a/src/main/asciidoc/quickstart.adoc b/src/main/asciidoc/quickstart.adoc new file mode 100644 index 0000000..9fc88db --- /dev/null +++ b/src/main/asciidoc/quickstart.adoc @@ -0,0 +1,7 @@ +Add this project to a Spring Boot REST service and deploy to +Cloudfoundry (and use the Actuator for maximum flexibility). It will +expose service-broker endpoints automatically (look in /mappings for +/v2/*) and you can register it with the Cloud Controller as described +here: +http://docs.cloudfoundry.org/services/managing-service-brokers.html[http://docs.cloudfoundry.org/services/managing-service-brokers.html]. + diff --git a/src/main/asciidoc/spring-cloud-cloudfoundry.adoc b/src/main/asciidoc/spring-cloud-cloudfoundry.adoc index 01e1d22..e5dc800 100644 --- a/src/main/asciidoc/spring-cloud-cloudfoundry.adoc +++ b/src/main/asciidoc/spring-cloud-cloudfoundry.adoc @@ -1,76 +1,8 @@ = Spring Cloud for Cloud Foundry -Integration between https://github.com/cloudfoundry[Cloud Foundry] -and https://github.com/spring-cloud[Spring Cloud]. - -Add this project to a Spring Boot REST service and deploy to -Cloudfoundry (and use the Actuator for maximum flexibility). It will -expose service-broker endpoints automatically (look in /mappings for -/v2/*) and you can register it with the Cloud Controller as described -here: -http://docs.cloudfoundry.org/services/managing-service-brokers.html[http://docs.cloudfoundry.org/services/managing-service-brokers.html]. +include::intro.adoc[] == Service Broker Example -Example script to deploy and register a broker: +include::broker-example.adoc[] -``` -DOMAIN=mydomain.net -cf push app -p target/*.jar --no-start -cf env app | grep SPRING_PROFILES_ACTIVE || cf set-env app SPRING_PROFILES_ACTIVE cloud -cf env app | grep APPLICATION_DOMAIN || cf set-env app APPLICATION_DOMAIN ${DOMAIN} - -cf services | grep configserver && cf bind app configserver - -cf restart app -cf create-service-broker app user secure http://app.${DOMAIN} - -for f in `cf curl /v2/service_plans | grep '\"guid' | sed -e 's/.*: "//' -e 's/".*//'`; do - cf curl v2/service_plans/$f -X PUT -d '{"public":true}' -done - -cf create-service app free appi -``` - -At which point you have a service called "app" and a service instance called "appi": - -``` -$ cf marketplace -OK - -service plans description -app free Singleton service app -$ cf services -Getting services in org default / space development as admin... -OK - -name service plan bound apps -appi app free -``` - -Your application can define a configuration property -`application.domain` (defaults to "cfapps.io") which will be used to -construct the credentials for any app that binds to your service. Or -it can define the URI directly using -`cloudfoundry.service.definition.metadata.uri`. - -You can change some other basic metadata by setting config properties: - -* `cloudfoundry.service.definition.*` is bound to a - `ServiceDefinition` (defined in spring-boot-cf-service-broker) which - has optional setters for plans and metadata. - -* `cloudfoundry.service.broker.*` is bound to an internal bean. It has - optional setters for "name" (the service name), "description" (user - friendly description) and "prefix" (used to create a unique id from - the name). - -An app which binds to your service will get credentials that contain a -"uri" property linking to your service. A Spring Boot app can bind to -that through the `vcap.services.[service].credentials.uri` environment -property. - -If your service also has a -https://github.com/Netflix/eureka[Eureka core] dependency, and you -can expose it as a Eureka service, then any service which registers -with Eureka will also become a Cloud Foundry service. diff --git a/src/main/ruby/generate_readme.sh b/src/main/ruby/generate_readme.sh new file mode 100755 index 0000000..a6b3611 --- /dev/null +++ b/src/main/ruby/generate_readme.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +base_dir = File.join(File.dirname(__FILE__),'../../..') +src_dir = File.join(base_dir, "/src/main/asciidoc") +require File.join(File.dirname(__FILE__), 'readme.rb') + +options = {} +ARGV.length > 0 and options[:to_file] = ARGV[0] + +SpringCloud::Build.render_file("#{src_dir}/README.adoc", options) diff --git a/src/main/ruby/readme.rb b/src/main/ruby/readme.rb new file mode 100644 index 0000000..348507c --- /dev/null +++ b/src/main/ruby/readme.rb @@ -0,0 +1,51 @@ +module SpringCloud + module Build + + IncludeDirectiveRx = /^\\?include::([^\[]+)\[(.*?)\]$/ + + class << self + + def process_include out, src, target, attrs + unless target.start_with?('/') + target = File.new(File.join(src, target)) + else + target = File.new(target) + end + target.each do |line| + self.process(out, File.dirname(target), line) + end + end + + def process out, src, line + if ((escaped = line.start_with?('\\include::')) || line.start_with?('include::')) && (match = IncludeDirectiveRx.match(line)) + if escaped + out << line[1..-1] + else + self.process_include out, src, match[1], match[2].strip + end + else + out << line + end + end + + def render_file file, options = {} + + srcDir = File.dirname(file) + out = ["// Do not edit this file (go to #{file} instead)",""] + File.new(file).each do |line| + self.process(out, srcDir, line) + end + + unless options[:to_file] + puts out + else + writer = File.new(options[:to_file],'w+') + out.each { |line| writer.write(line) } + end + + end + + end + + end +end