#!/usr/bin/env groovy

String getLatestSnapshot(repository_stem) {
    def script = """
        aptly snapshot list --sort=time --raw \
            | grep -E '^${repository_stem}-' \
            | tail -n1
    """

    return sh(returnStdout: true, script: script).trim()
}

def installGpgKeyring() {
    sh """
       install -d -m 700 -o root -g root /var/lib/aptly/.gnupg
       tar -C /var/lib/aptly/.gnupg -zxf /var/lib/aptly/keyring/release-keyring.tar.gz
       chown -R root:root /var/lib/aptly/.gnupg
       find /var/lib/aptly/.gnupg -type d -exec chmod 700 '{}' ';'
       find /var/lib/aptly/.gnupg -type f -exec chmod 600 '{}' ';'
       """
}

def workspacePath = "/home/jenkins/workspace"
def buildLabel = "task.publish.unstable-${UUID.randomUUID().toString()}"
def sourcePath = "${workspacePath}/src"

// FIXME(jtgans): Get rid of privileged! This is a security risk!
def jnlpContainer = containerTemplate(name: 'jnlp',
                                      image: 'jenkins/jnlp-slave:alpine')
def debianContainer = containerTemplate(name: 'debian',
                                        image: 'gcr.io/mendel-linux-cloud-infra/mendel-builder:latest',
                                        command: 'cat',
                                        args: '',
                                        ttyEnabled: true,
                                        privileged: true,
                                        alwaysPullImage: true)
def aptlyVolume = persistentVolumeClaim(claimName: 'aptly-state', mountPath: '/var/lib/aptly')
def gpgVolume = secretVolume(secretName: 'mendel-release-credentials', mountPath: '/var/lib/aptly/keyring')

def boards = [
    "enterprise",
    "excelsior"
]

podTemplate(label: buildLabel, containers: [jnlpContainer, debianContainer], volumes: [aptlyVolume, gpgVolume], envVars: []) {
    node(buildLabel) {
        dir(sourcePath) {
            container('debian') {
                sh "cp /etc/aptly.conf ~/.aptly.conf"
                withEnv(['GNUPGHOME=/var/lib/aptly/.gnupg']) {
                    def debianMainMirrorSnapshotName = getLatestSnapshot('debian-buster')
                    def debianContribMirrorSnapshotName = getLatestSnapshot('debian-buster-contrib')
                    def debianNonfreeMirrorSnapshotName = getLatestSnapshot('debian-buster-nonfree')
                    def coreSnapshotName = getLatestSnapshot('unstable-core')
                    def date = new Date()
                    String stamp = date.format("yyyyMMdd-HHmmss")

                    installGpgKeyring()

                    sh """
                       aptly snapshot merge core-full-unstable-${stamp} ${debianMainMirrorSnapshotName} ${debianContribMirrorSnapshotName} ${debianNonfreeMirrorSnapshotName} ${coreSnapshotName}
                       aptly publish snapshot --batch --force-overwrite --passphrase-file=/var/lib/aptly/keyring/passphrase.txt --architectures=source,amd64,arm64,armhf --distribution=unstable core-full-unstable-${stamp} filesystem:public:unstable
                       """

                    for (board in boards) {
                        def bspSnapshotName  = getLatestSnapshot("unstable-bsp-${board}")
                        sh "aptly publish snapshot --batch --force-overwrite --passphrase-file=/var/lib/aptly/keyring/passphrase.txt --architectures=source,amd64,arm64,armhf --distribution=unstable ${bspSnapshotName} filesystem:public:unstable-bsp-${board}"
                    }
                }
            }
        }
    }
}
