-
Notifications
You must be signed in to change notification settings - Fork 435
Git Stub Downloader #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git Stub Downloader #596
Conversation
pom.xml
Outdated
<dependency> | ||
<groupId>org.eclipse.jgit</groupId> | ||
<artifactId>org.eclipse.jgit</artifactId> | ||
<version>4.6.0.201612231935-r</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.json
Under
META-INF
folder: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-consumer
feature. 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
contracts
subfolder.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
pushStubsToScm
goal in Maven or execute (bind) thepushStubsToScm
task in Gradle. We don't push stubs toorigin
of your git repository out of the box..Maven
.Gradle
With such a setup:
META-INF/groupId/artifactId/version/contracts
folderto find contracts. E.g. for
com.example:foo:1.0.0
the path would beMETA-INF/com.example/foo/1.0.0/contracts
origin
Consumer
On the consumer side when passing the
repositoryRoot
parameter,either from the
@AutoConfigureStubRunner
annotation, 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.0
the path would beMETA-INF/com.example/foo/1.0.0/
Using the SCM Stub Downloader
Whenever the
repositoryRoot
starts 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
LOCAL
orREMOTE
, andrepositoryRoot
starts 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?
ContractProjectUpdater
that updates the project containing contracts from SCM. ATM supports only gitResourceResolver
that retrieves theProtocolResolver
s. It does it viaspring.factories
entries containingStubDownloaderBuilder
.SDP
extendsProtocolResovler
.StubRunner.properties
map, that will contain any properties that will be later used by anyStubDownloader
implementationsPUBLISH_STUBS_TO_SCM
env var for Docker, so thatpublishStubsToScm
task gets calledBreaking:
StubDownloaderBuilder
extendsProtocolResovler
. By default theProtocolResolver
methods returnnull
.stubRunnerOptions.stubRepositoryRoot
is aResource
not aString
generateWireMockClientStubs
Gradle task got removedcontracts
, we will pick contracts from the subfolderfixes #580