jenkins: automate uploading of Alpine release image
@@ -29,6 +29,12 @@ properties([
description: 'Fedora package revision.',
name: 'fedora_revision',
trim: true
+ ),
+ string(
+ defaultValue: '1',
+ description: 'Alpine Docker image revision.',
+ name: 'alpine_revision',
+ trim: true
)
])
])
@@ -158,6 +164,16 @@ def dockerInit() {
'./scripts/docker/debian/buster',
'./scripts/docker/debian/buster/doc.Dockerfile'
)
+
+ /*
+ * Alpine release image with installed Elektra
+ */
+ DOCKER_IMAGES.alpine_release = createDockerImageDescForRelease(
+ 'elektra/elektra', this.&idRelease,
+ './scripts/docker/alpine/*',
+ './scripts/docker/alpine/*/release.Dockerfile',
+ false
+ )
}
}
@@ -325,6 +341,12 @@ def generatePublishStages() {
// debian-buster release stage
tasks << publishMainRepo('debian-buster')
+ tasks << publishImageToDockerHub(
+ 'publish-alpine',
+ DOCKER_IMAGES.alpine_release,
+ params.alpine_revision
+ )
+
return tasks
}
@@ -621,6 +643,76 @@ tar -zxvf ${WORKSPACE}/artifacts/${artifactStageName}/${artifactStageName}-relea
}
}
+/**
+ * Builds and publishes an image to the official Docker Hub.
+ *
+ * The image is tagged with a version number and additional
+ * with 'latest'.
+ *
+ * @param stageName name of the stage
+ * @param image image to be build and pushed
+ * @param imageRevision revision number of the image
+ */
+def publishImageToDockerHub(stageName, image, imageRevision='1') {
+ return [(stageName): {
+ stage(stageName) {
+ node(PipelineConfig.instance.dockerNodeLabel) {
+ checkout scm
+ docker.withRegistry('',
+ 'docker-hub-official-elektrabot') {
+ def cpus = dockerUtils.cpuCount()
+ def i = docker.build(
+ image.id,"""\
+--pull \
+--build-arg PARALLEL=${cpus} \
+-f ${image.file} ${image.context}"""
+ )
+
+ def dockerVersionTag = "${RELEASE_VERSION}-${imageRevision}"
+ i.push(dockerVersionTag)
+ i.push('latest')
+ }
+ }
+ }
+ }]
+}
+
+/**
+ * Create a new Docker Image description for images published to official
+ * Docker Hub
+ *
+ * @param name Name of the image
+ * @param idFun Closure describing how the image id should be formatted
+ * (see idTesting() / idArtifact())
+ * @param context Build context for the docker build (base directory that will
+ * be sent to the docker agent). Relative to the current working
+ * directory.
+ * @param file Path to Dockerfile relative to the current working directory.
+ * @param autobuild If it should be automatically build at the start of the
+ * Jenkins run. If false it can be build manually
+ * (see buildImageStage()).
+ */
+def createDockerImageDescForRelease(name, idFun, context, file, autobuild=true) {
+ def map = [
+ name: name,
+ context: context,
+ file: file,
+ autobuild: autobuild,
+ exists: false
+ ]
+ return idFun(map)
+}
+
+/**
+ * Build id for artifact for release images without tagging it.
+ *
+ * @param imageMap Map identifying an docker image
+ */
+def idRelease(imageMap) {
+ imageMap.id = "${imageMap.name}"
+ return imageMap
+}
+
/**
* Push git repo
* Currently the best way according to
