← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad-buildd:shallow-git-clone-if-fetch-service into launchpad-buildd:master

 

Simone Pelosi has proposed merging ~pelpsi/launchpad-buildd:shallow-git-clone-if-fetch-service into launchpad-buildd:master.

Commit message:
If fetch-service is active use shallow git clone
    
Current builds with the fetch-service enabled would fail as the git
inspector of the fetch-service does not understand git clone but only
shallow clones.
We hide this feature under the use_fetch_service flag.


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad-buildd/+git/launchpad-buildd/+merge/474664
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad-buildd:shallow-git-clone-if-fetch-service into launchpad-buildd:master.
diff --git a/lpbuildd/target/build_rock.py b/lpbuildd/target/build_rock.py
index 3430ee5..a5405c2 100644
--- a/lpbuildd/target/build_rock.py
+++ b/lpbuildd/target/build_rock.py
@@ -121,9 +121,17 @@ class BuildRock(
         logger.info("Running repo phase...")
         env = self.build_proxy_environment(
             proxy_url=self.args.proxy_url,
-            use_fetch_service=self.args.use_fetch_service
+            use_fetch_service=self.args.use_fetch_service,
         )
-        self.vcs_fetch(self.args.name, cwd="/home/buildd", env=env)
+        if self.args.use_fetch_service:
+            self.vcs_fetch(
+                self.args.name,
+                cwd="/home/buildd",
+                env=env,
+                git_shallow_clone_with_single_branch=True,
+            )
+        else:
+            self.vcs_fetch(self.args.name, cwd="/home/buildd", env=env)
         self.vcs_update_status(self.buildd_path)
 
     def build(self):
@@ -134,7 +142,7 @@ class BuildRock(
         check_path_escape(self.buildd_path, build_context_path)
         env = self.build_proxy_environment(
             proxy_url=self.args.proxy_url,
-            use_fetch_service=self.args.use_fetch_service
+            use_fetch_service=self.args.use_fetch_service,
         )
         args = ["rockcraft", "pack", "-v", "--destructive-mode"]
         self.run_build_command(args, env=env, cwd=build_context_path)
diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
index 4c184ba..98ee383 100644
--- a/lpbuildd/target/build_snap.py
+++ b/lpbuildd/target/build_snap.py
@@ -179,9 +179,17 @@ class BuildSnap(
         logger.info("Running repo phase...")
         env = self.build_proxy_environment(
             proxy_url=self.args.proxy_url,
-            use_fetch_service=self.args.use_fetch_service
+            use_fetch_service=self.args.use_fetch_service,
         )
-        self.vcs_fetch(self.args.name, cwd="/build", env=env)
+        if self.args.use_fetch_service:
+            self.vcs_fetch(
+                self.args.name,
+                cwd="/build",
+                env=env,
+                git_shallow_clone_with_single_branch=True,
+            )
+        else:
+            self.vcs_fetch(self.args.name, cwd="/build", env=env)
         self.vcs_update_status(os.path.join("/build", self.args.name))
 
     @property
@@ -200,7 +208,7 @@ class BuildSnap(
         logger.info("Running pull phase...")
         env = self.build_proxy_environment(
             proxy_url=self.args.proxy_url,
-            use_fetch_service=self.args.use_fetch_service
+            use_fetch_service=self.args.use_fetch_service,
         )
         env["SNAPCRAFT_LOCAL_SOURCES"] = "1"
         env["SNAPCRAFT_SETUP_CORE"] = "1"
@@ -249,7 +257,7 @@ class BuildSnap(
         logger.info("Running build phase...")
         env = self.build_proxy_environment(
             proxy_url=self.args.proxy_url,
-            use_fetch_service=self.args.use_fetch_service
+            use_fetch_service=self.args.use_fetch_service,
         )
         if not self.args.private:
             env["SNAPCRAFT_BUILD_INFO"] = "1"
diff --git a/lpbuildd/target/tests/test_build_rock.py b/lpbuildd/target/tests/test_build_rock.py
index ddcb6d9..81e1ebc 100644
--- a/lpbuildd/target/tests/test_build_rock.py
+++ b/lpbuildd/target/tests/test_build_rock.py
@@ -257,9 +257,7 @@ class TestBuildRock(TestCase):
         )
         self.assertEqual(
             (b"proxy script\n", stat.S_IFREG | 0o755),
-            build_rock.backend.backend_fs[
-                "/usr/local/bin/lpbuildd-git-proxy"
-            ],
+            build_rock.backend.backend_fs["/usr/local/bin/lpbuildd-git-proxy"],
         )
 
     def test_install_certificate(self):
@@ -354,9 +352,7 @@ class TestBuildRock(TestCase):
                 ).encode("UTF-8"),
                 stat.S_IFREG | 0o644,
             ),
-            build_rock.backend.backend_fs[
-                "/etc/apt/apt.conf.d/99proxy"
-            ],
+            build_rock.backend.backend_fs["/etc/apt/apt.conf.d/99proxy"],
         )
 
     def test_install_snapd_proxy(self):
@@ -442,9 +438,7 @@ class TestBuildRock(TestCase):
                 ).encode("UTF-8"),
                 stat.S_IFREG | 0o644,
             ),
-            build_rock.backend.backend_fs[
-                "/etc/apt/apt.conf.d/99proxy"
-            ],
+            build_rock.backend.backend_fs["/etc/apt/apt.conf.d/99proxy"],
         )
 
     def test_install_fetch_service(self):
@@ -475,9 +469,19 @@ class TestBuildRock(TestCase):
         self.assertThat(
             build_rock.backend.run.calls,
             MatchesAll(
-                Not(AnyMatch(RanCommand(
-                    ["git", "config", "--global", "protocol.version", "2"]
-                ))),
+                Not(
+                    AnyMatch(
+                        RanCommand(
+                            [
+                                "git",
+                                "config",
+                                "--global",
+                                "protocol.version",
+                                "2",
+                            ]
+                        )
+                    )
+                ),
             ),
         )
 
@@ -509,9 +513,11 @@ class TestBuildRock(TestCase):
         self.assertThat(
             build_rock.backend.run.calls,
             MatchesAll(
-                AnyMatch(RanCommand(
-                    ["git", "config", "--global", "protocol.version", "2"]
-                )),
+                AnyMatch(
+                    RanCommand(
+                        ["git", "config", "--global", "protocol.version", "2"]
+                    )
+                ),
             ),
         )
 
@@ -766,6 +772,83 @@ class TestBuildRock(TestCase):
         with open(status_path) as status:
             self.assertEqual({"revision_id": "0" * 40}, json.load(status))
 
+    def test_repo_fetch_service(self):
+        args = [
+            "build-rock",
+            "--backend=fake",
+            "--series=xenial",
+            "--arch=amd64",
+            "1",
+            "--git-repository",
+            "lp:foo",
+            "--proxy-url",
+            "http://proxy.example:3128/";,
+            "test-image",
+            "--use_fetch_service",
+        ]
+        build_rock = parse_args(args=args).operation
+        build_rock.backend.build_path = self.useFixture(TempDir()).path
+        build_rock.backend.run = FakeRevisionID("0" * 40)
+        build_rock.repo()
+        env = {
+            "http_proxy": "http://proxy.example:3128/";,
+            "https_proxy": "http://proxy.example:3128/";,
+            "GIT_PROXY_COMMAND": "/usr/local/bin/lpbuildd-git-proxy",
+            "SNAPPY_STORE_NO_CDN": "1",
+            "CARGO_HTTP_CAINFO": (
+                "/usr/local/share/ca-certificates/local-ca.crt"
+            ),
+            "GOPROXY": "direct",
+        }
+        self.assertThat(
+            build_rock.backend.run.calls,
+            MatchesListwise(
+                [
+                    RanBuildCommand(
+                        [
+                            "git",
+                            "clone",
+                            "-n",
+                            "--depth",
+                            "1",
+                            "-b",
+                            "HEAD",
+                            "--single-branch",
+                            "lp:foo",
+                            "test-image",
+                        ],
+                        cwd="/home/buildd",
+                        **env,
+                    ),
+                    RanBuildCommand(
+                        ["git", "checkout", "-q", "HEAD"],
+                        cwd="/home/buildd/test-image",
+                        **env,
+                    ),
+                    RanBuildCommand(
+                        [
+                            "git",
+                            "submodule",
+                            "update",
+                            "--init",
+                            "--recursive",
+                        ],
+                        cwd="/home/buildd/test-image",
+                        **env,
+                    ),
+                    RanBuildCommand(
+                        ["git", "rev-parse", "HEAD^{}"],
+                        cwd="/home/buildd/test-image",
+                        get_output=True,
+                        universal_newlines=True,
+                    ),
+                ]
+            ),
+        )
+        status_path = os.path.join(build_rock.backend.build_path, "status")
+        with open(status_path) as status:
+            self.assertEqual({"revision_id": "0" * 40}, json.load(status))
+
     def test_build(self):
         args = [
             "build-rock",
@@ -878,10 +961,10 @@ class TestBuildRock(TestCase):
             "https_proxy": "http://proxy.example:3128/";,
             "GIT_PROXY_COMMAND": "/usr/local/bin/lpbuildd-git-proxy",
             "SNAPPY_STORE_NO_CDN": "1",
-            'CARGO_HTTP_CAINFO': (
-                '/usr/local/share/ca-certificates/local-ca.crt'
+            "CARGO_HTTP_CAINFO": (
+                "/usr/local/share/ca-certificates/local-ca.crt"
             ),
-            'GOPROXY': 'direct',
+            "GOPROXY": "direct",
         }
         self.assertThat(
             build_rock.backend.run.calls,
@@ -1050,7 +1133,5 @@ class TestBuildRock(TestCase):
         ]
         build_rock = parse_args(args=args).operation
         build_rock.buildd_path = self.useFixture(TempDir()).path
-        os.symlink(
-            "/etc/hosts", os.path.join(build_rock.buildd_path, "build")
-        )
+        os.symlink("/etc/hosts", os.path.join(build_rock.buildd_path, "build"))
         self.assertRaises(InvalidBuildFilePath, build_rock.build)
diff --git a/lpbuildd/target/tests/test_build_snap.py b/lpbuildd/target/tests/test_build_snap.py
index 78ed3dc..5c721f9 100644
--- a/lpbuildd/target/tests/test_build_snap.py
+++ b/lpbuildd/target/tests/test_build_snap.py
@@ -289,9 +289,7 @@ class TestBuildSnap(TestCase):
                 ).encode("UTF-8"),
                 stat.S_IFREG | 0o644,
             ),
-            build_snap.backend.backend_fs[
-                "/etc/apt/apt.conf.d/99proxy"
-            ],
+            build_snap.backend.backend_fs["/etc/apt/apt.conf.d/99proxy"],
         )
 
     def test_install_snapd_proxy(self):
@@ -380,9 +378,7 @@ class TestBuildSnap(TestCase):
                 ).encode("UTF-8"),
                 stat.S_IFREG | 0o644,
             ),
-            build_snap.backend.backend_fs[
-                "/etc/apt/apt.conf.d/99proxy"
-            ],
+            build_snap.backend.backend_fs["/etc/apt/apt.conf.d/99proxy"],
         )
 
     def test_install_channels(self):
@@ -440,9 +436,19 @@ class TestBuildSnap(TestCase):
         self.assertThat(
             build_snap.backend.run.calls,
             MatchesAll(
-                Not(AnyMatch(RanCommand(
-                    ["git", "config", "--global", "protocol.version", "2"]
-                ))),
+                Not(
+                    AnyMatch(
+                        RanCommand(
+                            [
+                                "git",
+                                "config",
+                                "--global",
+                                "protocol.version",
+                                "2",
+                            ]
+                        )
+                    )
+                ),
             ),
         )
 
@@ -466,9 +472,11 @@ class TestBuildSnap(TestCase):
         self.assertThat(
             build_snap.backend.run.calls,
             MatchesAll(
-                AnyMatch(RanCommand(
-                    ["git", "config", "--global", "protocol.version", "2"]
-                )),
+                AnyMatch(
+                    RanCommand(
+                        ["git", "config", "--global", "protocol.version", "2"]
+                    )
+                ),
             ),
         )
 
@@ -751,7 +759,18 @@ class TestBuildSnap(TestCase):
             MatchesListwise(
                 [
                     RanBuildCommand(
-                        ["git", "clone", "-n", "lp:foo", "test-snap"],
+                        [
+                            "git",
+                            "clone",
+                            "-n",
+                            "--depth",
+                            "1",
+                            "-b",
+                            "HEAD",
+                            "--single-branch",
+                            "lp:foo",
+                            "test-snap",
+                        ],
                         cwd="/build",
                         **env,
                     ),