Springboot running on Docker unable to read files from resources - docker

I have a springboot project with default structure. I have an excel file under resources/data. My program need to load excel file and dump data into different tables from each sheet.
When I run from Eclipse, program loads excel file correctly and everything looks good. However, when I deploy the same App on Docker, it fails to read the File from resources.
Have anyone encountered this issues? How have you solved it?

First of all try to check whether the Docker is a reason, or there is an issue with java code. Spring boot creates an artifact that can be run with just java -jar <your-spring-boot-artifact.jar>
If this doesn't run even without docker, then you should change the way you access Excel files from spring boot application (your java code):
if the file is in resources folder, it should be packaged into the spring boot artifact.
In this case, you have to use getClass().getResourceAsStream() to access the file, and not rely on java.io.File API, because File API doesn't allow working with files inside a Jar, its not a regular filesystem.

Related

How can I package a windows dependent program into a lightweight docker container?

I currently have a folder containing some .dll files, .bin files and some .exe files. The main .exe that I will be executing only works on windows, and I am not entirely sure what are all its dependencies. My goal is to package all the files in the folder into a docker container so I can integrate it into the rest of my pipeline. The main .exe is a command line tool which is only called once with some arguments and left to run.
I have tried to use windows server core as the container image and it works. However this image is too big for my needs. I have tried to use nano server but when I try to run the executable there is nothing printed in the command line and the program does not run. In that scenario, if I type:
C:\Bin\x64>echo %ERRORLEVEL%
I get the following output:
-1073741515
Meaning I am missing some dependencies.
So, I'm wondering if there is an alternate solution to packaging this folder since windows server core is too big.
Most likely you'll have to stick with the Server Core image. The main thing is that these images server different purposes, and the Nano Server is intended to new applications being developed with the targeted Nano Server API. Server Core is the image focused on existing apps, but its APIs make the image larger than what one would expect from a container.
Keep in mind that it's still better than a full VM. :)
I blogged about this here: https://techcommunity.microsoft.com/t5/containers/nano-server-x-server-core-x-server-which-base-image-is-the-right/ba-p/2835785

How to install mongoDb connector under Windows?

I use KSQLdb, and I have tried to install MongoDb connector. Tutorial says to use confluent hub client or download connector jar file that include in java application.
But I want to use KSQLDB as CLI.
Default installations is:
Download installation Or download the ZIP file and extract it into one
of the directories that is listed on the Connect worker's plugin.path
configuration properties. This must be done on each of the
installations where Connect will be run.
Where to place these files?
The connector simply needs to be on the java class path. Adding the jars to the lib or ext folder should be sufficient.

.Net Core application fails to publish to GCP App Engine becuase of MVC.Abstractions

This is my first foyer into .Net Core and App Engines, so please forgive me if I sound uninformed.
We have a .Net Core Application that we're trying to get published to a GCP App engine (obviously). when I run dotnet publish -c Release it builds just fine without any errors. When I test the program locally it runs just fine and I'm able to access it. However whenever I try to get it on GCP I get the following error:
Updating service [default] (this may take several minutes)...
.................................................................................................................................................failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
Error:
An assembly specified in the application dependencies manifest (ApplicationName.deps.json) was not found:
package: 'Microsoft.AspNetCore.Mvc.Abstractions', version: '2.0.2'
path: 'lib/netstandard2.0/Microsoft.AspNetCore.Mvc.Abstractions.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.5.xml
Failed to deploy project WebApiDotNetCore to App Engine Flex.
We tried removing it from the dependencies JSON, and that just ended up breaking everything, so it is indeed required. It is installed in the project via nuget, so it should be included with dotnet restore. I've looked around and some sources seem to think that it's the installation of the dotnet core sdk, but I've tried it on three computers and always get the same thing.
Lastly, I should say this happens when I try to deploy through command line as well as directly through Visual Studio with the GCP SDK.
Has anyone experienced this error, or something similar? Any advice or guidance is very much appreciated.
Thanks!
-BT
OP REVISION
As an update I was able to get this resolved aside from the fact that I get a 502 error when I try to load the application. Here are the steps I took for anyone else that is looking what to do:
Pre-reqs: Docker for Windows and Google Cloud SDK installed and running. Running turned out to be a pain with Docker for Windows. Many many restarts and reinstallations.
Open the solution and ensure that the startup project is set correctly.
Right click the startup Project, and select Add > Docker Support.
Select Linux in the popup window and allow the files to be created.
When complete, the Dockerfile should appear in the preview window. Do the following:
For me the first line read: FROM microsoft/aspnetcore:2.0 AS base. Change this to FROM microsoft/aspnetcore-build:2.0 AS base.
Additionally, check to make sure that the last line has the correct .dll name. Docker for Windows will put whatever the project name is rather than the class name, so for me my final .dll names were different than the project name.
Lastly, if your project has any dependencies that are required to run but not to build, then you'll need to manually add them. For me we have a couple of XML files that needed to be put in the app folder, so I had to add COPY *.xml /app/ and put those files in the same folder as the solution file is in.
If there's anything else you need to do to the Dockerfile I highly recommend this page. It's a how-to on all Dockerfile commands written in ENGLISH! (that was my biggest problem with all of this - I have little experience with Linux and even less with Docker and everything was written in Greek for me).
Create an app.yaml file. I just used the standard:
runtime: custom
env: flex
Copy the Dockerfile found in the startup project's folder into the folder with the solution.
Initialize gcloud to the right project, then navigate to the solution folder. The type gcloud app deploy app.yaml, and follow the onscreen guide.
for me it takes about 15 minutes to deploy the GCP, so depending on the complexity of your project it may take longer, though this one is rather complex.
Now I'm trying to figure out my 502 error... I've tried what seems like everything - changing the listening port in the application, exposing the listening port on the dockerfile, trying to get GCP to open that port, and trying half a dozen different ports. It's slow-going since it's such a chore to deploy each time.
Hope this helps anyone that was like me a couple weeks ago and had never even heard of Docker!
Which version of .NET Core is this? Also, have you tried to run in Cloud Shell? Maybe that will provide more clues on what might be wrong.
It looks that you don't have the Microsoft.AspNetCore.Mvc.Abstractions library installed in your system. Using the .NET CLI, type the following command:
dotnet add package Microsoft.AspNetCore.Mvc.Abstractions --version 2.0.2
After that, to ensure the library is included, run the following:
dotnet restore
dotnet build
Try running it locally (it should work), and then use the dotnet publish -c Release command again.

Deploy features.xml in servicemix during jenkins Build

I have my features.xml file in src/main/resources/features folder , when I build my project through Jenkins after building my bundle goes to the nexus repository , my requirement is that after my bundle goes to nexus then features.xml should automatically be deployed on servicemix as part of build only. I should not open the servicemix console to install the feature. Please help
You may think about using a KAR (KAraf aRchive).
More information can be found here: http://karaf.apache.org/manual/latest-3.0.x/users-guide/kar.html
You can build а KAR (through Jenkins), containing your feature, then you can use a hot deployment.
Apache Karaf also provides a KAR deployer. It means that you can drop
a KAR file directly in the deploy folder.
Apache Karaf will automatically install KAR files from the deploy
folder. You can change the behaviours of the KAR deployer in the
etc/org.apache.karaf.kar.cfg:
I have also been working on this and my solution was to turn to automated scripting to accomplish this. I wrote a ssh and FTP based program which would stop an smx, delete the ${karaf.home}/data/cache/ directory, replace the new feature file with the one retrieved from the ftp operation, then restart the karaf container.
If you are open to looking into other possibilities:
You can look into Fuse Fabric which can link many smx Containers together and implement version increases and rollbacks. Currently I believe this would also need scripting to accomplish it automatically.
The third option is relatively new and comes in the form of Building docker images and deploying them via OpenShiftV3 which was just unveiled at the Redhat Summit 2015. Its worth noting its fairly new, but it does pack a very impressive feature set.

Grails application in openshift

I am trying to deploy my grails application on an openshift server. I have created an instance using command "rhc app create MyApp jbossews-2.0". When I ssh to the server, I see a jboss folder but no tomcat folder. How can I deploy my .war file onto the server?
I think the Docs on how to deploy a binary file will help you with this, however what the docs do not say is that with Tomcat the deployments directory is called webapps but they work the same way (except for the marker files, tomcat does not use those).
You may want to check out https://github.com/gssOpenShiftsupportExamples/JavaSample as it shows an example of how to do this with JBoss (the same thing will work for Tomcat if you change the directory as denoted above).

Resources