Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
Added Gradle support (#11)
Browse files Browse the repository at this point in the history
now we also support Gradle projects out of the box
also minor fixes were applied

updated docs
fixed missing env passing to stub runner containing repo with jars
updated scripts used to remove routes
  • Loading branch information
marcingrzejszczak authored Oct 26, 2016
1 parent f4de601 commit f9091bc
Show file tree
Hide file tree
Showing 38 changed files with 891 additions and 173 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ hs_err_pid*
build
*.iml
.DS_Store
*.log
109 changes: 94 additions & 15 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ This repo contains an *opinionated pipeline* to deploy a Spring Cloud based micr
We've taken the following opinionated decisions:

- usage of Spring Cloud, Spring Cloud Contract Stub Runner and Spring Cloud Eureka
- usage of Maven Wrapper (we're working on Gradle)
- artifacts deployment by `./mvnw clean deploy`
- application deployment to Cloud Foundry
- running smoke tests on a deployed app via the `smoke` Maven profile
- running e2e tests on a deployed app via the `e2e` Maven profile
- For Maven:
* usage of Maven Wrapper
* artifacts deployment by `./mvnw clean deploy`
* `stubrunner.ids` property to retrieve list of collaborators for which stubs should be downloaded
* running smoke tests on a deployed app via the `smoke` Maven profile
* running end to end tests on a deployed app via the `e2e` Maven profile
- For Gradle (in the `github-analytics` application check the `gradle/pipeline.gradle` file):
* usage of Gradlew Wrapper
* `deploy` task for artifacts deployment
* running smoke tests on a deployed app via the `smoke` task
* running end to end tests on a deployed app via the `e2e` task
* `groupId` task to retrieve group id
* `artifactId` task to retrieve artifact id
* `currentVersion` task to retrieve the current version
* `stubIds` task to retrieve list of collaborators for which stubs should be downloaded

This is the initial approach that can be easily changed since all the core
deployment logic is done in a form of Bash scripts.
Expand Down Expand Up @@ -264,8 +275,8 @@ In this step we're generating a version of the pipeline and then we're publishin
- a fat jar of the application
- a Spring Cloud Contract jar containing stubs of the application

During this phase we're executing a `Maven` build using Maven Wrapper, with unit and integration tests.
We're also *tagging* the repository with `dev/${version}` format. That way in each
During this phase we're executing a `Maven` build using Maven Wrapper or a `Gradle` build using Gradle Wrapper
, with unit and integration tests. We're also *tagging* the repository with `dev/${version}` format. That way in each
subsequent step of the pipeline we're able to retrieve the tagged version. Also we know
exactly which version of the pipeline corresponds to which Git hash.

Expand All @@ -284,7 +295,7 @@ the application with `smoke` Spring profile on which you can stub out all HTTP c
a mocked response
- if the application is using a database then it gets upgraded at this point via Flyway, Liquibase
or any other tool once the application gets started
- from the project's Maven build we're extracting `stubrunner.ids` property that contains
- from the project's Maven or Gradle build we're extracting `stubrunner.ids` property that contains
all the `groupId:artifactId:version:classifier` notation of dependant projects for which
the stubs should be downloaded.
- then we're uploading `Stub Runner Boot` and pass the extracted `stubrunner.ids` to it. That way
Expand Down Expand Up @@ -637,11 +648,22 @@ Not really. This is an `opinionated pipeline` that's why we took some
opinionated decisions like:

- usage of Spring Cloud, Spring Cloud Contract Stub Runner and Spring Cloud Eureka
- usage of Maven Wrapper
- artifacts deployment by `./mvnw clean deploy`
- application deployment to Cloud Foundry
- running smoke tests on a deployed app via the `smoke` Maven profile
- running e2e tests on a deployed app via the `e2e` Maven profile
- For Maven:
* usage of Maven Wrapper
* artifacts deployment by `./mvnw clean deploy`
* `stubrunner.ids` property to retrieve list of collaborators for which stubs should be downloaded
* running smoke tests on a deployed app via the `smoke` Maven profile
* running end to end tests on a deployed app via the `e2e` Maven profile
- For Gradle (in the `github-analytics` application check the `gradle/pipeline.gradle` file):
* usage of Gradlew Wrapper
* `deploy` task for artifacts deployment
* running smoke tests on a deployed app via the `smoke` task
* running end to end tests on a deployed app via the `e2e` task
* `groupId` task to retrieve group id
* `artifactId` task to retrieve artifact id
* `currentVersion` task to retrieve the current version
* `stubIds` task to retrieve list of collaborators for which stubs should be downloaded

This is the initial approach that can be easily changed in the future.

Expand All @@ -664,6 +686,9 @@ cf stop github-eureka
cf stop stubrunner
----

You can also execute `kill_all_pcfdev_apps.sh` that will remove all demo-related apps
deployed to PCF dev.

==== The rollback step fails due to missing JAR ?!

You must have pushed some tags and have removed the Artifactory volume that
Expand All @@ -689,6 +714,11 @@ Don't worry... most likely you've just forgotten to click the `play` button to
unpause the pipeline. Click to the top left, expand the list of pipelines and click
the `play` button next to `github-webhook`.

Another problem that might occur is that you need to have the `version` branch.
Concourse will wait for the `version` branch to appear in your repo. So in order for
the pipeline to start ensure that when doing some git operations you haven't
forgotten to create / copy the `version` branch too.

==== The route is already in use

If you play around with Jenkins / Concourse you might end up with the routes occupied
Expand Down Expand Up @@ -732,6 +762,41 @@ All in all there are the following projects taking part in the whole `microservi
- https://github.com/spring-cloud-samples/github-eureka[Eureka] - simple Eureka Server. This is an infrastructure application.
- https://github.com/spring-cloud-samples/github-analytics-stub-runner-boot[Github Analytics Stub Runner Boot] - Stub Runner Boot server to be used for tests with Github Analytics. Uses Eureka and Messaging. This is an infrastructure application.

=== Project setup

[source,bash]
----
.
├── jobs
│   ├── jenkins_pipeline_empty.groovy
│   ├── jenkins_pipeline_jenkinsfile_empty.groovy
│   ├── jenkins_pipeline_sample.groovy
│   └── jenkins_pipeline_sample_view.groovy
├── seed
│   ├── gradle.properties
│   ├── init.groovy
│   ├── jenkins_pipeline.groovy
│   └── settings.xml
└── src
├── main
   └── test
----

In the `jobs` folder you have all the seed jobs that will generate pipelines.

- `jenkins_pipeline_empty.groovy` - is a template of a pipeline with empty steps using the Jenkins Job DSL plugin
- `jenkins_pipeline_jenkinsfile_empty.groovy` - is a template of a pipeline with empty steps using the Pipeline plugin
- `jenkins_pipeline_sample.groovy` - is an opinionated implementation using the Jenkins Job DSL plugin
- `jenkins_pipeline_sample_view.groovy` - builds the views for the pipelines

In the `seed` folder you have the `init.groovy` file which is executed when Jenkins starts.
That way we can configure most of Jenkins options for you (adding credentials, JDK etc.).
`jenkins_pipeline.groovy` contains logic to build a seed job (that way you don't have to even click that
job - we generate it for you).

In the `src` folder you have production and test classes needed for you to build your own pipeline.
Currently we have tests only cause the whole logic resides in the `jenkins_pipeline_sample` file.

=== Step by step

If you want to just run the demo as far as possible using PCF Dev and Docker Compose
Expand Down Expand Up @@ -1221,11 +1286,22 @@ Not really. This is an `opinionated pipeline` that's why we took some
opinionated decisions like:

- usage of Spring Cloud, Spring Cloud Contract Stub Runner and Spring Cloud Eureka
- usage of Maven Wrapper
- artifacts deployment by `./mvnw clean deploy`
- application deployment to Cloud Foundry
- running smoke tests on a deployed app via the `smoke` Maven profile
- running e2e tests on a deployed app via the `e2e` Maven profile
- For Maven:
* usage of Maven Wrapper
* artifacts deployment by `./mvnw clean deploy`
* `stubrunner.ids` property to retrieve list of collaborators for which stubs should be downloaded
* running smoke tests on a deployed app via the `smoke` Maven profile
* running end to end tests on a deployed app via the `e2e` Maven profile
- For Gradle (in the `github-analytics` application check the `gradle/pipeline.gradle` file):
* usage of Gradlew Wrapper
* `deploy` task for artifacts deployment
* running smoke tests on a deployed app via the `smoke` task
* running end to end tests on a deployed app via the `e2e` task
* `groupId` task to retrieve group id
* `artifactId` task to retrieve artifact id
* `currentVersion` task to retrieve the current version
* `stubIds` task to retrieve list of collaborators for which stubs should be downloaded

This is the initial approach that can be easily changed in the future.

Expand All @@ -1248,6 +1324,9 @@ cf stop github-eureka
cf stop stubrunner
----

You can also execute `kill_all_pcfdev_apps.sh` that will remove all demo-related apps
deployed to PCF dev.

==== The rollback step fails due to missing JAR ?!

[[jenkins_tags]] You must have pushed some tags and have removed the Artifactory volume that
Expand Down
21 changes: 18 additions & 3 deletions common/src/main/bash/build_and_upload.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/bin/bash
#!/bin/bash +x

set -e

source pipeline.sh || echo "No pipeline.sh found"

./mvnw versions:set -DnewVersion=${PIPELINE_VERSION} ${MAVEN_ARGS}
./mvnw clean verify deploy -Ddistribution.management.release.id=${M2_SETTINGS_REPO_ID} -Ddistribution.management.release.url=${REPO_WITH_JARS} ${MAVEN_ARGS}
if [[ "${PROJECT_TYPE}" == "MAVEN" ]]; then
./mvnw versions:set -DnewVersion=${PIPELINE_VERSION} ${MAVEN_ARGS}
if [[ "${CI}" == "CONCOURSE" ]]; then
./mvnw clean verify deploy -Ddistribution.management.release.id=${M2_SETTINGS_REPO_ID} -Ddistribution.management.release.url=${REPO_WITH_JARS} ${MAVEN_ARGS} || ( $( printTestResults ) && return 1)
else
./mvnw clean verify deploy -Ddistribution.management.release.id=${M2_SETTINGS_REPO_ID} -Ddistribution.management.release.url=${REPO_WITH_JARS} ${MAVEN_ARGS}
fi
elif [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
if [[ "${CI}" == "CONCOURSE" ]]; then
./gradlew clean build deploy -PnewVersion=${PIPELINE_VERSION} -DM2_LOCAL=${M2_LOCAL} -DREPO_WITH_JARS=${REPO_WITH_JARS} --stacktrace || ( $( printTestResults ) && return 1)
else
./gradlew clean build deploy -PnewVersion=${PIPELINE_VERSION} -DM2_LOCAL=${M2_LOCAL} -DREPO_WITH_JARS=${REPO_WITH_JARS} --stacktrace
fi
else
echo "Unsupported project build tool"
return 1
fi
Loading

0 comments on commit f9091bc

Please sign in to comment.