92 lines
3.0 KiB
Groovy
92 lines
3.0 KiB
Groovy
#!groovy
|
|
|
|
def repository = "registry.c.test-chamber-13.lan"
|
|
def repositoryCreds = "harbor-repository-creds"
|
|
|
|
def workspace
|
|
def dockerFile
|
|
def dockerScript
|
|
|
|
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
|
def templateName = "pipeline-worker"
|
|
pipeline {
|
|
agent {
|
|
kubernetes {
|
|
yaml functions.podYaml(
|
|
repo: repository,
|
|
templateName: templateName,
|
|
kaniko: true
|
|
)
|
|
}
|
|
}
|
|
|
|
stages {
|
|
stage ('Initalize Jenkins') {
|
|
steps {
|
|
script {
|
|
workspace = pwd()
|
|
def calibreVer = "5.40.0"
|
|
dockerFile = """FROM ${repository}/dockerhub/library/ubuntu:focal
|
|
|
|
LABEL org.opencontainers.image.authors="The_Spider <spider@smoothnet.org>"
|
|
LABEL org.opencontainers.image.title="calibre"
|
|
LABEL org.opencontainers.image.description="Docker container for converting ebooks"
|
|
LABEL org.opencontainers.image.base.name="docker.io/library/ubuntu:focal"
|
|
|
|
COPY entrypoint.sh /calibre/entrypoint.sh
|
|
|
|
RUN apt-get update && \\
|
|
apt-get upgrade -y && \\
|
|
apt-get install -y --no-install-recommends curl xz-utils libgl1 libxcb1 && \\
|
|
apt-get clean && \\
|
|
chmod +x /calibre/entrypoint.sh && \\
|
|
mkdir -p /opt/calibre && \\
|
|
curl -Lks "https://nexus.c.test-chamber-13.lan/repository/calibre/${calibreVer}/calibre-${calibreVer}-x86_64.txz" -o /tmp/calibre.tar.xz && \\
|
|
tar -J -x -f /tmp/calibre.tar.xz -C /opt/calibre && \\
|
|
rm -f /tmp/calibre.tar.xz
|
|
|
|
ENTRYPOINT ["/bin/bash", "-c", "/calibre/entrypoint.sh"]
|
|
"""
|
|
dockerScript = """#!/usr/bin/env bash
|
|
|
|
IFS=\$'\\n'
|
|
|
|
while true; do
|
|
sleep 5s
|
|
if [ ! -z "\$(find /calibre/input -type f \\( -iname "*.mobi" -o -iname "*.epub" -o -iname "*.prc" \\) -print -quit)" ]; then
|
|
for i in \$(find /calibre/input -type f \\( -iname "*.mobi" -o -iname "*.epub" -o -iname "*.prc" \\)); do
|
|
/opt/calibre/ebook-convert "\${i}" "/calibre/output/\$(basename \${i%.*}.azw3)"
|
|
rm -f -v "\${i}"
|
|
done
|
|
fi
|
|
done
|
|
"""
|
|
|
|
writeFile(file: workspace + "/entrypoint.sh", text: dockerScript)
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Build & Push') {
|
|
steps {
|
|
container ('kaniko') {
|
|
script {
|
|
declarativeFunctions.buildContainerMultipleDestinations(
|
|
dockerFile: dockerFile,
|
|
repositoryAccess: [
|
|
[
|
|
repository: repository,
|
|
credentials: repositoryCreds
|
|
],
|
|
],
|
|
destination: [
|
|
"${repository}/library/calibre:latest",
|
|
]
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|