@Library("Pages")_

pipeline {
    agent any
        environment {
            WATCHTOWER_TOKEN = credentials("watchtower-token")
        }
    stages {
            stage('Cloning our Git') {
                steps {
                    checkout([$class: 'GitSCM',
                              branches: [[name: '*/master']],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'SubmoduleOption',
                                            disableSubmodules: false,
                                            parentCredentials: false,
                                            recursiveSubmodules: true,
                                            reference: '',
                                            trackingSubmodules: false]],
                              submoduleCfg: [],
                              userRemoteConfigs: [[url: 'https://git.tobiasmanske.de/user/rad4day/public/blog/']]])
                }
            }

            stage('Build HTML') {
                steps {
                    script {
                            docker.withRegistry('https://registry.chaoswg.org:5000', 'docker-registry-credentials') {
                                def dockerImage = docker.image('registry.chaoswg.org:5000/alpine-avif-webp:latest')
                                dockerImage.pull()
                            }
                    }

                    sh 'docker pull klakegg/hugo:alpine'

                    sh 'docker run --rm -v "$PWD:/src" registry.chaoswg.org:5000/alpine-avif-webp:latest'
                    sh 'docker run --rm -v "$PWD:/src" klakegg/hugo:alpine --minify'
                }
            }


            stage('Deploying Docker Image') {
                steps {
                    DeployPages("./docs", "tobiasmanske.de:latest")
                }
            }

            stage('Cleaning Up') {
                steps{
                  sh "docker rmi --force tobiasmanske.de:latest"
                  cleanWs()
                }
            }
        }
    }