pipeline {
    agent {
        docker {
            image 'jvconseil/jekyll-docker'
            args '''
                -u root:root
                -v "${PWD}:/srv"
                -e JEKYLL_UID=1001 -e JEKYLL_GID=1001
                '''
        }
    }
    environment {
        KEY_FILE = credentials('ubuntu-box.myemail.cloud')
    }
    stages {
        stage('Prep') {
            steps {
                sh 'apk add curl'
                sh 'chmod -R 777 .'
                sh 'gem install bundler'
                sh 'curl -d "robertjohnson.work Prep stage done." https://ntfy.draft13.com/jenkins'
            }
        }
        stage('Build') {
            steps {
                sh 'bundle install'
                sh 'bundle exec jekyll build'
                sh 'curl -d "robertjohnson.work Build stage done." https://ntfy.draft13.com/jenkins'
            }
        }
        stage('Deploy') {
            steps {
                sh 'scp -r -o StrictHostKeychecking=no -i $KEY_FILE _site/ ubuntu@box.myemail.cloud:/home/ubuntu'
                sh 'ssh ubuntu@box.myemail.cloud -i $KEY_FILE \'bash -s\' < deploy.sh'
                sh 'curl -d "robertjohnson.work Deploy stage done." https://ntfy.draft13.com/jenkins'
            }
        }
    }
}