-3

I am trying to copy a file (jar file) so that I can run the jar (java -jar) in my pod. But the copy command just doesn't work. The pod logs don't throw any error also.

My deployment.yaml looks like (in brief):

- name: glowroot-jar-init-container
image: "{{ .Values.images.repository }}/{{ .Values.config.aptm.image }}"
securityContext:
  runAsUser: 1000
  runAsGroup: 1000
  runAsNonRoot: true
  readOnlyRootFilesystem: true
imagePullPolicy: {{ .Values.images.pullPolicy }}
command: ["cp","/opt/tools/aptm/glowroot.jar","/aptm"]
volumeMounts:
  - name: aptm-data-glowroot
    mountPath: /aptm
.
.
.
.
.
.
containers:
- name: {{ template "name" . }}
  image: "{{ .Values.images.repository }}/com.gtt.ecomp.vod.dev/vod:{{ .Values.images.vodTag }}"
  imagePullPolicy: {{ .Values.images.pullPolicy }}
  securityContext:
    runAsUser: 1000
    runAsGroup: 1000
    runAsNonRoot: true
    readOnlyRootFilesystem: true
  command:
    - sh
    - -c
    - -x
    - >
      .
      .
      .
      .
      
      echo "Copying aptm JAR."
      cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm;

      .
      .
      .

      bash /mounted-config/start_tomcat.sh;
  args:
  - "30000"
.
.
.
.
- name: aptm-data
  mountPath: /opt/tools/aptm
- name: aptm-data-glowroot
  mountPath: /aptm
.
.
.
.
- name: aptm-data
  emptyDir: {}
- name: aptm-data-glowroot
  emptyDir: {}
 .
 .
 .

The file hram-agent-0.13.jar is present in the WEB-INF/lib/ folder. But when I do a bash and get into the pod to check the if the jar file was copied or not I do not see it.

vodadmin@vod-58867c5dc6-lg8ch:/usr/local/tomcat/webapps/vod/WEB-INF/lib$ ls -lrt hr*
-rw-r--r-- 1 vodadmin vodadmin 13864793 Apr 25 12:56 hram-agent-0.13.jar
vodadmin@vod-58867c5dc6-lg8ch:/usr/local/tomcat/webapps/vod/WEB-INF/lib$

But when cd to the target folder:

vodadmin@vod-58867c5dc6-lg8ch:/opt/tools/aptm$ ls -lrt
total 0

All the trouble started when I changed everything to read only root file system in my pod.

1
  • You'd usually do this with a Dockerfile COPY command, much earlier in the build-test-and-deploy process. You shouldn't need any special setup for your application to be in the image: you're deploying. Commented Jun 19 at 20:53

1 Answer 1

1

Just a quick guess -

When you use > in a yaml, it stacks the lines of its data together into one line.

   - >
      echo "Copying aptm JAR."
      cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm;
      . . .

becomes

echo "Copying aptm JAR." cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm;

which I bet outputs

Copying aptm JAR. cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm

So add a semicolon after the echo statement. Then

   - >
      echo "Copying aptm JAR.";
      cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm;
      . . .

becomes

echo "Copying aptm JAR."; cp /usr/local/tomcat/webapps/vod/WEB-INF/lib/hram-agent-0.13.jar /opt/tools/aptm;

and might work.

Or use a | instead, which preserves the internal newlines.

I'm still suspicious of how the syntax gets delivered to the parser, though. Maybe write a script that wraps all that in a simpler call, and rebuild it into your image?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. That was a lifesaver. It worked. Silly of me to miss the semi-colon.
It wouldn'tr matter in a normal script - It's more YAML than Bash. Deployment yamls layer abstraction into everything. Think about design, though. We build & deploy hundreds of different images - mostly different services written in java or Node.js - across multiple apps, environments, & clusters with a common Dockerfile & a common Helm chart for all, using a common gitlab library file included in the CI file of each repo with a few carefully abstracted & standardized variables to set behavior. Automation rocks, but it takes a lot of work to get all the kinks out, lol

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.