Cannot copy file to Docker container via Spotify Docker Client - java

I want to copy file to the not running container via Docker Client by Spotify -
File is created like -
File.createTempFile("olb-", "-temp").deleteOnExit().writeText("some text")
When I try:
client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/asd.json")
I get:
Either container 1adbf9c1ee511272bec78a46be08bf9299c317b11cdb176eed986640ac86a38c or path /app/my_json.json not found.
Well, ok - I create this file while building image with RUN touch /app/my_json.json
Next run:
client.copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/my_json.json")
Resulted in
{"message":"extraction point is not a directory"}
Ok... I tried directory
copyToContainer(inputFileProvider.createFile(task.dataToInsert).toPath(), containerId, "/app/")
Result:
{"message":"Error processing tar file(exit status 1): cannot overwrite directory \"/\" with non-directory \"/\""}
Same for "/app"
Any ideas how to copy file into docker container via Java client?

It turned out that I must create whole new folder, then single file in it and copy that folder.
val dir = Files.createTempDirectory("tem-folder-")
Files.createFile(dir.resolve("filename")).toFile().writeText("data to write")
val toBeCopied = dir.toFile()
cliend.copyToContainer(toBeCopied.toPath(), "containerId", "targetPath")

Related

What causes this dependabot issue?

I am following this : https://bobbybouwmann.nl/blog/dependabot-on-gitlab, to attempt to get Dependabot working with gitlab. I get the following error?
Using docker image sha256:bc6c0ffef6650bcfbb0afd5a07b813b5ccf1d00ecddccadb85123c6ee57a7995 for docker with digest docker#sha256:63107bd6ce718f130bb2668704239467b74f034c446f9e9c4ae1ffa5ddf4e3dd ...
$ docker build -t "dependabot/dependabot-script" -f Dockerfile .
error during connect: Post "http://docker:2375/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=dependabot%2Fdependabot-script&target=&ulimits=null&version=1": dial tcp: lookup docker on 172.31.0.2:53: no such host
So I checked, and the specified docker image does not exist: https://hub.docker.com/u/dependabot
but, if I use a different, publicly available image, I get this:
Executing "step_script" stage of the job script
00:03
Using docker image sha256:ed97757f85d791b7e0a967622f0d671b810d1ad45aef30d5314dcaef94e7c457 for sethjones/dependabot-script with digest sethjones/dependabot-script#sha256:209a0952bfeb845f67f2eeb9a647c25e058bbae1b9b0e343d7891884840f17e0 ...
/usr/local/lib/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- dependabot/file_fetchers (LoadError)
from /usr/local/lib/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
from ./generic-update-script.rb:4:in `<main>'
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
I'd recommend that you check out the Dependabot GitLab repository. They provide a CI/CD template that is kept up-to-date, so instead of having to write your own jobs you can include their template using:
include:
- project: 'dependabot-gitlab/dependabot-standalone'
file: '.gitlab-ci.yml'
They also provide instructions on their page for how to configure it to automatically create MRs.

Writing to a file in a folder while running a JAR on Docker Container results in FileNotFoundException

I am running a JAR in a Docker container. Functionality of my applications is to connect to a DB and get records and output it to a .csv file inside a folder called reports.
Both my src folder and reports folder are in same directory. Which means I can write to the file like below.
String csvFile = "." + File.separator + "reports" + File.separator + "VAS_Report_" + subscriberType +
df.format(new Date()) + ".csv";
//db connection and result extraction logic
........
CSVWriter csvWriter = new CSVWriter(new FileWriter(csvFile));
csvWriter.writeAll(resultSet, true);
This works fine when I run the program locally. I build the project and bundle it as a JAR file.
I create a dockerfile with other relevant steps and following step (to create a folder named reports in the folder where my JAR will be copied)
RUN mkdir -p /apps/Consumer/
COPY My-App-1.0.jar /apps/Consumer/
RUN mkdir -p /apps/Consumer/reports
RUN chmod ugo+w /apps/Consumer/reports #giving write permission
Docker image builds successfully, db connection success and during run time when it tries to write to csv file, the application throws exceptions stating that it cannot find specified folder/file (FileNotFound Exception).
What am I doing wrong here?
Following are additional questions which came across while searching for a solution.
Does bundling an application preserve project structure? (Since I needed to manually create a folder named reports in docker container)
Do I need to provide permissions for created folder (reports) in any way? (Which I did here)
In place of:
RUN mkdir -p /apps/Consumer/
...
RUN mkdir -p /apps/Consumer/reports
Use WORKDIR as:
WORKDIR /apps/Consumer/
COPY My-App-1.0.jar .
RUN chmod ugo+w /apps/Consumer/reports #giving write permission

CF pushing - the system cannot find the file specified

I am using cf for the first time, trying to deploy a simple app to Bluemix. When I try cf push, I get this error:
E:\Program Files\tomcat\apache-tomcat-8.0.41\webapps\helloServletMaven\target
λ cf push /helloServletMaven -p /helloServletMaven.war
Creating app /helloServletMaven in org alexander.kirwan / space ORG as alexander.kirwan#mycit.ie...
OK
Using route helloservletmaven.mybluemix.net
Binding helloservletmaven.mybluemix.net to /helloServletMaven...
OK
FAILED
Error processing app files: GetFileAttributesEx E:\helloServletMaven.war: The system cannot find the file specified.
E:\Program Files\tomcat\apache-tomcat-8.0.41\webapps\helloServletMaven\target
λ ls
classes/ generated-sources/ helloServletMaven/ helloServletMaven.war m2e-wtp/ maven-archiver/ maven-status/ test-classes/
E:\Program Files\tomcat\apache-tomcat-8.0.41\webapps\helloServletMaven\target
But as you can see, when I run ls, I do have the war file.
Why is this happening?
By the way, I am using Windows and CMDER for the console.
It looks like your file is in the local directory so you don't have use /helloServletMaven.war, i.e. remove the slash (/)
cf push helloServletMaven -p helloServletMaven.war

Open a file on Openshift using Java

I have a DIY cartridge. My project structure looks like
MY_PROJECT
-diy
-myProgram.jar
-resources
-file1, file2...
-.openshift
-action_hooks
-start
The myProgram.jar uses files from the folder 'resources'.
The code looks like
File imageFolder = new File("resources");
System.out.println("Image Folder read:"+imageFolder.canRead()); //canRead returns false
File[] listOfFiles = imageFolder.listFiles(); // here I get null
The program runs by action hook 'start':
nohup java -jar $OPENSHIFT_REPO_DIR/diy/*.jar --server.port=${OPENSHIFT_DIY_PORT} --server.address=${OPENSHIFT_DIY_IP} &
The problem is that I'm not able to work with files.
As described in code comments I get null on listFiles().
If I run the program on Openshift manually(ssh to server/$OPENSHIFT_REPO_DIR/diy/ and run java -jar ...) it works, but it doesn't work via action_hooks.
Thank you in advance!
I resolved the issue with Openshift env variable 'OPENSHIFT_REPO_DIR'.
Instead of using relative path
new File("resources");
I use absolute
String absolutePath = System.getenv("OPENSHIFT_REPO_DIR");
new File(absolutePath + "diy/resources")

JETTY_LOGS is being appended to JETTY_HOME

I'm trying to run Jetty on CentOS and am having problems as I am getting unexpected results when I try to set the full path for JETTY_LOGS. The system tries to take that path and append it to the path I specified in the JETTY_HOME variable.
JETTY_HOME=/usr/local/jetty/jetty-9.1.4
JETTY_USER=jetty
JETTY_PORT=8085
JETTY_HOST=0.0.0.0
JETTY_LOGS=/usr/local/jetty/jetty-9.1.4/logs
Any ideas as to what I'm doing wrong?
The error I get is:
Starting Jetty: java.io.IOException: Cannot write start.log to directory
/usr/local/jetty/jetty-9.1.4/usr/local/jetty/jetty-9.1.4/logs [directory doesn't exist or is read-only]
java.io.IOException: Cannot write start.log to directory /usr/local/jetty/jetty-9.1.4/usr/local/jetty/jetty-9.1.4/logs [directory doesn't exist or is read-only]
at org.eclipse.jetty.start.StartLog.initLogFile(StartLog.java:127)
at org.eclipse.jetty.start.StartLog.initialize(StartLog.java:113)
at org.eclipse.jetty.start.Main.processCommandLine(Main.java:520)
at org.eclipse.jetty.start.Main.main(Main.java:102)
It seems that JETTY_LOG directory is relative to JETTY_HOME.
Could you try to set:
JETTY_LOGS=/logs
or alternatively
JETTY_HOME=/usr/local/jetty/jetty-9.1.4/
JETTY_LOGS=logs
You're not doing anything wrong, this is new behavior in jetty 9.1.4:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=432192
Workaround is to set the JETTY_LOGS env var relative to your jetty base dir (like the logs dir that comes in the standard jetty tarball):
JETTY_LOGS=logs
Which will resolve to /usr/local/jetty/jetty-9.1.4/logs in your case (the jetty base dir defaults to the jetty home dir).
If you want the logs written somewhere outside of your jetty base dir, the best way is to use the above JETTY_LOGS=logs env setting, and just symlink the dir elsewhere; like this to create and link to the common /var/log/jetty dir:
# mv /usr/local/jetty/jetty-9.1.4/logs /var/log/jetty
# ln -s /var/log/jetty /usr/local/jetty/jetty-9.1.4/logs
Whatever you do, also make sure that the user as which you run jetty has write access to the logs dir; if you use the jetty user in the jetty group, make it the owner of your logs dir:
# chown -R jetty:jetty /var/log/jetty

Categories

Resources