添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

There is no ADD because the expectation is that the user would mount the project directory as a volume on the guest. ex: docker run -v pwd:/<project_directory> -w=”/<project_directory>” test gauge run specs. ref: docs.gauge.org/howto/ci_cd/… – Srikanth Venugopalan Oct 9, 2019 at 6:25 @SrikanthVenugopalan Does that mean, you need both the docker container and also the project directory available on the machine so you can run the specs? I'm trying to dokerize the whole project. – AliReza Oct 9, 2019 at 14:46 Yes, the docker instructions in the documentation refers to building an environment with gauge and dependencies, that can run multiple projects, by mounting them as volumes. I would not recommend shipping the project in the container, since you'll have to build an image for every change! Also, if you mount the volumes, you can access the reports/logs in the host (after the container is killed). – Srikanth Venugopalan Oct 11, 2019 at 4:38 @Alireza - replacing ubuntu with alpine will still serve the purpose and will make the image lightweight. – sumit sachdeva Jul 23, 2021 at 13:14

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.