node {
    def app

    stage('Clone repository') {
        /* Let's make sure we have the repository cloned to our workspace */

        checkout scm
    }

    stage('Build image') {
        /* This builds the actual image; synonymous to
         * docker build on the command line */

        app = docker.build("thisfro/plantex")
    }

    stage('Test image') {
        /* Ideally, we would run a test framework against our image.
         * For this example, we're using a Volkswagen-type approach ;-) */

        app.inside {
            // php 'bin/phpunit'
            sh 'echo "success"'
        }
    }

    stage('Push image') {
        docker.withRegistry('https://hub.thisfro.ch') {
            app.push("$BUILD_NUMBER")            
            app.push('latest')       
        }    
    }

    stage('Deploy staging') {
        sh 'cd /opt/containers/pflaenz.li && docker-compose pull && docker-compose up -d'
    }
}