Running Integration tests from a Docker image for Java project - java

I am new to Docker and currently working on a project which uses docker for build and deployment. I have installed Docker for windows on my Windows 10 machine and currently running docker in windows environment.
I am using Jenkins for creating the docker image for a project which has Integration tests coded inside it.
I need to create new Job in Jenkins which will take docker image from previous job and run Integration tests on this image and not on the code base. I am not sure if we can do it for Windows. I have searched online but have not found any articles or tutorials which explain how to achieve this.
Can someone help me with this problem or guide me to a solution which i can refer.
Thanks
Vikeng

Your question is a few months old, but still :)
You can have a look at the Fabric8 Docker Maven Plugin https://dmp.fabric8.io/
It integrates very well with the Maven workflow: you describe how to build your image (with a DockerFile or in the pom directly), as well as how to run it (in a 'docker run' manner or with a docker-compose.yaml). Of course, Windows is supported, since it is your use case :)
Then, the phases of the plugin integrate well, the build of the image is made at the 'package' phase, and the containers are started at 'pre-integration' and stopped and removed at 'post-integration'.
One small thing to remember is if you have a multi-module project, the integration tests are run by module, so if you have several images that integrate together, make sure to define them in the same pom.
Hope this helps

Related

quarkus dev mode for CLI, how to restart app

I just created a sample Quarkus CLI app. When I run it in dev mode, pressing [enter] does not restart the application.
Steps to reproduce:
I am using the quarkus CLI, on macOS Big Sur, default Terminal app. I generate a default cli app with the following command:
quarkus create cli --group-id=test --artifact-id=test --maven --java --code
Then, once I am inside the test folder, I run:
quarkus dev
The example code runs and dev mode stays waiting for changes, but if I update the sample code and press [enter] on the terminal as described in the quarkus guide for CLI apps, the app is not rerun.
I also tried maven directly as suggested on the guide:
mvn compile quarkus:dev
But the result is the same.
The example generated is very simple, and uses Quarkus 2.0.1 with the picocli extension. Works fine when compiled and run standalone.
Does anyone know what am I missing?
Thanks for any suggestions.
I think what you are seeing is a bug in 2.0 cli where create cli does not create a cli but just the standard app. Thus it won't reload until you hit localhost:8080.
it will be fixed in next version. sorry for inconvenience.
In the mean time you can use https://quarkus.io/guides/command-mode-reference which explains the minimal code and dependencies needed for a Quarkus cli.
Does your project have any tests? The picocli project created by the cli doesn't by default (yet?).
https://github.com/quarkusio/quarkus/pull/18700 should fix your issue (behavior of dev mode for projects without tests).

Developing Java (Maven) application on Docker container

For a new Spring project I'd like to setup a Docker container to build + run + debug my application.
At the moment I'm using this Dockerfile:
FROM maven:3.6.2-jdk-8-slim
COPY . /app/
WORKDIR /app/
RUN mvn clean package
FROM maven:3.6.2-jdk-8-slim
COPY target/app.jar app.jar
ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-jar","/app.jar"]
EXPOSE 5005
In the first step the project is built. In the second step the application is run exposing a 5005 port for "remote" debugging.
Then from my IDE (IntelliJ IDEA) I'm configuring a remote debugging configuration to execute debug on the container.
As you may guess is a bit awkward to execute these steps for every little edit I'd like to debug in the project.
So, I'm wondering if there's a more practical approach using IntelliJ to automatically build and attach the debugger to my application just like when developing directly on my dev machine...
First of all, you can open a pom.xml right from IntelliJ and run the application without the need to run maven (IntelliJ has an excellent maven plugin).
Since you're running it as a java -jar you don't even need an ultimate version of IntelliJ.
Now this is how we develop usually, even before maven. You can run mvn clean package locally as well if you want to, say, check that the tests are run (again, you can also do that in Idea). And when you push your changes create a docker and deploy on server.
This is by far the best solution I can recommend. The way you've described in the question suites more to debugging the remote servers (read ready environments).
If you absolutely need this way, you still can use HotSwap feature of JVM for small changes (as longs as these changes are inside the method): While connected via Remote Debugger, right click and "Recompile" the class that has a change. It will be automatically loaded to remote JVM so that you don't actually need to trigger all this process.
You also don't have to run all the tests in maven (mvn clean package -Dmaven.tests.skip)
A couple of ideas that you can implement:
Use CI/CD to build your docker images
Instead of offloading this work to docker files, let your CI/CD pipeline to build your artifact and then pack it into a docker image ( you'll have more control over the process ). Finally, you can also deploy it to a targeted environment.
Use IntelliJ to run and debug your project on the DEV machine
You gain almost no benefit by running your project using Docker on your DEV machine, only a lot of hassle.

Run docker-compose up in testNG beforesuite

I am looking for help/Suggestion about automating the docker-compose.yml file.
I have automated test scripts(testing xml suite) which verifies multiple micro API services, they are developed using Rest Assured, java and TestNG. Now these micro API services and DB are available on docker as image.
Currently I am executing this automation while running this automation in following way
Making the docker-compose up
Waiting for the services to get up
Updating the end points in my configuration(Automation suite) which we see in docker container
And finally running the automation suite
I want to do all the above 4 points in one go as following. However unable to find any docs or anything open maven lib for it.
Run the docker-compose in beforeSuite method. Should work on all operating system wherever the docker and docker-compose is installed eg. Windows, centOS , linux, ubuntu
Once the services are up in docker container , it should update the end points in configuration file
Docker-compose down in aftersuite method
How we can achieve this or any kind open source lib available?
I think fabric8 docker-maven-plugin suits your needs. You can run your it tests against containers you configure by docker-compose, dockerfile or plugin's configuration. I used the pluging in this dummy project. Have a look.

Scriptable Eclipse run/debug configuration [duplicate]

I'm finding it difficult to phrase this question well, as there are quite a few generic terms (run, configuration, launch, etc.). Here goes:
You can save run configurations in a .launch file. (in the Run Configuration Dialog, under the Common tab, Save as a shared file.
We check these in to SVN. The developers can pass them around, and it helps getting new devs running a working application quicker.
I'd like to check these out as part of our build and use them to programatically run the application, the tests, etc, without spinning up the whole IDE.
What would be the best way to run a .launch file outside of the UI?
Edit: I am trying to unify the tests run on the build server and the IDE. I do not
particularly want to give up integrated debugging, which would be the case with an ant script to run the tests .
This is probably more a problem for integration testing with multiple bundles, or unit testing a whole bundle, where you'd like to mock up extensions.
there is an eclipse plugin built over JUnit, called TPTP. It provides an automation client which can be used to launch the test from eclipse with no gui. maybe it helps
Ant4Eclipse may provide a good starting point on how to do this.
Unfortunately, this is limited to Java Applications and JUnit configurations; I am more interested in PDE applications and Plugin JUnit tests.
I have recently had alot of success building an Eclipse RCP app inside a Hudson CI server using Eclipse Buckminster. It took a bit of doing, but once I setup both features, made my RCP product be based on features, and added the Buckminster query files and the like, it worked. There is a Hudson/Jenkins Buckminster plugin that allowed me to have hudson build the application.
After saving the launch configurations for each test fragment, I created hudson commands to invoke them (yes one line per test fragment unfortunately), but after that I got the automated CI build that I wanted.
You could also use the shell command Eclipse uses. To get it:
Run your program in Eclipse
Go to the "Debug" view
Right-click on the process (probably the second item in the tree) and select "Properties"
Copy shell command and delete the agentlib flag to run in bash
I think you don't need to use the .launch configurations to run the tests. If you build an application using the Eclipse Build System, then you can use the AntRunner application from Eclipse to run your units tests. This doesn't start the whole IDE.
This article describes how to run the tests during your build process. With this process, you use a special "Test" Eclipse and load the plugins you want to test.
Perhaps running the configurations the way you would run your own custom run configurations would help here. It is described in this article.

how to build project after code changes without mvn clean install?

I have a project in eclipse, a java app with appengine sdk and maven as my builder.
The .class files are not refreshed until i launch clean install, so every change i do in code i have to run:
mvn clean install
mvn eclipse:clean
mvn eclipse:eclipse
and then try to launch my app.
Help me please it's really annoying. Thanks
I know this is a very old post but I recently came across this issue while working with STS and Websphere application server. Hope this helps anyone to come across this ancient relic of a post.
Have a look at the "FileSync" plugin in the Eclipse marketplace. It allows to sync your workspace files with external directories (think your application server). After you install "FileSync" you can configure it to "copy/paste" your workspace files directly to your application server's exploded .war directory. It might take a little playing around with to get your files copied in a j2ee compliant format but it worked like a charm for me. Once its configured you basically just update files, save them, and your application is ready to go!
You are probably looking for a hot deployment feature. When working wit ha webapp, in most cases it is not enough just to compile a java class - usually you have to create a war package, and nearly always you have to redeploy the new code to the app server.
mvn package should be enough to create the war. You don't need to run mvn clean as long as you don't remove or rename any file. That would make things faster.
To achieve hot deployment (i.e. to get the new code instantaneously on the web-engine dev server) you need to do do some extra work, however. Make sure you use the Google Plugin for Eclipse - you can use it along with maven. The plugin at least should take care of static files hot deployment. Running the application in debug mode with Eclipse helps a bit as well as it is capable of replacing the methods' bodies on the fly.
Find further information answers to this question.
It's unclear from the question exactly what is happening and why. To figure this out, we would need to see the pom.xml and the "tree" command output showing the relevant folders and files. Then we could compare that to what the relevant maven plugin should be doing, and work from there.
As it stands, this is a quite old question in which it's unclear exactly what's happening, and OP has disappeared a long time ago. If this issue occurred today, the best thing to do would be to post to the App Engine Public Issue Tracker, although this could be inappropriate if the issue weren't in the App Engine SDK (or related maven plugins) but came from a third-party maven plugin not behaving properly (maven-compiler-plugin, for example). However, until a more in-depth analysis were performed, it would be difficult to know in advance.
Getting hot-reload of your App Engine application working is easy using only the Eclipse m2e plugin actually, and doesn't require the GPE plugin or any other special connectors:
1) Create your App Engine app as a Maven project in Eclipse as you would normally, using one of the provided Google archetypes or another custom archetype.
2) Configure your project, and do an initial build with mvn clean install in the root of the project to create the initial target/<artifact>-<version> WAR directory.
3) Start the development server with mvn appengine:devserver in the project root and ensure you can view your locally served app in a browser. Leave the development server running.
4) In Eclipse, make sure that Project -> Build automatically is checked.
Now, whenever you save a .java file Eclipse will automatically build the corresponding .class file under target/<artifact>-<version>/WEB-INF/classes. In a Maven project, this directory is set as the output directory for classes in your .classpath. The development server will detect the file change and do a hot-reload of your application so that the changes will appear immediately when you refresh your app in the browser.

Categories