Replies: 1 comment
-
| 
         @EuSouVoce this feels close to the capability enabled by the  Using the flag looks something like this (if you are using the container version of 'mint'):   | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         @EuSouVoce this feels close to the capability enabled by the  Using the flag looks something like this (if you are using the container version of 'mint'):   | 
  
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've just used a Jenkins CI/CD job to read a
.mintkeepfile at the root of a project, build a Docker image, run Mint to slim it down, and then copy back every glob declared in.mintkeepbefore pushing the final image. It’s a tiny proof‑of‑concept, but I hope it helps anyone looking to add.mintkeepsupport to Mint itself (or to their own pipelines). Getting this into the official toolkit would be an awesome quality‑of‑life upgrade.Below is the trimmed file structure I used, followed by the minimal Jenkinsfile that handles the keep‑paths. This assumes the Jenkins agent already has the Docker CLI and that Mint is available as a container image (here I call
mintoolkit/mint:latestexplicitly).pipeline { agent any environment { IMAGE_NAME = 'example/mint-demo' BUILD_TAG = "${IMAGE_NAME}:${env.BUILD_NUMBER}" SLIM_TAG = "${IMAGE_NAME}:slim-${env.BUILD_NUMBER}" FINAL_TAG = "${IMAGE_NAME}:latest" MINT_IMAGE = 'mintoolkit/mint:latest' } stages { stage('Checkout') { steps { checkout scm } } stage('Resolve mint keep paths') { steps { script { def keepCsv = sh( script: ''' if [ -f .mintkeep ]; then awk ' NF && $1 !~ /^#/ { gsub(/\\r$/, ""); print $0 } ' .mintkeep | paste -sd "," - fi ''', returnStdout: true ).trim() env.SLIM_KEEP_PATHS = keepCsv if (!keepCsv) { echo 'No patterns found in .mintkeep; proceeding without keep paths.' } else { echo "Parsed keep paths: ${keepCsv}" } } } } stage('Build image') { steps { sh """ docker build -t ${BUILD_TAG} . """ } } stage('Run mint') { steps { sh """ docker run --rm \\ -v /var/run/docker.sock:/var/run/docker.sock \\ ${MINT_IMAGE} \\ --source ${BUILD_TAG} \\ --target ${SLIM_TAG} """ } } stage('Restore keep files') { when { expression { env.SLIM_KEEP_PATHS?.trim() } } steps { script { def patterns = env.SLIM_KEEP_PATHS.split(',') def prefixes = ['', '/app', '/workspace', '/usr/share/nginx/html'] for (pattern in patterns) { boolean restored = false for (prefix in prefixes) { def candidate = prefix ? "${prefix}${pattern}" : pattern def result = sh( script: """ set -e tmpdir=$(mktemp -d) docker create --name keep-src ${BUILD_TAG} >/dev/null if docker cp keep-src:${candidate} "${'$'}tmpdir/" 2>/dev/null; then tar -C "${'$'}tmpdir" -cf - . | docker cp - ${SLIM_TAG}:/ docker rm keep-src >/dev/null rm -rf "${'$'}tmpdir" exit 0 else docker rm keep-src >/dev/null rm -rf "${'$'}tmpdir" exit 1 fi """, returnStatus: true ) if (result == 0) { echo "Restored ${pattern} using prefix '${prefix}'." restored = true break } } if (!restored) { echo "Warning: pattern ${pattern} not found in source image." } } } } } stage('Tag & push') { steps { sh """ docker tag ${SLIM_TAG} ${BUILD_TAG} docker tag ${SLIM_TAG} ${FINAL_TAG} docker push ${BUILD_TAG} docker push ${FINAL_TAG} """ } } } post { always { sh """ docker image rm -f ${SLIM_TAG} ${BUILD_TAG} ${FINAL_TAG} || true """ } } }Feel free to adapt the prefixes list (add
/usr/src/app,/var/www, etc.) to match your Dockerfile layout. In this PoC the.mintkeepcan look like:The gist: parse
.mintkeep, turn it into a CSV, build once, slim the image, then run a lightweight restore loop that copies the requested paths from the original image into the Minted image. The logs show which patterns matched (and which didn’t), so contributors can spot missing assets quickly.Would love feedback—especially from anyone on the Mint side who’s interested in making
.mintkeepa first-class feature.Thanks for taking a look! Hope this helps someone out. 🙂
Cheers,
EuSouVoce
Beta Was this translation helpful? Give feedback.
All reactions