Caching all dependencies in Docker image that has jetty:run in CMD - docker

I'm trying to alter Dockerfile ending with:
ENTRYPOINT ["mvn", "clean", "jetty:run"]
to make it download all the Maven dependencies into the image, not when you run a container.
I added:
RUN mvn dependency:go-offline
It downloaded a lot of dependencies during build, but not all required to call jetty:run.
Because when alter the ENTRYPOINT
ENTRYPOINT ["mvn", "-o", "jetty:run"]
it fails when you run image:
[ERROR] Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:8.1.16.v20140903:run (default-cli) on project LODE: Execution default-cli of goal org.mortbay.jetty:jetty-maven-plugin:8.1.16.v20140903:run failed: Plugin org.mortbay.jetty:jetty-maven-plugin:8.1.16.v20140903 or one of its dependencies could not be resolved: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.codehaus.plexus:plexus-utils:jar:1.1 has not been downloaded from it before. -> [Help 1]
Can you somehow tell go-offline that you want to cache all the dependencies required to run a specific target (in this case jetty:run)? Maybe I can solve my main problem in any other way (it's actually not Docker-specific, but I wanted to show the motivation behind it)?
The project I'm altering is: https://github.com/essepuntato/LODE

Related

Isolate maven jar dependencies that are unavailable from maven central

I am attempting to refactor a maven build process, and I am trying to populate a local maven repository to help with this refactor.
My build depends on obsolete versions of jar files that exist only in a maven repo on my network (not in maven central). Example: org.foo:example:1.7:jar
I have been attempting to run my maven build in a docker image image with the hope that I could identify all of the obsolete components being pulled from my maven repository.
My goal is to explicitly pull down dependencies from my maven repo and then build the application using only maven central as an external repository.
I have a docker file to run the build
FROM maven:3-jdk-8 as build
WORKDIR /build
# This pom.xml file only references maven central.
COPY pom.xml .
# Explicitly download artifacts into /root/.m2/...
RUN mvn dependency:get -Dartifact=org.foo:example:1.7.jar \
-DrepoUrl=https://my.maven.repo
# Run the build making use of the dependencies loaded into the local repo
RUN mvn install
Unfortunately, I see an error: could not resolve dependencies for project ... The following artifacts could not be resolved: org.foo:example:jar:1.7.
I presume there might be some metadata in my local org.foo:example:1.7:pom that has an awareness of its origin repository. I had hoped I could satisfy this dependency by pulling it into my local repository.
I also attempted to add the following flag
RUN mvn install --no-snapshot-updates
After further investigation, I discovered that the downloads in my .m2/repository contained files named _remote.repositories.
Solution: set -Dmaven.legacyLocalRepo=true when running dependency:get
With this flag, the _remote.repositories files are not created.
RUN mvn dependency:get -Dmaven.legacyLocalRepo=true \
-Dartifact=org.foo:example:1.7.jar \
-DrepoUrl=https://my.maven.repo
This question helped to provide a solution: _remote.repositories prevents maven from resolving remote parent

How to fetch maven dependencies for quarkus:dev with dependency:go-offline

I have a set up where a quarkus microservice docker image is based on the docker image of the mavencache. Mavencache image is created by
RUN maven dependency:go-offline
and it fetches a certain amount of the dependencies from the pom.xml. I'd rather say almost all dependencies.
But when the quarkus microservice docker container is being created, it runs:
CMD ["mvn", "quarkus:dev"]
and this command fetches some "Additional dependencies" which takes additional time which I would like to save. That's actually why I've created mavencache base docker image.
Does anyone from the quarkus can help with understanding why mvn quarkus:dev fetches additional maven dependencies instead of fetching them during mvn dependency:go-offline?
UPD1
The following picture describes how I expect the whole caching schema to be working. Despite of the mvn package or mvn quarkus:dev it should NOT fetch any additional dependencies on when some file in the src/ directory.

How to generate runtimeconfig.json for dependency with dotnet publish

I'm building a .Net Core 2.1 library. It has a runnable dependency, which I need to start first.
However dotnet publish generates .runtimeconfig.json only for my library and not for my dependency.
Is there a way to force dotnet to generate .runtimeconfig.json for a dependency?
I have tried:
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateDependencyFile>true</GenerateDependencyFile>
</PropertyGroup>
but it did not help.
As a workaround I can copy my app .runtimeconfig.json to the dependency .runtimeconfig.json but it seems hacky. Is there a better option?
I have prepared the test case, if anyone wants to take a crack at it:
git clone https://github.com/eduard93/gerenate-runtimeconfig.json.git
cd gerenate-runtimeconfig.json
docker build --tag mbs .
docker run --name mbs mbs
docker rm mbs --force
If you remove the comment from Line 24 in the Dockerfile with the copy workaround the image would run successfully.
Without workaround I get this error:
A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the /app/IRISGatewayCore21.runtimeconfig.json file specifying the appropriate framework.

Push JHipster 6.0.1 to Gitlab repository

After having everything ready to deploy, I realized JHipster doesn't have a Dockerfile anymore and the packaging is done with jib. The generated gitlab-ci.yml has a docker-push stage with a command like this:
./mvnw jib:build -Djib.to.image=$IMAGE_TAG -Djib.to.auth.username=gitlab-ci-token -Djib.to.auth.password=$CI_BUILD_TOKEN
but it fails with
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.11:build (default-cli) on project test-project: Obtaining project build output files failed; make sure you have compiled your project before trying to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean compile jib:build"?): /builds/amatos/test-project/target/classes -> [Help 1]
As that failed, I tried to run the command locally like this:
./mvnw jib:build -Djib.to.image=registry.gitlab.com/amatos/test-project:v6.0.1 -Djib.to.auth.username=amatos -Djib.to.auth.password=password
but instead of trying to connect to Gitlab's registry, it tries to connect to registry.hub.docker.com:
[INFO] Retrieving registry credentials for registry.hub.docker.com...
What I would like to know is: how do I set it to connect to Gitlab instead of Docker Hub?
In order to connect to a custom repository, I changed -Djib.to.image to -Dimage and it worked
This is followed by jhipster/generator-jhipster issue 9761 which states:
as the docker-push is done in another stage, there is a missing - target/classes in the previous stage.
It is needed by jib. It should look like:
maven-package:
stage: package
script:
- ./mvnw verify -Pprod -DskipTests -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
paths:
- target/*.jar
- target/classes
expire_in: 1 day
Possibly addressed by PR (merged) 9762, commit 50cc009, which is only in master, not yet referenced by any tag.

How to ask sbt to only fetch dependencies, without compiling?

Is there a way to only download the dependencies but do not compile source.
I am asking because I am trying to build a Docker build environment for my bigger project.
The Idear is that during docker build I clone the project, download all dependencies and then delete the code.
Then use docker run -v to mount the frequently changing code into the docker container and start compiling the project.
Currently I just compile the code during build and then compile it again on run. The problem ist that when a dependencie changes I have to build from scratch and that takes a long time.
Run sbt's update command. Dependencies will be resolved and retrieved.

Resources