Page MenuHomeSoftware Heritage

D7479.id27135.diff
No OneTemporary

D7479.id27135.diff

diff --git a/jobs/swh-build-docker-image.yml b/jobs/swh-build-docker-image.yml
new file mode 100644
--- /dev/null
+++ b/jobs/swh-build-docker-image.yml
@@ -0,0 +1,22 @@
+- job-template:
+ name: "{name}/build-and-push"
+ description: Build the docker image and publish it to a registry
+ node: built-in
+ project-type: pipeline
+ dsl:
+ !include-jinja2: templates/swh-build-docker-image.groovy.j2
+
+ parameters:
+ - git-parameter:
+ name: TAG
+ description: Tag to build the image and then use as name
+ type: PT_BRANCH_TAG
+ sortMode: DESCENDING_SMART
+ selectedValue: TOP
+
+- project:
+ name: DLSMAVEXP
+ display-name: maven-index-exporter
+ repo_name: maven-index-exporter
+ jobs:
+ - "{name}/build-and-push"
diff --git a/jobs/swh-environment.yaml b/jobs/swh-environment.yaml
--- a/jobs/swh-environment.yaml
+++ b/jobs/swh-environment.yaml
@@ -17,7 +17,6 @@
url: https://forge.softwareheritage.org/source/swh-environment.git
branches:
- "*/master"
-
wrappers:
- timeout:
timeout: 90
diff --git a/jobs/templates/swh-build-docker-image.groovy.j2 b/jobs/templates/swh-build-docker-image.groovy.j2
new file mode 100644
--- /dev/null
+++ b/jobs/templates/swh-build-docker-image.groovy.j2
@@ -0,0 +1,51 @@
+def organization = "softwareheritage"
+def repo_name = "{{repo_name}}"
+def docker_image_name = "${organization}/${repo_name}"
+
+// Normalize to "latest" if we build from head commit (main or master)
+// Otherwise, keep the transmitted tag
+def tag = params.TAG
+def tag_name = ( tag == "origin/main" || tag == "origin/master" ) ? "latest" : tag
+
+def docker_image_with_tag = "${docker_image_name}:${tag_name}"
+
+// The following is configured in jenkins manually:
+// > Manage Jenkins > Configure System > Declarative pipeline (Docker)
+// Input the information in the form
+// Docker label: docker-io
+// Registry credentials: select the token created for the occasion in the docker hub
+// user (permissions required: Read / Write / Delete)
+// then click the 'Add' button
+def dockerCredentialsKeyID = 'docker-io'
+def registry = "https://registry-1.docker.io"
+
+node('built-in') {
+ stage ('pre-cleanup') {
+ cleanWs()
+ }
+ // Checkout repository
+ stage('Checkout') {
+ checkout([
+ $class: 'GitSCM',
+ branches: [[name: tag]],
+ userRemoteConfigs: [[
+ url: "https://forge.softwareheritage.org/source/${repo_name}/",
+ ]],
+ ])
+ }
+ def dockerImage
+ stage ('Build image') {
+ dockerImage = docker.build(
+ docker_image_with_tag,
+ "--pull --no-cache -f docker/Dockerfile docker"
+ )
+ }
+ with docker.withRegistry(registry, dockerCredentialsKeyID) {
+ stage ('Push image') {
+ dockerImage.push()
+ }
+ }
+ stage ('post-cleanup') {
+ cleanWs()
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mar 17 2025, 7:10 PM (7 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3232988

Event Timeline