I'm having an issue writing a file to a directory created from a prior curl/tar command. I can create a subdirectory under the existing directory structure, but I cannot place a file using a tar command in that preexisting directory structure.
In other words, I want to put a .jar file in the /opt/$JMETER_VERSION/lib directory, and cannot. The weird part is that I can create a subdirectory under /opt/$JMETER_VERSION/lib and can put a file in that, but I cannot use a tar command, nor a mv or cp to put a file in the /lib directory.
I did a "chmod w /opt/$JMETER_VERSION/lib" and also did a "ls -l -R /opt" and everything shows up as being under root, which is what I'm under while doing this automation from within a dockerfile. Any idea why I can't write to /opt/$JMETER_VERSION/lib?
The tar command below is causing the automation to fail -
&& curl -fsSL --compressed -o /tmp/mysql-connector.tar.gz https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-6.0.3.tar.gz
&& chmod w /opt/$JMETER_VERSION/lib
&& tar -C /opt/$JMETER_VERSION/lib -xzvf /tmp/mysql-connector.tar.gz --strip-components 1 mysql-connector-java-6.0.3/mysql-connector-java-6.0.3-bin.jar \
CodePudding user response:
Given your user is able to create this /opt/$JMETER_VERSION
directory it should have write access there already.
I don't think it's possible to extract a single file from a tarball without keeping the whole directory structure so I would recommend extracting mysql-connector-java-6.0.3
folder, moving mysql-connector-java-6.0.3-bin.jar
from it to JMeter's "lib" folder (or other folder which is in JMeter Classpath) and performing cleanup of the /tmp folder.
Example Dockerfile
FROM openjdk:8-jdk-slim
ARG JMETER_VERSION=apache-jmeter-5.4.1
ARG JMETER_DOWNLOAD_URL=https://archive.apache.org/dist/jmeter/binaries/${JMETER_VERSION}.tgz
RUN apt-get update && \
apt-get install -y \
curl procps && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /opt/${JMETER_VERSION} \
&& curl -fsSL -o /tmp/apache-jmeter.tar.gz ${JMETER_DOWNLOAD_URL} \
&& tar -xzf /tmp/apache-jmeter.tar.gz -C /opt/${JMETER_VERSION} --strip-components=1 \
&& rm -f /tmp/apache-jmeter.tar.gz \
&& curl -fsSL --compressed -o /tmp/mysql-connector.tar.gz https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-6.0.3.tar.gz \
&& tar -xzf /tmp/mysql-connector.tar.gz -C /tmp mysql-connector-java-6.0.3/mysql-connector-java-6.0.3-bin.jar \
&& mv /tmp/mysql-connector-java-6.0.3/mysql-connector-java-6.0.3-bin.jar /opt/${JMETER_VERSION}/lib \
&& rm -rf /tmp/mysql-connector*
More information: Make Use of Docker with JMeter - Learn How
CodePudding user response:
If it helps, here is the RUN command with the issue. If I comment out the tar command abov th commented line in the middle, the automation passes, but I o course don't get the .jar file I need -
Install jmeter, MySql Connector for Jmeter, plugins manager and plugins (non-deprecated)
RUN curl -fsSL --compressed -o /tmp/jmeter.tgz https://archive.apache.org/dist/jmeter/binaries/$JMETER_VERSION.tgz
&& tar -C /opt -xzvf /tmp/jmeter.tgz
&& rm /tmp/jmeter.tgz
&& curl -fsSL --compressed -o /tmp/mysql-connector.tar.gz https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-6.0.3.tar.gz
&& chmod w /opt/$JMETER_VERSION/lib
&& tar -C /opt/$JMETER_VERSION/lib -xzvf /tmp/mysql-connector.tar.gz --strip-components 1 mysql-connector-java-6.0.3/mysql-connector-java-6.0.3-bin.jar
# && tar -C /tmp -xzvf /tmp/mysql-connector.tar.gz --strip-components 1 mysql-connector-java-6.0.3/mysql-connector-java-6.0.3-bin.jar
&& rm /tmp/mysql-connector.tar.gz
&& curl -fsSL --compressed -o /opt/$JMETER_VERSION/lib/ext/jmeter-plugins-manager.jar https://jmeter-plugins.org/get
&& curl -fsSL --compressed -o /opt/$JMETER_VERSION/lib/cmdrunner-$CMDRUNNER_VERSION.jar https://repo1.maven.org/maven2/kg/apc/cmdrunner/$CMDRUNNER_VERSION/cmdrunner-$CMDRUNNER_VERSION.jar\
&& java -cp /opt/$JMETER_VERSION/lib/ext/jmeter-plugins-manager.jar org.jmeterplugins.repository.PluginManagerCMDInstaller
&& /opt/$JMETER_VERSION/bin/PluginsManagerCMD.sh install-all-except jpgc-hadoop,jpgc-oauth,ulp-jmeter-gwt-plugin,ulp-jmeter-autocorrelator-plugin,ulp-jmeter-videostreaming-plugin
&& sleep 2
&& /opt/$JMETER_VERSION/bin/PluginsManagerCMD.sh status