From 163e2e9f83a79def2d7bfda6b2b6609cfa02c1b2 Mon Sep 17 00:00:00 2001
From: Vitaliy Potyarkin <v.potyarkin@yadro.com>
Date: Mon, 24 Mar 2025 17:04:24 +0300
Subject: [PATCH] ci: Cache pre-commit installations on Jenkins Agent

This change introduces a custom helper from our shared library [0]
that defines ad-hoc container environment to execute CI steps in.

Pre-commit installation will now be cached on Jenkins Agent: builds will
tolerate network hiccups better and we will also save some run time
(although on non-critical path of a parallel process).

[0]: https://git.frostfs.info/TrueCloudLab/jenkins/pulls/8

Change-Id: I93b01f169c457aa35f4d8bc5b90f31b31e2bd8b2
Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
---
 .ci/Jenkinsfile | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile
index e21ce61c5..166fb9286 100644
--- a/.ci/Jenkinsfile
+++ b/.ci/Jenkinsfile
@@ -68,12 +68,14 @@ async {
     }
 
     task('pre-commit') {
-        sh '''
-            apt update
-            apt install -y --no-install-recommends pre-commit
-        ''' // TODO: Make an OCI image for pre-commit + golang? Unpack golang tarball with a library function?
-        withEnv(['SKIP=make-lint,go-staticcheck-repo-mod,go-unit-tests,gofumpt']) {
-            sh 'pre-commit run --color=always --hook-stage=manual --all-files'
+        dockerfile("""
+            FROM ${golangDefault}
+            RUN apt update && \
+                apt install -y --no-install-recommends pre-commit
+        """) {
+            withEnv(['SKIP=make-lint,go-staticcheck-repo-mod,go-unit-tests,gofumpt']) {
+                sh 'pre-commit run --color=always --hook-stage=manual --all-files'
+            }
         }
     }
 }