summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Anderson <17242663+blue42u@users.noreply.github.com>2023-07-12 16:03:10 -0500
committerGitHub <noreply@github.com>2023-07-12 21:03:10 +0000
commit90208da8a5035d3f2531f32fc763a889ed09b624 (patch)
tree56eda6d2e86189912f6ea41291ee313a5248bdff
parentc8026c3c87efe86b87913463708f076516d59328 (diff)
downloadspack-90208da8a5035d3f2531f32fc763a889ed09b624.tar.gz
spack-90208da8a5035d3f2531f32fc763a889ed09b624.tar.bz2
spack-90208da8a5035d3f2531f32fc763a889ed09b624.tar.xz
spack-90208da8a5035d3f2531f32fc763a889ed09b624.zip
containers: retain shallow git data (#37734)
-rw-r--r--lib/spack/spack/container/images.py14
-rw-r--r--lib/spack/spack/test/container/cli.py6
-rw-r--r--share/spack/templates/container/bootstrap-base.dockerfile2
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/spack/spack/container/images.py b/lib/spack/spack/container/images.py
index 130adaffdb..476fbab1db 100644
--- a/lib/spack/spack/container/images.py
+++ b/lib/spack/spack/container/images.py
@@ -5,6 +5,7 @@
"""Manages the details on the images used in the various stages."""
import json
import os.path
+import shlex
import sys
import llnl.util.filesystem as fs
@@ -130,8 +131,11 @@ def checkout_command(url, ref, enforce_sha, verify):
if enforce_sha or verify:
ref = _verify_ref(url, ref, enforce_sha)
- command = (
- "git clone {0} . && git fetch origin {1}:container_branch &&"
- " git checkout container_branch "
- ).format(url, ref)
- return command
+ return " && ".join(
+ [
+ "git init --quiet",
+ f"git remote add origin {shlex.quote(url)}",
+ f"git fetch --depth=1 origin {shlex.quote(ref)}",
+ "git checkout --detach FETCH_HEAD",
+ ]
+ )
diff --git a/lib/spack/spack/test/container/cli.py b/lib/spack/spack/test/container/cli.py
index 8353514b70..1ccd47d002 100644
--- a/lib/spack/spack/test/container/cli.py
+++ b/lib/spack/spack/test/container/cli.py
@@ -41,5 +41,7 @@ def test_bootstrap_phase(minimal_configuration, config_dumper, capsys):
with fs.working_dir(spack_yaml_dir):
output = containerize()
- # Check for the presence of the clone command
- assert "git clone" in output
+ # Check for the presence of the Git commands
+ assert "git init" in output
+ assert "git fetch" in output
+ assert "git checkout" in output
diff --git a/share/spack/templates/container/bootstrap-base.dockerfile b/share/spack/templates/container/bootstrap-base.dockerfile
index e002cce02e..ac069bbe37 100644
--- a/share/spack/templates/container/bootstrap-base.dockerfile
+++ b/share/spack/templates/container/bootstrap-base.dockerfile
@@ -23,7 +23,7 @@ RUN ln -s $SPACK_ROOT/share/spack/docker/entrypoint.bash \
RUN mkdir -p /root/.spack \
&& cp $SPACK_ROOT/share/spack/docker/modules.yaml \
/root/.spack/modules.yaml \
- && rm -rf /root/*.* /run/nologin $SPACK_ROOT/.git
+ && rm -rf /root/*.* /run/nologin
# [WORKAROUND]
# https://superuser.com/questions/1241548/