Git Stub Downloader#596
Merged
marcingrzejszczak merged 12 commits intomasterfrom Mar 31, 2018
Merged
Conversation
| <dependency> | ||
| <groupId>org.eclipse.jgit</groupId> | ||
| <artifactId>org.eclipse.jgit</artifactId> | ||
| <version>4.6.0.201612231935-r</version> |
Contributor
Author
There was a problem hiding this comment.
parametrize
Codecov Report
@@ Coverage Diff @@
## master #596 +/- ##
============================================
+ Coverage 60.88% 60.98% +0.09%
- Complexity 1760 1826 +66
============================================
Files 203 210 +7
Lines 7033 7507 +474
Branches 1063 1121 +58
============================================
+ Hits 4282 4578 +296
- Misses 2154 2291 +137
- Partials 597 638 +41
Continue to review full report at Codecov.
|
when stubsMode is set to LOCAL or REMOTE, and repository Root starts with git:// we can clone the provided git repository, and search for the folder with stubs for the given artifact. So if the git repo has a folder structure of groupid/artifactid/version (where group id is either dot or slash separated), then we will provide a path to that repository for the stub runner to harvest the stubs part of #580
with this change we're making SDB extend PR. The user already has to register SDB in META-INF/spring.factories , so we won't have to ask the user to do it again for PR. We also introduce a map of properties passed via `stubrunner.properties` system propery or `STUBRUNNER_PROPERTIES` env var or just directly via Spring mechanism or Maven / Gradle plugins. That way one will be able to pass arbitrary properties to any SDB mechanism. For Git Stub Downloader, this change also introduces passing of git credentials and git branch to check out. Tested against https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/git_downloader
5b82209 to
53dad52
Compare
still to add gradle and docs and tests for maven, gradle and maybe one standalone (extension of the existing one)
- added more debugging messages - if folder with contracts has a subfolder called `contracts`, we will pick contracts from the subfolder - extracted a PROTOCOL field for GitStubDownloader - GitStubDownloader is public but can't be extended - preloads TemporaryFileStorage class wherever it's used cause, upon shutdown hook execution, exceptions are thrown that the class is not found
|
I need to configure a CredentialsProvider to provide username and password for downloading from a private Git repo that requires https. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description from the docs
Do I need a Binary Storage? Can't I use Git?
In the polyglot world, there are languages that don't use binary storages like
Artifactory or Nexus. Starting from Spring Cloud Contract version 2.0.0 we provide
mechanisms to store contracts and stubs in a SCM repository. Currently the
only supported SCM is Git.
The repository would have to the following setup
(which you can checkout here https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/2.0.x/contracts_git/):
. └── META-INF └── com.example └── beer-api-producer-git └── 0.0.1-SNAPSHOT ├── contracts │ └── beer-api-consumer │ ├── messaging │ │ ├── shouldSendAcceptedVerification.groovy │ │ └── shouldSendRejectedVerification.groovy │ └── rest │ ├── shouldGrantABeerIfOldEnough.groovy │ └── shouldRejectABeerIfTooYoung.groovy └── mappings └── beer-api-consumer └── rest ├── shouldGrantABeerIfOldEnough.json └── shouldRejectABeerIfTooYoung.jsonUnder
META-INFfolder:groupId(e.g.com.example)artifactId(e.g.beer-api-producer-git)0.0.1-SNAPSHOT)**
contracts- the good practice is to store the contracts required by eachconsumer in the folder with the consumer name (e.g.
beer-api-consumer). That way youcan use the
stubs-per-consumerfeature. Further directory structure is arbitrary.**
mappings- in this folder the Maven / Gradle Spring Cloud Contract plugins will pushthe stub server mappings. On the consumer side, Stub Runner will scan this folder
to start stub servers with stub definitions. The folder structure will be a copy
of the one created in the
contractssubfolder.Protocol convention
In order to control the type and location of the source of contracts (whether it's
a binary storage or an SCM repository), you can use the protocol in the URL of
the repository. Spring Cloud Contract iterates over registered protocol resolvers
and tries to fetch the contracts (via a plugin) or stubs (via Stub Runner).
For the SCM functionality, currently, we support the Git repository. To use it,
in the property, where the repository URL needs to be placed you just have to prefix
the connection URL with
git://. Here you can find a couple of examples:Producer
For the producer, to use the SCM approach, we can reuse the same mechanism we use for external contracts. We route Spring Cloud Contract to use the SCM implementation via the URL that contains the
git://protocol.IMPORTANT: You have to manually add the
pushStubsToScmgoal in Maven or execute (bind) thepushStubsToScmtask in Gradle. We don't push stubs tooriginof your git repository out of the box..Maven
.Gradle
contracts { // We want to pick contracts from a Git repository contractDependency { stringNotation = "${project.group}:${project.name}:${project.version}" } /* We reuse the contract dependency section to set up the path to the folder that contains the contract definitions. In our case the path will be /groupId/artifactId/version/contracts */ contractRepository { repositoryUrl = "git://https://github.com/spring-cloud-samples/spring-cloud-contract-nodejs-contracts-git.git" } // The mode can't be classpath contractsMode = "REMOTE" // Base class mappings etc. } /* In this scenario we want to publish stubs to SCM whenever the `publish` task is executed */ publish.dependsOn("publishStubsToScm")With such a setup:
META-INF/groupId/artifactId/version/contractsfolderto find contracts. E.g. for
com.example:foo:1.0.0the path would beMETA-INF/com.example/foo/1.0.0/contractsoriginConsumer
On the consumer side when passing the
repositoryRootparameter,either from the
@AutoConfigureStubRunnerannotation, theJUnit rule or properties, it's enough to pass the URL of the
SCM repository, prefixed with the protocol. For example
With such a setup:
META-INF/groupId/artifactId/version/folderto find stub definitions and contracts. E.g. for
com.example:foo:1.0.0the path would beMETA-INF/com.example/foo/1.0.0/Using the SCM Stub Downloader
Whenever the
repositoryRootstarts with a SCM protocol (currently we support onlygit://), the stub downloader will try to clone the repository and use it as a source of contracts to generate tests or stubs.Either via environment variables, system properties, properties set inside the plugin or contracts repository configuration you can tweak the downloader's behaviour. Below you can find the list of properties
Technical issues
The approach
when stubsMode is set to
LOCALorREMOTE, andrepositoryRootstarts withgit://we can clone the provided git repository, and search for the folder with stubs for the given artifact. So if the git repo has a folder structure ofgroupid/artifactid/version(where group id is either dot or slash separated), then we will provide a path to that repository for the stub runner to harvest the stubsWhat's done?
ContractProjectUpdaterthat updates the project containing contracts from SCM. ATM supports only gitResourceResolverthat retrieves theProtocolResolvers. It does it viaspring.factoriesentries containingStubDownloaderBuilder.SDPextendsProtocolResovler.StubRunner.propertiesmap, that will contain any properties that will be later used by anyStubDownloaderimplementationsPUBLISH_STUBS_TO_SCMenv var for Docker, so thatpublishStubsToScmtask gets calledBreaking:
StubDownloaderBuilderextendsProtocolResovler. By default theProtocolResolvermethods returnnull.stubRunnerOptions.stubRepositoryRootis aResourcenot aStringgenerateWireMockClientStubsGradle task got removedcontracts, we will pick contracts from the subfolderfixes #580