Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Add archive extract files support #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add archive extract files support #208

wants to merge 1 commit into from

Conversation

bhuisgen
Copy link

Add option extractArchives to extract included WAR/JAR file when image is built (only if dockerDirectory is set).

This feature allows me to speed up my app startup and to disable war unpacking in Tomcat configuration.

My POM file :

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>${docker-maven-plugin}</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <imageName>foobot/${project.artifactId}</imageName>
        <imageTags>
            <imageTag>${project.version}</imageTag>
            <imageTag>latest</imageTag>
        </imageTags>
        <dockerDirectory>src/main/docker</dockerDirectory>
        <extractArchives>true</extractArchives>
        <resources>
            <resource>
                <directory>${project.build.directory}</directory>
                <include>ROOT.war</include>
                <targetPath>/root/usr/local/tomcat/webapps</targetPath>
            </resource>
        </resources>
    </configuration>
</plugin>

My Dockerfile :

FROM foobot/tomcat:latest
MAINTAINER Boris HUISGEN <[email protected]>
COPY root /

And maven output :

[INFO] 
[INFO] --- maven-war-plugin:2.6:war (default-war) @ gatewaylab ---
[INFO] Packaging webapp
[INFO] Assembling webapp [gatewaylab] in [/home/boris/Projects/java/labs/gatewaylab/target/gatewaylab-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/boris/Projects/java/labs/gatewaylab/src/main/webapp]
[INFO] Webapp assembled in [127 msecs]
[INFO] Building war: /home/boris/Projects/java/labs/gatewaylab/target/gatewaylab-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] --- maven-antrun-plugin:1.7:run (default) @ gatewaylab ---
[INFO] Executing tasks

main:
     [copy] Copying 1 file to /home/boris/Projects/java/labs/gatewaylab/target
[INFO] Executed tasks
[INFO] 
[INFO] --- docker-maven-plugin:0.4.5-SNAPSHOT:build (default) @ gatewaylab ---
[INFO] Extracting /home/boris/Projects/java/labs/gatewaylab/target/ROOT.war -> /home/boris/Projects/java/labs/gatewaylab/target/docker/root/usr/local/tomcat/webapps/ROOT
[INFO] Copying src/main/docker/Dockerfile -> /home/boris/Projects/java/labs/gatewaylab/target/docker/Dockerfile
[INFO] Building image foobot/gatewaylab
Step 1 : FROM foobot/tomcat:latest
 ---> be64d6f44aa8
Step 2 : MAINTAINER Boris HUISGEN <[email protected]>
 ---> Using cache
 ---> bfab68dd9516
Step 3 : COPY root /
 ---> 9868e1d0dada
Removing intermediate container dcbdcc50d3c4
Successfully built 9868e1d0dada

You can see that ROOT.war is extracted into directory webapps/ROOT.

Signed-off-by: Boris HUISGEN [email protected]

Signed-off-by: Boris HUISGEN <[email protected]>
@kvfedorov
Copy link
Contributor

I think, this might not be needed, if ADD would be used in docker file instead of COPY (and it is docker-maven-plugin default behaviour too)

@bhuisgen
Copy link
Author

ADD doesn't extract ZIP archive (moby/moby#15036).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants