Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

glimmerveen
Copy link
Contributor

@glimmerveen glimmerveen commented Apr 19, 2023

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

…rol to retain only specific execution of a plugin as well.
@bvarner
Copy link
Contributor

bvarner commented Apr 19, 2023

I really like this. Thanks!

@bvarner bvarner merged commit db0864b into e-gineering:development Apr 19, 2023
@glimmerveen glimmerveen deleted the feature/fine-grained-control-retain-plugin-executions-on-master branch April 19, 2023 16:15
@rhierlmeier
Copy link

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
Copy link

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
Copy link
Contributor Author

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!

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

Successfully merging this pull request may close these issues.

3 participants