pipeline {
    agent none
    stages {
        stage('Build PHP') {
            agent {
                docker {
                    image 'umanit/web:7.0'
                    args '-v $HOME/composer-cache:/tmp'
                }
            }
            steps {
                sh 'composer install --optimize-autoloader --prefer-dist --no-scripts'
            }
        }
        stage('Build assets') {
            agent {
                docker {
                    image 'node:12-alpine'
                    args '-v $HOME/.cache/yarn:/.cache/yarn'
                }
            }
            steps {
                sh 'yarn install'
                sh 'yarn run build:prod'
            }
        }
        stage('Generate artifacts') {
            agent {
                docker {
                    image 'node:12-alpine'
                }
            }
            steps {
                archiveArtifacts artifacts: 'web/assets/build/**/*', onlyIfSuccessful: true
            }
        }
    }
}
