Unable to run Maven Commands on Docker as Non-root - java

I am building my project on docker (using docker-maven) and need to execute it as non-root.
From the official documentation, it seems that running maven as non-root is supported (https://github.com/carlossg/docker-maven#running-as-non-root).
So I run the following:
sudo docker run -v "$PWD":/var/maven -w /var/maven -ti -u 1000 -e MAVEN_CONFIG=/var/maven maven mvn package -Duser.home=/var/maven
where $PWD is my project root directory.
However, I always get permission related issue such as
Error while storing the mojo status: /var/maven/mymodule/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst (Permission denied)
or unable to delete some files if I run mvn clean package instead.
How do I run the command as non-root properly?

Related

Unable to run 'RUN ./mvnw dependency:go-offline -B' when building docker image from "openjdk:8-jdk-alpine" for Spring Boot app

So I am trying to run a spring boot app with maven wrapper inside the docker container. Here is my Docker file:
### Stage 1: Build the application
FROM openjdk:8-jdk-alpine as build
RUN mkdir -p /app
#Set the current working directory inside the image
WORKDIR /app
#copy maven executable to the image
COPY mvnw .
COPY .mvn .mvn
#Copy the pom.xml file
COPY pom.xml .
#Build all the dependencies in preparation to go offline
#This is a separate step so the dependencies will be cached unless
#the pom.xml file has changed
RUN ./mvnw dependency:go-offline -B
#Copy the project source
COPY src src
#Package the application
RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
I have this error:
Step 7/16 : RUN ./mvnw dependency:go-offline -B
---> Running in 642a32f86392
/bin/sh: ./mvnw: not found
ERROR: Service 'app-server' failed to build: The command '/bin/sh -c ./mvnw dependency:go-offline -B' returned a non-zero code: 127
I am working with windows 10 pro. Please I need your help
Maybe a duplicate of Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app
Can you check the line endings of the mvnw shell script?
You could fix it by adding this before executing the mvnw command:
RUN dos2unix mvnw
Alternatively, if the file is in git, you can also fix it by adding the following to a .gitattributes file and checking the file out again:
*.bat text eol=crlf
mvnw text eol=lf
You have to copy the project files into the /app dir first. And you don't have the maven wrapper in the context folder where you run the docker build.
Try change the end of line mvnw file from Windows style CRLF to Unix style LF. Then rebuild the image.

Docker image for Debian : Access to the file or directory '/usr/local/openjdk-8/bin/java' is denied

While performing some Java related operation for Mendix on docker image "openjdk:8-jre" , I am getting an error: "System.UnauthorizedAccessException: Access to the file or directory '/usr/local/openjdk-8/bin/java' is denied."
Note: Command I am executing is not being executed manually, but I am using Gitlab for CICD for my project and one of the script is executing this Java related command.
A bit about Mendix : This is a platform I used for building my app. I am trying to build a deployable package on this docker image using following command.
mono /modeler/mxbuild.exe --output="Automation" --java-home =$JAVA_HOME --java-exe-path=$JAVA_HOME/bin/java Automation.mpr
I tried to execute following two commands before executing java command:
su
chmod 777 $JAVA_HOME/bin/java
chown -R root:root $JAVA_HOME
Not able to figure out why permission is getting denied .

How to run maven command in AWS Device Farm

I am trying to run my java mobile project in device farm using maven.
When I run this command on my local machine in the right directory it works:
mvn test -D "cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps --tags #InstallApp"
I put this command on the yaml file in the aws device farm but it doesn't work.
This is the error I get:
[DeviceFarm] echo "Start Appium TestNG test"
Start Appium TestNG test
[DeviceFarm] mvn test -D
"cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps
--tags #InstallApp"
[INFO] Scanning for projects...
[INFO] BUILD FAILURE
[ERROR] The goal you specified requires a project to execute but there
is
no POM in this directory (/tmp/scratchncneoU.scratch/test-
packageO6o8s7).
Please verify you invoked Maven from the correct directory. -> [Help 1]
How can I run this maven command in device farm? Where is the pom located there?
Thanks
After typing this command in the yaml file:
[DeviceFarm] java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="classpath:features" --glue cucumber.steps --tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
I get an error of: Couldn't find the testng.xml in the jar file although I have this in my pom:
<directory>${project.basedir}/src/test/java/cucumber</directory>
</testResource>
</testResources>
What can it be?
The mvn command fails because your deployment package doesn't contain the whole project. From the sound of things with the current deployment package you should be able to do what you want with this command:
- java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="src/test/java/cucumber/features" --glue cucumber.steps
--tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
Otherwise, if you want to use maven you'll need to zip up the whole project and include it's pom.xml. So for example using the sample cucumber java tests
git clone https://github.com/aws-samples/aws-device-farm-appium-cucumber-tests-for-sample-app.git
zip -r deployment_package.zip aws-device-farm-appium-cucumber-tests-for-sample-app
Then you should be able to use maven in the testspec.yml file. For example, I could run the following command for the sample: mvn clean test after going to the project dir and then to get the results I had to export the target directory.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app
- mvn clean test
...
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app/target
- $DEVICEFARM_LOG_DIR
However, you'll need to upload the zip file as an APPIUM_NODE test type to avoid the test package parser there.
HTH
-James

Jenkins failing build when not finding ".part" files

I've created a Jenkins job for maven releases. When doing "release:perform" the build fails with messages of this kind:
Caused by: java.io.FileNotFoundException:
/home/jenkins/.m2/repository/org/sonatype/sisu/inject/guice-bean/1.4.2/guice-bean-1.4.2.pom.part (No such file or directory)
The file changes sometimes, but the kind of error is always the same.
When performing the release manually (aka on my own machine) the error does not happen.
My job run the following commands:
mvn clean install
mvn release:clean release:prepare -e -B
mvn -X release:perform -e -Dusername='username' -Dpassword='password' -Darguments="-Dmaven.javadoc.skip=true"
I believe it's related to space on disk or something similar to that. Is there any kind of config to fix it?
ps: the slaves are not running on containers yet
Thanks in advance

Jenkins Execute failed: java.io.IOException ant build

I have set up Jenkins on debianserver and I am trying to create the first android build but ant is not able to get invoked
In jenkins configuration I have:
Name: Java6
JAVA_HOME/usr/lib/jvm/java-6-sun
Name: AntHome
ANT_HOME/usr/share/ant
On the job config:
git > repo
Build step-
Ant invoke
Ant Version: AntHome
Targets: -d
build file: folder/folder/build.xml
When I build the job it gives me this error
[folder] $ /usr/share/ant/bin/ant -file build.xml -d
/var/lib/jenkins/workspace/Project/folder/folder/build.xml:47: Execute failed: \
java.io.IOException: Cannot run program \
"/home/dims/android-sdk-linux_x86-1.0_r2/tools/aapt": \
java.io.IOException: error=2, No such file or directory
I get the same on command line
jenkins#host:~/workspace/Project/folder/folder$/usr/share/ant/bin/ant -d
/var/lib/jenkins/workspace/Project/folder/folder/build.xml:47: Execute failed: \
java.io.IOException: Cannot run program \
"/home/dims/android-sdk-linux_x86-1.0_r2/tools/aapt": \
java.io.IOException: error=2, No such file or directory
It's happening with this particular project because I have created others and ant -d works: for example
jenkins#host:~$ android create project -n template -t android-10 -p Project -k some.pkg -a Some
Created project directory: Project
Created directory /var/lib/jenkins/Project/src/some/pkg
Added file Project/src/some/pkg/Some.java
Created directory /var/lib/jenkins/Project/res
Created directory /var/lib/jenkins/Project/bin
Created directory /var/lib/jenkins/Project/libs
Created directory /var/lib/jenkins/Project/res/values
Added file Project/res/values/strings.xml
Created directory /var/lib/jenkins/Project/res/layout
Added file Project/res/layout/main.xml
Added file Project/AndroidManifest.xml
Added file Project/build.xml
Added file Project/proguard-project.txt
jenkins#host:~$ cd Project/
jenkins#host:~/Project$ ant -d
Apache Ant version 1.8.0 compiled on M
....
[echo] unless 'nodeps' is used as well.
BUILD SUCCESSFUL
Total time: 0 seconds
This peculiar error happens when you attempt to run aapt (or a project that requires it) on a 64 bit system that is lacking some required 32 bit libraries, such as a default Ubuntu > 9. The solution is to install the ia32-libs package with
$ sudo apt-get install ia32-libs
Assuming you don't want to install close to 300 packages, run this instead:
$ sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 --no-install-recommends

Categories

Resources