Giter Club home page Giter Club logo

maven-3-git-alpine-docker-image's Introduction

maven-3-git-alpine-docker-image

Docker image that might be used by CI/CD servers to execute the release of project artifacts [by maven-release-plugin].

Motivation

DevOps is a popular field nowadays where engineers spending lots of time automating\enhancing continuous delivery process. Many CI/CD servers have built-in capabilities to develop CD pipelines. For instance Jenkins has a concept of Pipeline as code or defining the deployment pipeline through code rather than configuring a running CI/CD tool, provides tremendous benefits for teams automating infrastructure across their environments.

Docker is very handy tool these days. CI/CD servers might spin up actual docker containers where CI/CD jobs take place.

Say you were given to design\implement CD pipeline for JVM based projects. Maven is a super popular build/automation tool - so why not to take advantage out of it ? There is the maven-release-plugin allowing you to release project with maven, saving a lot of repetitive, manual work.

So you want to:

  • utilize maven-release-plugin
  • and run release job by Jenkins agent
  • where the entire pipeline, or a specific stage, will get executed within docker container.
  • how ?

How

There's already available docker image maven:3-alpine that you might use ... but it does NOT have git installed which is required by maven-release-plugin. In order to let maven-release-plugin push changes to your Git server you have to connect your docker container runtime with Git server. This can be done via SSH:

  • deploy your public key to GIT server.
  • normally private key will be available under ~/.ssh/id_rsa
  • build docker image docker build -t git-maven:3-alpine -f Dockerfile . Make sure private key was added to /root/.ssh/id_rsa

Now your newly built docker image is ready to release projects via maven-release-plugin. Appropriate Jenkins Pipeline might look like :

pipeline {
    agent {
        docker {
            image 'git-maven:3-alpine'
            args '-v /root/.m2:/root/.m2 --network=host'
        }
    }
    
    parameters {
        string defaultValue: '', description: 'Release Version.', name: 'releaseVersion', trim: true
        string defaultValue: '', description: 'Next Devevelopment Version.', name: 'developmentVersion', trim: true
    }
    stages {
        stage('Checkout') {
            steps {
               checkout([$class: 'GitSCM', 
						branches: [[name: 'origin/master']], 
						doGenerateSubmoduleConfigurations: false,  extensions: [[$class: 'LocalBranch', localBranch: 'master']], 
						submoduleCfg: [], 
						userRemoteConfigs: [[credentialsId: 'yourCredsId', url: 'https://github.com/[username]/[project]']]])
            }
        }
        stage('Release') {
            steps {
                sh 'mvn release:clean release:prepare release:perform -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}'
            }
        }
    }
}

Voilà!

maven-3-git-alpine-docker-image's People

Contributors

romalev avatar

Stargazers

 avatar  avatar

Forkers

jamesdube

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.