I am new to docker and I need help to figure this out. I have a project with sub projects and I am creating a docker image for one of the sub project. My end goal is to execute the gradle task from the docker container. Is this possible?
Here is what I am trying to achieve. I want to call a task defined in the build.gradle from inside a docker file Here is the task which I want to execute and the task docker inside my build.gradle
task mytestTask(type: JUnitHarnessRunnerTask) {
//some task that needs to be executed
}
docker {
String version = project.getVersion()
name "${componentDockerImageName}:${version}"
dockerfile file('Dockerfile')
buildArgs(['ARTIFACT_NAME' : 'my-tests-module',
'ARTIFACT_VERSION': version,
'ARTIFACT_FILE' : "my-tests-module-" + version + ".jar",
'BASE_IMAGE' : componentDockerBaseImage,
'COMPONENT' : 'my-tests-module'])
files project.libsDir
dependsOn tasks.build
}
//Here is my docker file
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
USER root
RUN yum --assumeyes install unzip
WORKDIR /gradle
RUN curl -L https://services.gradle.org/distributions/gradle-5.6.4-bin.zip -o gradle-5.6.4-bin.zip
RUN unzip gradle-5.6.4-bin.zip
ENV GRADLE_HOME=/gradle/gradle-5.6.4
ENV PATH=$PATH:${GRADLE_HOME}/bin
ARG ARTIFACT_FILE
ENV MY_COMPONENT="${COMPONENT}"
ENV MY_COMPONENT_ROOT="${MY_APP_ROOT}/${COMPONENT}"
ENV MY_ARTIFACT="${MY_COMPONENT_ROOT}/${ARTIFACT_FILE}"
COPY --chown=admin:mydir ${ARTIFACT_FILE} ${MY_ARTIFACT}
USER admin
WORKDIR /tmp
RUN gradle --version
RUN gradle my-tests-module:mytestTask
This is the error I am getting when I build ./gradlew my-tests-module:Docker Project 'my-tests-module' not found in root project 'tmp'.
I am able to see gradle --version when I do RUN gradle tasks --all , it is not listing out all the tasks which I have given inside my build.gradle
How can I get the docker file to run my gradle task. How do I copy all the necessary files to run the gradle task.right now, I am only copying the jar. I cannot share the base image details but everything works and executes till gradle --version command and it correctly displays the gradle version.