From 8e7726f465ff61eea94b8e942aae73a0b7ce6593 Mon Sep 17 00:00:00 2001
From: buildmaster /spring-cloud-contract/build folder (it’s useful for debugging
purposes).
It’s enough for you to mount your contracts, pass the environment variables and the image will:
The Docker image requires some environment variables to point to -your running application, to the Artifact manager instance etc.
PROJECT_GROUP - your project’s group id. Defaults to com.example.PROJECT_VERSION - your project’s version. Defaults to 0.0.1-SNAPSHOTPROJECT_NAME - artifact id. Defaults to exampleREPO_WITH_BINARIES_URL - URL of your Artifact Manager. Defaults to http://localhost:8081/artifactory/libs-release-local
-which is the default URL of Artifactory running locallyREPO_WITH_BINARIES_USERNAME - (optional) username when the Artifact Manager is securedREPO_WITH_BINARIES_PASSWORD - (optional) password when the Artifact Manager is securedPUBLISH_ARTIFACTS - if set to true then will publish artifact to binary storage. Defaults to true.These environment variables are used when tests are executed:
APPLICATION_BASE_URL - url against which tests should be executed.
+your running application, to the Artifact manager instance etc.PROJECT_GROUP - your project’s group id. Defaults to com.examplePROJECT_VERSION - your project’s version. Defaults to 0.0.1-SNAPSHOTPROJECT_NAME - artifact id. Defaults to exampleREPO_WITH_BINARIES_URL - URL of your Artifact Manager. Defaults to http://localhost:8081/artifactory/libs-release-local
+which is the default URL of Artifactory running locallyREPO_WITH_BINARIES_USERNAME - (optional) username when the Artifact Manager is securedREPO_WITH_BINARIES_PASSWORD - (optional) password when the Artifact Manager is securedPUBLISH_ARTIFACTS - if set to true then will publish artifact to binary storage. Defaults to true.These environment variables are used when contracts lay in an external repository. To enable
+this feature you must set the EXTERNAL_CONTRACTS_ARTIFACT_ID environment variable.
EXTERNAL_CONTRACTS_GROUP_ID - group id of the project with contracts. Defaults to com.exampleEXTERNAL_CONTRACTS_ARTIFACT_ID- artifact id of the project with contracts.EXTERNAL_CONTRACTS_CLASSIFIER- classifier of the project with contracts. Empty by defaultEXTERNAL_CONTRACTS_VERSION - version of the project with contracts. Defaults to +, equivalent to picking the latestEXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL - URL of your Artifact Manager. Defaults to value of REPO_WITH_BINARIES_URL env var.
+If that’s not set, defaults to http://localhost:8081/artifactory/libs-release-local
+which is the default URL of Artifactory running locallyEXTERNAL_CONTRACTS_PATH - path to contracts for the given project, inside the project with contracts.
+Defaults to slash separated EXTERNAL_CONTRACTS_GROUP_ID concatenated with / and EXTERNAL_CONTRACTS_ARTIFACT_ID. E.g.
+for group id foo.bar and artifact id baz, would result in foo/bar/baz contracts path.EXTERNAL_CONTRACTS_WORK_OFFLINE - if set to true then will retrieve artifact with contracts
+from the container’s .m2. Mount your local .m2 as a volume available at the container’s /root/.m2 path.
+You must not set both EXTERNAL_CONTRACTS_WORK_OFFLINE and EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL.These environment variables are used when tests are executed:
APPLICATION_BASE_URL - url against which tests should be executed.
Remember that it has to be accessible from the Docker container (e.g. localhost
will not work)APPLICATION_USERNAME - (optional) username for basic authentication to your applicationAPPLICATION_PASSWORD - (optional) password for basic authentication to your applicationLet’s take a look at a simple MVC application
$ git clone https://github.com/spring-cloud-samples/spring-cloud-contract-nodejs
$ cd bookstoreThe contracts are available under /contracts folder.
Since we want to run tests, we could just execute:
$ npm testhowever, for learning purposes, let’s split it into pieces:
# Stop docker infra (nodejs, artifactory) diff --git a/single/spring-cloud-contract.html b/single/spring-cloud-contract.html index d423bce110..6c769e577c 100644 --- a/single/spring-cloud-contract.html +++ b/single/spring-cloud-contract.html @@ -1747,8 +1747,15 @@ The output from running the tests will be available under/spring-cloud-contract/buildfolder (it’s useful for debugging purposes).It’s enough for you to mount your contracts, pass the environment variables and the image will:
- generate the contract tests
- execute the tests against the provided URL
- generate the WireMock stubs
- (optional - turned on by default) publish the stubs to a Artifact Manager
The Docker image requires some environment variables to point to -your running application, to the Artifact manager instance etc.
PROJECT_GROUP- your project’s group id. Defaults tocom.example.PROJECT_VERSION- your project’s version. Defaults to0.0.1-SNAPSHOTPROJECT_NAME- artifact id. Defaults toexampleREPO_WITH_BINARIES_URL- URL of your Artifact Manager. Defaults tohttp://localhost:8081/artifactory/libs-release-local-which is the default URL of Artifactory running locallyREPO_WITH_BINARIES_USERNAME- (optional) username when the Artifact Manager is securedREPO_WITH_BINARIES_PASSWORD- (optional) password when the Artifact Manager is securedPUBLISH_ARTIFACTS- if set totruethen will publish artifact to binary storage. Defaults totrue.These environment variables are used when tests are executed:
APPLICATION_BASE_URL- url against which tests should be executed. +your running application, to the Artifact manager instance etc.
PROJECT_GROUP- your project’s group id. Defaults tocom.examplePROJECT_VERSION- your project’s version. Defaults to0.0.1-SNAPSHOTPROJECT_NAME- artifact id. Defaults toexampleREPO_WITH_BINARIES_URL- URL of your Artifact Manager. Defaults tohttp://localhost:8081/artifactory/libs-release-local+which is the default URL of Artifactory running locallyREPO_WITH_BINARIES_USERNAME- (optional) username when the Artifact Manager is securedREPO_WITH_BINARIES_PASSWORD- (optional) password when the Artifact Manager is securedPUBLISH_ARTIFACTS- if set totruethen will publish artifact to binary storage. Defaults totrue.These environment variables are used when contracts lay in an external repository. To enable +this feature you must set the
EXTERNAL_CONTRACTS_ARTIFACT_IDenvironment variable.
EXTERNAL_CONTRACTS_GROUP_ID- group id of the project with contracts. Defaults tocom.exampleEXTERNAL_CONTRACTS_ARTIFACT_ID- artifact id of the project with contracts.EXTERNAL_CONTRACTS_CLASSIFIER- classifier of the project with contracts. Empty by defaultEXTERNAL_CONTRACTS_VERSION- version of the project with contracts. Defaults to+, equivalent to picking the latestEXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL- URL of your Artifact Manager. Defaults to value ofREPO_WITH_BINARIES_URLenv var. +If that’s not set, defaults tohttp://localhost:8081/artifactory/libs-release-local+which is the default URL of Artifactory running locallyEXTERNAL_CONTRACTS_PATH- path to contracts for the given project, inside the project with contracts. +Defaults to slash separatedEXTERNAL_CONTRACTS_GROUP_IDconcatenated with/andEXTERNAL_CONTRACTS_ARTIFACT_ID. E.g. +for group idfoo.barand artifact idbaz, would result infoo/bar/bazcontracts path.EXTERNAL_CONTRACTS_WORK_OFFLINE- if set totruethen will retrieve artifact with contracts +from the container’s.m2. Mount your local.m2as a volume available at the container’s/root/.m2path. +You must not set bothEXTERNAL_CONTRACTS_WORK_OFFLINEandEXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL.These environment variables are used when tests are executed:
APPLICATION_BASE_URL- url against which tests should be executed. Remember that it has to be accessible from the Docker container (e.g.localhostwill not work)APPLICATION_USERNAME- (optional) username for basic authentication to your applicationAPPLICATION_PASSWORD- (optional) password for basic authentication to your applicationLet’s take a look at a simple MVC application
$ git clone https://github.com/spring-cloud-samples/spring-cloud-contract-nodejs $ cd bookstoreThe contracts are available under
/contractsfolder.Since we want to run tests, we could just execute:
$ npm testhowever, for learning purposes, let’s split it into pieces:
# Stop docker infra (nodejs, artifactory) diff --git a/spring-cloud-contract.xml b/spring-cloud-contract.xml index 4b3dbc2f0a..47278c30f4 100644 --- a/spring-cloud-contract.xml +++ b/spring-cloud-contract.xml @@ -3027,7 +3027,7 @@ purposes). your running application, to the Artifact manager instance etc.+ - + PROJECT_GROUP - your project’s group id. Defaults tocom.example .PROJECT_GROUP - your project’s group id. Defaults tocom.example @@ -3049,6 +3049,37 @@ which is the default URL of Artif PROJECT_VERSION - your project’s version. Defaults to0.0.1-SNAPSHOT PUBLISH_ARTIFACTS - if set totrue then will publish artifact to binary storage. Defaults totrue .These environment variables are used when contracts lay in an external repository. To enable +this feature you must set the +EXTERNAL_CONTRACTS_ARTIFACT_ID environment variable.+ + ++ EXTERNAL_CONTRACTS_GROUP_ID - group id of the project with contracts. Defaults tocom.example + ++ EXTERNAL_CONTRACTS_ARTIFACT_ID - artifact id of the project with contracts.+ ++ EXTERNAL_CONTRACTS_CLASSIFIER - classifier of the project with contracts. Empty by default+ ++ EXTERNAL_CONTRACTS_VERSION - version of the project with contracts. Defaults to+ , equivalent to picking the latest+ ++ EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL - URL of your Artifact Manager. Defaults to value ofREPO_WITH_BINARIES_URL env var. +If that’s not set, defaults tohttp://localhost:8081/artifactory/libs-release-local +which is the default URL of Artifactory running locally+ ++ EXTERNAL_CONTRACTS_PATH - path to contracts for the given project, inside the project with contracts. +Defaults to slash separatedEXTERNAL_CONTRACTS_GROUP_ID concatenated with/ andEXTERNAL_CONTRACTS_ARTIFACT_ID . E.g. +for group idfoo.bar and artifact idbaz , would result infoo/bar/baz contracts path.+ ++ EXTERNAL_CONTRACTS_WORK_OFFLINE - if set totrue then will retrieve artifact with contracts +from the container’s.m2 . Mount your local.m2 as a volume available at the container’s/root/.m2 path. +You must not set bothEXTERNAL_CONTRACTS_WORK_OFFLINE andEXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL .These environment variables are used when tests are executed: