pipeline {
    agent { label 'master' }

    stages {
        stage('Build') {
            parallel {
                stage('i686') {
                    agent {
                        docker {
                            label 'master'
                            image 'lyos_build'
                            args '-u root --privileged -v /var/www:/var/www'
                        }
                    }

                    stages {
                        stage('Build - i686') {
                            steps {
                                sh 'make SUBARCH=i686 defconfig'
                                sh 'make SUBARCH=i686 objdirs'
                                sh 'make SUBARCH=i686 install-headers'

                                dir('toolchain') {
                                    sh './download.sh'
                                    sh 'BUILD_EVERYTHING=true ./setup.sh -m i686'
                                }

                                ansiColor('xterm') {
                                    sh 'make SUBARCH=i686'
                                }

                                dir('toolchain') {
                                    sh 'BUILD_EVERYTHING=true ./setup-x11.sh -m i686'
                                    sh 'BUILD_EVERYTHING=true ./setup-extra.sh -m i686'
                                }
                            }
                        }

                        stage('Make image - i686') {
                            steps {
                                sh './scripts/setup-disk.sh -m i686'
                                sh 'mv lyos-disk-i686.img lyos-i686.img'
                                sh 'xz --fast lyos-i686.img'
                            }
                        }

                        stage('Collect - i686') {
                            steps {
                                sh 'cp lyos-i686.img.xz /var/www/lyos-build/nightly'
                                archiveArtifacts 'lyos-i686.img.xz'
                            }
                        }
                    }

                    post {
                        cleanup {
                            deleteDir()
                        }
                    }
                }
            }
        }
    }
}
