Travis yml to run Selenium Java Gradle Docker build - java

I'm looking for an example .travis.yml file that would execute a Gradle build inside a Docker container that would run my Selenium tests. So far I've seen various blog posts and answers, but they are either in a language that I'm not looking for like JavaScript, or they use Maven instead of Gradle.

I finally got a working example after piecing it together from various blogs:
.travis.yml
sudo: required
dist: trusty
language: java
jdk:
- oraclejdk8
script:
- gradle clean test
before_install:
- docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm -e VNC_NO_PASSWORD=1 selenium/standalone-chrome-debug:latest
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

Related

Providing full path to java in gitlab config

In my gitlab-ci.yml configuration I have the following snippet:
before_script:
- java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
It does not work but for a different reason (since java versions are incompatible).
Here's the output:
The solution was to install a newer java 11.
I did so and changed the configuration correspondingly:
before_script:
- /opt/java11/jdk-11/bin/java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
However, with this configuration nothing works at all:
But if I execute this command in VM environment directly, it works as expected.
Is there a limitation on using full qualified path in the yml file or maybe it has to do with something else?
Before you updated java the job fail at the java command, so it didn't try to execute mvn.
However, when the first problem is solved, you get a new issue and now with mvn command.
I guess the runner cannot recognize mvn because maven is not installed.
You could try adding the following to the before_script section:
- apt-get update && apt-get install maven
This is will depend on the linux distribution, use yum instead if the runner is on redhat or centos

qemu-x86_64: Could not open '/lib/ld-musl-x86_64.so.1': No such file or directory

Has anyone come across this error when trying to execute a docker-compose up command.
I have tried to resolve it by looking at other articles that touch on something similar but I am having no success.
I am trying to run my spring boot app using a docker-compose file and I keep getting this error:
qemu-x86_64: Could not open '/lib/ld-musl-x86_64.so.1': No such file or directory
I have tried to fix it by following the advice I read online but nothing has worked.
I have tried:
After reading this post: https://github.com/nodejs/help/issues/3239
adding the following
platform: linux/amd64
to my docker-compose file but it doesn't make a difference
and tried FROM --platform=linux/amd64 in front of my Dockerfile
When I read this I tried to install musl as well but failed to execute the make command
curl https://musl.libc.org/releases/musl-1.2.2.tar.gz -o musl-1.2.2.tar.gz
tar -xvf musl-1.2.2.tar.gz
cd musl-1.2.2
./configure
make
make install
My Docker file looks like this
FROM azul/zulu-openjdk-alpine:11 as packager
RUN { \
java --version ; \
echo "jlink version:" && \
jlink --version ; \
}
ENV JAVA_MINIMAL=/opt/jre
# build modules distribution
RUN jlink \
--verbose \
--add-modules \
java.base,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument \
# java.naming - javax/naming/NamingException
# java.desktop - java/beans/PropertyEditorSupport
# java.management - javax/management/MBeanServer
# java.security.jgss - org/ietf/jgss/GSSException
# java.instrument - java/lang/instrument/IllegalClassFormatException
--compress 2 \
--strip-debug \
--no-header-files \
--no-man-pages \
--output "$JAVA_MINIMAL"
# Second stage, add only our minimal "JRE" distr and our app
FROM alpine
ENV JAVA_MINIMAL=/opt/jre
ENV PATH="$PATH:$JAVA_MINIMAL/bin"
COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL"
COPY "build/libs/company-coordinator-app-0.0.1-SNAPSHOT.jar" "/company-coordinator-app.jar"
EXPOSE 8080
CMD [ "-jar", "/company-coordinator-app.jar" ]
ENTRYPOINT [ "java" ]
and my docker-compose.yml file looks like this
version: '2'
services:
company-coordinator-app:
container_name: 'company-coordinator-app'
build:
context: /Users/ciaran/cmkdev/company-coordinator-project/company-coordinator-app
dockerfile: Dockerfile
image: springio/gs-spring-boot-docker
ports:
- "8080:8080"
I am running this off an M1 mbp
I read this post on here in an attempt to build my Dockerfile correctly as I needed to use Java 11.
Java 11 application as lightweight docker image
If anyone has any insights here it would be greatly appreciated.
It seems azul/zulu-openjdk-alpine:11 doesn't have arm64 image needed to run on Apple silicon architecture.
Try updating to jdk 17 image with arm64 support https://hub.docker.com/r/azul/zulu-openjdk-alpine/

Extract test coverage from the docker container in GitLab-CI

I'm using GitLab-CI and running the java application that is built with help of Gradle.
There is an application running inside the Docker container. In parallel, the job automation runs the ApiTestSuite test suite along with the java application.
The question is: How can I get the test coverage from the running application after the ApiTestSuite suite ends?
Here is the simplified version of the GitLab job:
automation:
stage: validate
tags:
- dind
variables:
PROFILE: some-profile
services:
- docker:stable-dind
- redis:5-alpine
- webcenter/activemq
before_script:
- docker run --detach --name MY_APPLICATION
script:
- ./gradlew ApiTestSuite
I can fetch the code coverage while running unit test cases but have some problems understanding how it can be implemented for the example above.
Thank you in advance :)
Tell java to use JaCoCo Agent while running the application inside the container
-javaagent:/home/java/jacoco.jar=destfile=folder_inside_contrainer/jacoco-it.exec,append=true
Configure Agent to write the results into folder_inside_contrainer
replace *folder_inside_contrainer* with the one you will share with the host later on
Share folder folder_inside_contrainer between the container and the host (in this case GitLab Job)
docker run -d -v gitlab_folder:folder_inside_contrainer
Export results that are in .exec format into .html format via JaCoCo-cli.jar
java -jar jacococli.jar report gitlab_folder/jacoco-it.exec --classfiles path_to_app_compiled_classes --html coverage/api-coverage-html
Grab the coverage from HTML and display it for that job
api-coverage:
stage: release
script:
- 'apt-get install -y unzip'
- 'curl -L "https://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.6/jacoco-0.8.6.zip" -o jacoco.zip'
- 'unzip jacoco'
- 'java -jar lib/jacococli.jar report gitlab_folder/jacoco-it.exec --classfiles path_to_app_compiled_classes --html coverage/api-coverage-html'
- grep -oP "Total.*?([0-9]{1,3})%" coverage/api-coverage-html/index.html
coverage: "/Total.*?([0-9]{1,3})%/"
artifacts:
paths:
- coverage/

Run gauge tests inside a docker container

I'm trying to Dockerize a Gauge test automation project so I can run specs inside a Docker container. The project is written in Java and Spring Boot.
I saw this tutorial in Gauge documentation.
This is the DockerFile in the tutorial:
FROM ubuntu
# Install Java.
RUN apt-get update && apt-get install -q -y \
openjdk-8-jdk \
apt-transport-https \
gnupg2 \
ca-certificates
# Install gauge
RUN apt-key adv --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 023EDB0B && \
echo deb https://dl.bintray.com/gauge/gauge-deb stable main | tee -a /etc/apt/sources.list
RUN apt-get update && apt-get install gauge
# Install gauge plugins
RUN gauge install java && \
gauge install screenshot
ENV PATH=$HOME/.gauge:$PATH
As you see, there's no "ADD"/"COPY" there in the DokcerFile.
Is it just suggesting an alternative to install Gauge and the other packages on the host?
Any ideas on how to run the specs inside a Docker container?
Here is what I did to get the test running in the docker container.
I have a specs folder beside src in my project structure meaning the gauge tests will run using the JAR file but they're not part of the JAR file themselves.
--MyProject
----specs
----src
...
I used maven to run the test inside the container. That's why I preferred to build the project inside the container so I get the JAR file ready with the same version of maven I run the test with.
Here is the DockerFile. I developed a bash script to run the test. You may run the script with CMD or ENTRYPOINT:
FROM maven:3.6.1-jdk-8
# add any project resources needed
ADD env /home/e2e/env
ADD specs /home/e2e/specs
ADD src /home/e2e/src
ADD src/main/scripts/entrypoint.sh /home/e2e/
ADD pom.xml /home/e2e/
RUN ["chmod", "+x", "./home/e2e/entrypoint.sh"]
# Install Gauge, web browser and webdriver in your preferred way...
ENV PATH=$HOME/.gauge:$PATH
# I'm keeping the cntainer running. But it's all up to you.
CMD /home/e2e/entrypoint.sh && tail -f /dev/null
And then here is the simple entrypoint.sh script:
#!/bin/bash
cd /home/e2e/
mvn clean package
gauge --version
google-chrome --version
mvn -version
mvn gauge:execute -DspecsDir=specs/myTest.spec
Of course, you could just use a ready JAR instead of building it inside the container. Or you could build the JAR while creating the docker image.

Installing Java on online Gitlab ci

Here is my .gitlab-ci.yml script.
before_script:
- uname -a
- apt-get install default-jre default-jdk openjdk-7-jre openjdk-7-jdk
- java -version
- export MODE="service"
- export PID_FOLDER="/var/run/gitlab-runner-test"
dev:
script:
- chmod +x gradlew
- ./gradlew assembleDebug
I am trying to run the script on gitlab.com page to compile a android project. I checked with some alterations to my script that there is no java installed on the ci
linux Linux runner-8a2f473d-project-881036-concurrent-0 4.5.0-coreos-r1 #2 SMP Thu May 5 07:27:26 UTC 2016 x86_64 GNU/Linux.
I tried installing java, just like a sample which was shown for ruby, but it does not work, and gives an Unable to locate package error.
I am not sure what should be the package as it seems like a ubuntu system, but the command which works on my ubuntu does not work here.
This is not a local installation.
I believe you should be able to use the image feature described here. I found success with the anapsix/alpine-java:jdk8 Docker image.
I am using my own Docker gitlab-runner with a custom Docker image as I need Maven with Oracle java. I'm not 100% on if the shared runner on gitlab.com allows you to use your own image.
My Dockerfile for that (which I upload to Gitlab and use their new Docker container register feature)
FROM anapsix/alpine-java:jdk8
ENV MAVEN_VERSION 3.3.3
RUN apk update && apk upgrade && apk add curl wget bash tar rsync openssh-client
RUN mkdir -p /usr/share/maven \
&& curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn \
&& rm -rf /tmp/* /var/cache/apk/*;
ENV MAVEN_HOME /usr/share/maven
ENTRYPOINT []
CMD ["bash"]

Categories

Resources