e-gineering / gitflow-helper-maven-plugin

An extension and plugin that teaches Maven to work well with gitflow projects and CI servers.
Apache License 2.0
76 stars 21 forks source link

Fine-grained control to retaining plugin executions on master #137

Closed glimmerveen closed 1 year ago

glimmerveen commented 1 year ago

Refactored how the MasterPromoteExtension prevents plugins to execute, allowing more fine-grained control allowing specific plugin executions to run on master, but not necessarily all executions of a single plugin.

This refines an earlier addition #129, and should address #136

bvarner commented 1 year ago

I really like this. Thanks!

rhierlmeier commented 1 year ago

Thanks @glimmerveen, today I will have the time to testing it. But I will test it tomorrow. I am preparing a project, where I want to integrate Docker into the git workflow. It uses kubernetes-maven-plugin to push to different Docker repositories. On the master build it must push an Docker image from a Docker staging repo to the release repo, how it must not build die Docker image again.

rhierlmeier commented 1 year ago

I tested the retained execution in my docker gitworkflow example. It works. @glimmerveen thank you this feature.

Details:

I defined in the pom an execution in the maven-antrun-plugin that copies the Docker images from a staging Docker registry into the release Docker registry:

   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <executions>
         <execution>
            <id>copy-from-stage-to-release</id>
            <goals>
               <goal>run</goal>
            </goals>
            <phase>deploy</phase>
            <configuration>
               <skip>${docker.skip.deployToRelease}</skip>
               <target>
                  <exec executable="docker" failOnError="true">
                     <arg line="${docker.globalArgs}"/>
                     <arg value="pull"/>
                     <arg value="dockerregistry-stage.example.com/${project.groupId}/${docker.artifactId}:${project.version}"/>
                  </exec>
                  <exec executable="docker" failOnError="true">
                     <arg line="${docker.globalArgs}"/>
                     <arg value="tag"/>
                     <arg value="dockerregistry-stage.example.com/${project.groupId}/${docker.artifactId}:${project.version}"/>
                     <arg value="dockerregistry-release.example.com/${project.groupId}/${docker.artifactId}:${project.version}"/>
                  </exec>

                  <exec executable="docker" failOnError="true">
                     <arg line="${docker.globalArgs}"/>
                     <arg value="push"/>
                     <arg value="dockerregistry-release.example.com/${project.groupId}/${docker.artifactId}:${project.version}"/>
                  </exec>
               </target>

            </configuration>
         </execution>
      </executions>

In the gitflow-helper-maven-plugin put this execution onto the retainPlugins list:

  <plugin>
     <groupId>com.e-gineering</groupId>
     <artifactId>gitflow-helper-maven-plugin</artifactId>    
     <configuration>
      ...
      <retainPlugins>
         <retainPlugin>org.apache.maven.plugins:maven-antrun-plugin:copy-from-stage-to-release</retainPlugin>
      </retainPlugins>
      ...
      </configuration>
 </plugin>

The master build copies now the Docker image from the stagine Docker registry to the release registry:

 [INFO] GitBranchInfo: [name='master-1.0.7', type='MASTER', pattern='(origin/)?(master\-?).*']
 [INFO] gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [master-1.0.7] matches masterBranchPattern: [(origin/)?(master\-?).*]
 [INFO] The following plugin (execution) whitelist will be applied: {org.apache.maven.plugins:maven-deploy-plugin=[], com.e-gineering:gitflow-helper-maven-plugin=[], org.apache.maven.plugins:maven-antrun-plugin=[copy-from-stage-to-release]}
 [INFO] Continuing execution....
...
[INFO] --- maven-antrun-plugin:3.1.0:run (copy-from-stage-to-release) @ 9999_998-TEST_GitFlowDocker ---
 [INFO] Executing tasks
 [INFO]      [exec] 1.0.7: Pulling from 9999-998/9999_998-test_gitflow_docker/stage
 [INFO]      [exec] Digest: sha256:11f7c81a3214751ca43cecaa8a1077042b7d42bcb154157fbcf01bdd802cea19
 [INFO]      [exec] Status: Image is up to date for dockerregistry-stage.example.com/9999-998/9999_998-test_gitflow_docker/stage:1.0.7
 [INFO]      [exec] dedockerregistry-snapshot.de-gmbh.com/9999-998/9999_998-test_gitflow_docker/stage:1.0.7
 [INFO]      [exec] The push refers to repository [dedockerregistry-release.example.com/9999-998/9999_998-test_gitflow_docker]
 [INFO]      [exec] 002cb1823993: Preparing
 [INFO]      [exec] ae56c0c5405b: Preparing
 [INFO]      [exec] ae56c0c5405b: Layer already exists
 [INFO]      [exec] 002cb1823993: Layer already exists
 [INFO]      [exec] 1.0.7: digest: sha256:11f7c81a3214751ca43cecaa8a1077042b7d42bcb154157fbcf01bdd802cea19 size: 735
 [INFO] Executed tasks
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time:  4.791 s
 [INFO] Finished at: 2023-04-21T14:05:58+02:00
 [INFO] ------------------------------------------------------------------------ 
glimmerveen commented 1 year ago

I tested the retained execution in my docker gitworkflow example. It works. @glimmerveen thank you this feature.

@rhierlmeier : good to hear that it is working in your setup!