Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven skip deploy & push only Docker images

Tags:

docker

maven

I have both deploy plugin and dockerize plugin in my Maven project.

Deploy plugin,

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>

Dockerize plugin,

<profiles>
        <profile>
            <id>docker</id>
            <properties>
                <assembly.skipAssembly>true</assembly.skipAssembly>
            </properties>
            <build>
                <finalName>${project.artifactId}</finalName>
                <plugins>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <version>${version.docker.plugin}</version>
                        <executions>
                            <execution>
                                <id>dockerize-app</id>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <repository>${docker.image-prefix}${project.artifactId}</repository>
                            <tag>${project.version}</tag>
                            <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                            <buildArgs>
                                <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                            </buildArgs>
                            <resources>
                                <resource>
                                    <targetPath>/</targetPath>
                                    <directory>${project.build.directory}</directory>
                                    <include>${project.artifactId}.war</include>
                                </resource>
                            </resources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

I have following use cases.

  1. Deploy artifacts alone
  2. Deploy Docker image alone
  3. Deploy artifact & Docker image

To achieve this, I added Docker plugin under profile. So that, Docker image will be deployed on passing the profile name.

mvn deploy

The above command will deploy just the artifacts.

mvn deploy -P docker

The above command will deploy artifacts & Docker image.

But, I am unable to just deploy the Docker image.

To just deploy the Docker image, I am adding the below config in the deploy plugin,

<configuration>
                    <skip>true</skip>
                </configuration>

Or, setting default-deploy to none.

<execution>
                        <id>default-deploy</id>
                        <phase>none</phase>
                    </execution>

The above 2 approaches needs pom change.

  1. The other approach would be to create a profile for deploy also so that we can pass the profile we want.

Is there any other better approach? Or, is it possible with the Maven arguments to skip deploy?

like image 491
user1578872 Avatar asked Aug 06 '18 19:08

user1578872


1 Answers

I think you can do what you want by using properties instead of profiles. Just remove the docker profile and put the configuration directly inside your POM, and the following commands should work :

  • mvn -Dmaven.deploy.skip deploy to deploy only Docker images (default deploy phase is skipped)
  • mvn -Ddockerfile.skip deploy to deploy only artifacts to your repository manager. Options to skip goals (like dockerfile.skip) are described on the dockerfile-maven-plugin documentation
  • mvn deploy to deploy both (artifacts and Docker images)
like image 93
norbjd Avatar answered Oct 11 '22 01:10

norbjd