7

I'm baking a Docker image which runs a Maven task at runtime. It looks kind of like this:

ADD pom.xml /srv
ADD src /srv/src

WORKDIR /srv
RUN mvn dependencies:go-offline scala:testCompile

At runtime, I'm running mvn gatling:execute to run a load testing utility.

My POM looks like this:

<project>
  <dependencies>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-core</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-http</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-app</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
            <version>${gatling.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>${scala-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

What I want to have happen is that when I ultimately run mvn gatling:execute, I don't want to have to download any dependencies, I'd like them all baked into the image at build time.

However, even executing mvn dependencies:go-offline scala:testCompile doesn't get me all of the way there. Running gatling:execute still requires downloading more dependencies.

How can I download absolutely everything that Maven requires into my Docker image, so that no downloads at runtime are required?

Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
  • Have you tried binding the Gatling execution to a phase and see whether dependencies:go-offline picks it up? – Trent Bartlem Oct 28 '15 at 01:14
  • What do you suggest? I'm sorry, long day, not sure exactly what you mean. – Naftuli Kay Oct 28 '15 at 01:15
  • Something like integration-testexecute – Trent Bartlem Oct 28 '15 at 01:18
  • The problem is that I can't run `gatling:execute` without massively pwning an endpoint ;) – Naftuli Kay Oct 28 '15 at 01:26
  • That's understandable, but not a problem if you don't go past the mvn package phase. Regardless of that, did the maven dependency plugin find the Gatling dependencies if they are bound to a phase? – Trent Bartlem Oct 28 '15 at 01:29
  • @TrentBartlem Can you submit that as an answer as to how I should modify my pom? – Naftuli Kay Oct 28 '15 at 05:46
  • @NaftuliTzviKay what is your objective? Do you want to distribute this image (e.g. in the company), or do you want to use it as a build environment and you don't want to download the same stuff with every build? If it's the latter, you can put your maven repository directory in a docker volume. – ivant Oct 28 '15 at 19:01
  • @ivant I want to distribute a Docker image which runs `mvn gatling:execute`, but I'd like all of the dependencies to be compiled into the image at build-time, not at run-time. Waiting for Maven to download the internet at Docker container start time is something I'd like to avoid. – Naftuli Kay Oct 28 '15 at 19:52
  • I guess you mean `dependency:go-offline`, right? Normally, maven will check SNAPSHOT dependencies once per day. Do you have any? Also try forcing the offline mode when running execute: `mvn -o gatling:execute`. – ivant Oct 28 '15 at 20:23
  • @NaftuliTzviKay did what I suggested in my previous comment work for you? – ivant Oct 30 '15 at 10:05

2 Answers2

1

You don't necessarily have to run the simulation with the maven plugin, do you? You can use maven to package a jar with all dependencies and execute the gatling runner from it.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • I know. I needed something _fast_, I didn't want to muck around with the maven assembly plugin all day trying to get a Scala application packaged and running properly. – Naftuli Kay Nov 08 '15 at 05:02
0

You can download all dependencies using: mvn dependency:copy-dependencies

After this you all project's dependencies will be available in the ./target/dependency/ folder.

aholub7x
  • 808
  • 12
  • 26