Fixes #1672: allow users to specify a custom build.gradle when using standalone docker image (#1695)

* pre-create directories for mounting and use /spring/cloud-contract and /contract and /spring-cloud-contract

* add documentation on how to run a customized gradle build to create tests
This commit is contained in:
Bastian Doetsch
2021-08-10 15:59:32 +02:00
committed by GitHub
parent 9b147dd991
commit 2f37b46dde
4 changed files with 39 additions and 13 deletions

View File

@@ -16,21 +16,29 @@ RUN useradd -u1000 -m scc
COPY sdkman/ /usr/local/bin/
RUN chmod +x /usr/local/bin/sdkman-wrapper.sh
# provide output & contract directories and change owner to scc
RUN mkdir -p /contracts
RUN mkdir -p /spring-cloud-contract-output
RUN mkdir -p /spring-cloud-contract
RUN chown -R scc:scc /contracts
RUN chown -R scc:scc /spring-cloud-contract-output /spring-cloud-contract
RUN chown -R scc:scc /spring-cloud-contract
USER scc
RUN curl -s https://get.sdkman.io/ | bash
COPY --chown=scc sdkman.config /home/scc/.sdkman/etc/config
COPY --chown=scc:scc sdkman.config /home/scc/.sdkman/etc/config
RUN bash -c "source /home/scc/.sdkman/bin/sdkman-init.sh"
RUN bash -c "sdkman-wrapper.sh install java ${SDKMAN_JAVA_INSTALLATION}"
ENV JAVA_HOME /home/scc/.sdkman/candidates/java/current/
ENV PATH "${PATH}:${JAVA_HOME}/bin"
# Spring Cloud Contract
COPY --chown=scc project /home/scc/spring-cloud-contract/
WORKDIR /home/scc/spring-cloud-contract/
COPY --chown=scc:scc project /spring-cloud-contract/
WORKDIR /spring-cloud-contract/
# Let's copy the downloaded deps to .m2 and the gradle cache
COPY --chown=scc target/maven_dependencies /home/scc/.m2/repository/
COPY --chown=scc target/gradle_dependencies /home/scc/.gradle/
COPY --chown=scc:scc target/maven_dependencies /home/scc/.m2/repository/
COPY --chown=scc:scc target/gradle_dependencies /home/scc/.gradle/
# Let's download gradle wrapper if for some reason it hasn't been downloaded
RUN ./gradlew clean resolveDependencies build --stacktrace -x copyOutput || echo "Expected to fail"

View File

@@ -2,6 +2,7 @@
## Developer tips
### Environment variables
In order to use a new environment variable inside the Gradle script, you need to add it to the `envVars` map together with a description and a default value. Otherwise, any attempt to resolve such an environment variable will lead to an exception being thrown.
If you're referencing any environment variables from inside the Java code please follow the following convention.
@@ -14,4 +15,10 @@ If you're referencing any environment variables from inside the Java code please
String envVar;
```
If you provide Javadocs, we will automatically parse any `@Value` annotated fields and build a table of environment variables with description and default values.
If you provide Javadocs, we will automatically parse any `@Value` annotated fields and build a table of environment variables with description and default values.
### Customizing the gradle build
You can provide a customized `gradle.build` to be run in the container by mounting your customized build file as a volume when running the container:
`docker run -v <absolute-path-of-your-custom-file>:/spring-cloud-contract/build.gradle springcloud/spring-cloud-contract:<version>`