richardmaw-codethink pushed to branch jennis/docs_patch at BuildStream / buildstream
Commits:
-
9a045080
by Josh Smith at 2018-11-06T13:23:19Z
-
d3a07e6b
by Josh Smith at 2018-11-06T13:23:19Z
-
0c09fb9c
by richardmaw-codethink at 2018-11-06T14:12:20Z
-
b4eec489
by Jim MacArthur at 2018-11-06T16:44:14Z
-
1f7acf74
by Jim MacArthur at 2018-11-06T17:16:31Z
-
8e64ccef
by James Ennis at 2018-11-07T11:06:11Z
-
09ab676d
by James Ennis at 2018-11-07T11:06:11Z
-
f514124f
by James Ennis at 2018-11-07T11:06:11Z
7 changed files:
- buildstream/sandbox/_sandboxremote.py
- buildstream/utils.py
- doc/source/format_project.rst
- doc/source/using_config.rst
- doc/source/using_configuring_artifact_server.rst
- + tests/testutils/mock_os.py
- + tests/utils/misc.py
Changes:
| ... | ... | @@ -28,10 +28,7 @@ from ..storage._filebaseddirectory import FileBasedDirectory |
| 28 | 28 |
from ..storage._casbaseddirectory import CasBasedDirectory
|
| 29 | 29 |
from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
|
| 30 | 30 |
from .._protos.google.rpc import code_pb2
|
| 31 |
- |
|
| 32 |
- |
|
| 33 |
-class SandboxError(Exception):
|
|
| 34 |
- pass
|
|
| 31 |
+from .._exceptions import SandboxError
|
|
| 35 | 32 |
|
| 36 | 33 |
|
| 37 | 34 |
# SandboxRemote()
|
| ... | ... | @@ -634,7 +634,7 @@ def _parse_size(size, volume): |
| 634 | 634 |
|
| 635 | 635 |
# _pretty_size()
|
| 636 | 636 |
#
|
| 637 |
-# Converts a number of bytes into a string representation in KB, MB, GB, TB
|
|
| 637 |
+# Converts a number of bytes into a string representation in KiB, MiB, GiB, TiB
|
|
| 638 | 638 |
# represented as K, M, G, T etc.
|
| 639 | 639 |
#
|
| 640 | 640 |
# Args:
|
| ... | ... | @@ -646,10 +646,11 @@ def _parse_size(size, volume): |
| 646 | 646 |
def _pretty_size(size, dec_places=0):
|
| 647 | 647 |
psize = size
|
| 648 | 648 |
unit = 'B'
|
| 649 |
- for unit in ('B', 'K', 'M', 'G', 'T'):
|
|
| 649 |
+ units = ('B', 'K', 'M', 'G', 'T')
|
|
| 650 |
+ for unit in units:
|
|
| 650 | 651 |
if psize < 1024:
|
| 651 | 652 |
break
|
| 652 |
- else:
|
|
| 653 |
+ elif unit != units[-1]:
|
|
| 653 | 654 |
psize /= 1024
|
| 654 | 655 |
return "{size:g}{unit}".format(size=round(psize, dec_places), unit=unit)
|
| 655 | 656 |
|
| ... | ... | @@ -190,19 +190,34 @@ for more detail. |
| 190 | 190 |
Artifact server
|
| 191 | 191 |
~~~~~~~~~~~~~~~
|
| 192 | 192 |
If you have setup an :ref:`artifact server <artifacts>` for your
|
| 193 |
-project then it is convenient to configure this in your ``project.conf``
|
|
| 193 |
+project then it is convenient to configure the following in your ``project.conf``
|
|
| 194 | 194 |
so that users need not have any additional configuration to communicate
|
| 195 | 195 |
with an artifact share.
|
| 196 | 196 |
|
| 197 | 197 |
.. code:: yaml
|
| 198 | 198 |
|
| 199 |
+ #
|
|
| 200 |
+ # Artifacts
|
|
| 201 |
+ #
|
|
| 199 | 202 |
artifacts:
|
| 203 |
+ # A remote cache from which to download prebuilt artifacts
|
|
| 204 |
+ - url: https://foo.com/artifacts:11001
|
|
| 205 |
+ server.cert: server.crt
|
|
| 206 |
+ # A remote cache from which to upload/download built/prebuilt artifacts
|
|
| 207 |
+ - url: https://foo.com/artifacts:11002
|
|
| 208 |
+ server-cert: server.crt
|
|
| 209 |
+ client-cert: client.crt
|
|
| 210 |
+ client-key: client.key
|
|
| 200 | 211 |
|
| 201 |
- # A url from which to download prebuilt artifacts
|
|
| 202 |
- url: https://foo.com/artifacts
|
|
| 212 |
+.. note::
|
|
| 213 |
+ |
|
| 214 |
+ You can also specify a list of different caches here; earlier entries in the
|
|
| 215 |
+ list will have higher priority than later ones.
|
|
| 216 |
+ |
|
| 217 |
+The use of ports are required to distinguish between pull only access and
|
|
| 218 |
+push/pull access. For information regarding the server/client certificates
|
|
| 219 |
+and keys, please see: :ref:`Key pair for the server <server_authentication>`.
|
|
| 203 | 220 |
|
| 204 |
-You can also specify a list of caches here; earlier entries in the list
|
|
| 205 |
-will have higher priority than later ones.
|
|
| 206 | 221 |
|
| 207 | 222 |
Remote execution
|
| 208 | 223 |
~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -32,38 +32,75 @@ the supported configurations on a project wide basis are listed here. |
| 32 | 32 |
|
| 33 | 33 |
Artifact server
|
| 34 | 34 |
~~~~~~~~~~~~~~~
|
| 35 |
-The project you build will often specify a :ref:`remote artifact cache
|
|
| 36 |
-<artifacts>` already, but you may want to specify extra caches. There are two
|
|
| 37 |
-ways to do this. You can add one or more global caches:
|
|
| 35 |
+Although project's often specify a :ref:`remote artifact cache <artifacts>` in
|
|
| 36 |
+their ``project.conf``, you may also want to specify extra caches.
|
|
| 38 | 37 |
|
| 39 |
-**Example**
|
|
| 38 |
+Assuming that your host/server is reachable on the internet as ``artifacts.com``
|
|
| 39 |
+(for example), there are two ways to declare remote caches in your user
|
|
| 40 |
+configuration:
|
|
| 41 |
+ |
|
| 42 |
+1. Adding global caches:
|
|
| 40 | 43 |
|
| 41 | 44 |
.. code:: yaml
|
| 42 | 45 |
|
| 46 |
+ #
|
|
| 47 |
+ # Artifacts
|
|
| 48 |
+ #
|
|
| 43 | 49 |
artifacts:
|
| 44 |
- url: https://artifacts.com/artifacts
|
|
| 50 |
+ # Add a cache to pull from
|
|
| 51 |
+ - url: https://artifacts.com/artifacts:11001
|
|
| 52 |
+ server-cert: server.crt
|
|
| 53 |
+ # Add a cache to push/pull to/from
|
|
| 54 |
+ - url: https://artifacts.com/artifacts:11002
|
|
| 55 |
+ server-cert: server.crt
|
|
| 56 |
+ client-cert: client.crt
|
|
| 57 |
+ client-key: client.key
|
|
| 58 |
+ push: true
|
|
| 59 |
+ # Add another cache to pull from
|
|
| 60 |
+ - url: https://anothercache.com/artifacts:8080
|
|
| 61 |
+ server-cert: another_server.crt
|
|
| 62 |
+ |
|
| 63 |
+.. note::
|
|
| 45 | 64 |
|
| 46 |
-Caches listed there will be considered lower priority than those specified
|
|
| 47 |
-by the project configuration.
|
|
| 65 |
+ Caches declared here will be used by **all** BuildStream project's on the user's
|
|
| 66 |
+ machine and are considered a lower priority than those specified in the project
|
|
| 67 |
+ configuration.
|
|
| 48 | 68 |
|
| 49 |
-You can also add project-specific caches:
|
|
| 50 | 69 |
|
| 51 |
-**Example**
|
|
| 70 |
+2. Specifying caches for a specific project within the user configuration:
|
|
| 52 | 71 |
|
| 53 | 72 |
.. code:: yaml
|
| 54 | 73 |
|
| 55 | 74 |
projects:
|
| 56 | 75 |
project-name:
|
| 57 | 76 |
artifacts:
|
| 58 |
- - url: https://artifacts.com/artifacts1
|
|
| 59 |
- - url: ssh://user artifacts com/artifacts2
|
|
| 77 |
+ # Add a cache to pull from
|
|
| 78 |
+ - url: https://artifacts.com/artifacts:11001
|
|
| 79 |
+ server-cert: server.crt
|
|
| 80 |
+ # Add a cache to push/pull to/from
|
|
| 81 |
+ - url: https://artifacts.com/artifacts:11002
|
|
| 82 |
+ server-cert: server.crt
|
|
| 83 |
+ client-cert: client.crt
|
|
| 84 |
+ client-key: client.key
|
|
| 60 | 85 |
push: true
|
| 86 |
+ # Add another cache to pull from
|
|
| 87 |
+ - url: https://ourprojectcache.com/artifacts:8080
|
|
| 88 |
+ server-cert: project_server.crt
|
|
| 89 |
+ |
|
| 90 |
+ |
|
| 91 |
+.. note::
|
|
| 92 |
+ |
|
| 93 |
+ Caches listed here will be considered a higher priority than those specified
|
|
| 94 |
+ by the project. Furthermore, for a given list of URLs, earlier entries will
|
|
| 95 |
+ have higher priority.
|
|
| 96 |
+ |
|
| 97 |
+ |
|
| 98 |
+Notice that the use of different ports for the same server distinguishes between
|
|
| 99 |
+pull only access and push/pull access. For information regarding this and the
|
|
| 100 |
+server/client certificates and keys, please see:
|
|
| 101 |
+:ref:`Key pair for the server <server_authentication>`.
|
|
| 61 | 102 |
|
| 62 |
-Caches listed here will be considered higher priority than those specified
|
|
| 63 |
-by the project.
|
|
| 64 | 103 |
|
| 65 |
-If you give a list of URLs, earlier entries in the list will have higher
|
|
| 66 |
-priority than later ones.
|
|
| 67 | 104 |
|
| 68 | 105 |
Strict build plan
|
| 69 | 106 |
~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -98,6 +98,8 @@ Command reference |
| 98 | 98 |
:prog: bst-artifact-server
|
| 99 | 99 |
|
| 100 | 100 |
|
| 101 |
+.. _server_authentication:
|
|
| 102 |
+ |
|
| 101 | 103 |
Key pair for the server
|
| 102 | 104 |
~~~~~~~~~~~~~~~~~~~~~~~
|
| 103 | 105 |
|
| ... | ... | @@ -237,52 +239,12 @@ We can then check if the services are successfully running with: |
| 237 | 239 |
For more information on systemd services see:
|
| 238 | 240 |
`Creating Systemd Service Files <https://www.devdungeon.com/content/creating-systemd-service-files>`_.
|
| 239 | 241 |
|
| 240 |
-User configuration
|
|
| 241 |
-~~~~~~~~~~~~~~~~~~
|
|
| 242 |
-The user configuration for artifacts is documented with the rest
|
|
| 243 |
-of the :ref:`user configuration documentation <user_config>`.
|
|
| 244 |
- |
|
| 245 |
-Note that for self-signed certificates, the public key fields are mandatory.
|
|
| 246 |
- |
|
| 247 |
-Assuming you have the same setup used in this document, and that your
|
|
| 248 |
-host is reachable on the internet as ``artifacts.com`` (for example),
|
|
| 249 |
-then a user can use the following user configuration:
|
|
| 250 |
- |
|
| 251 |
-Pull-only:
|
|
| 252 |
- |
|
| 253 |
-.. code:: yaml
|
|
| 254 |
- |
|
| 255 |
- #
|
|
| 256 |
- # Artifacts
|
|
| 257 |
- #
|
|
| 258 |
- artifacts:
|
|
| 259 |
- |
|
| 260 |
- url: https://artifacts.com:11001
|
|
| 261 |
- |
|
| 262 |
- # Optional server certificate if not trusted by system root certificates
|
|
| 263 |
- server-cert: server.crt
|
|
| 242 |
+Declaring remote artifact caches
|
|
| 243 |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 244 |
+Remote artifact caches can be declared within either:
|
|
| 264 | 245 |
|
| 265 |
-Pull and push:
|
|
| 266 |
- |
|
| 267 |
-.. code:: yaml
|
|
| 268 |
- |
|
| 269 |
- #
|
|
| 270 |
- # Artifacts
|
|
| 271 |
- #
|
|
| 272 |
- artifacts:
|
|
| 273 |
- |
|
| 274 |
- url: https://artifacts.com:11002
|
|
| 275 |
- |
|
| 276 |
- # Optional server certificate if not trusted by system root certificates
|
|
| 277 |
- server-cert: server.crt
|
|
| 278 |
- |
|
| 279 |
- # Optional client key pair for authentication
|
|
| 280 |
- client-key: client.key
|
|
| 281 |
- client-cert: client.crt
|
|
| 282 |
- |
|
| 283 |
- push: true
|
|
| 284 |
- |
|
| 285 |
-.. note::
|
|
| 246 |
+1. The :ref:`project configuration <project_essentials_artifacts>`, or
|
|
| 247 |
+2. The :ref:`user configuration <config_artifacts>`.
|
|
| 286 | 248 |
|
| 287 |
- Equivalent statements can be delcared in a project's configuration file
|
|
| 288 |
- (the ``project.conf``).
|
|
| 249 |
+Please follow the above links to see examples showing how we declare remote
|
|
| 250 |
+caches in both the project configuration and the user configuration, respectively.
|
| 1 |
+from contextlib import contextmanager
|
|
| 2 |
+import os
|
|
| 3 |
+ |
|
| 4 |
+ |
|
| 5 |
+# MockAttributeResult
|
|
| 6 |
+#
|
|
| 7 |
+# A class to take a dictionary of kwargs and make them accessible via
|
|
| 8 |
+# attributes of the object.
|
|
| 9 |
+#
|
|
| 10 |
+class MockAttributeResult(dict):
|
|
| 11 |
+ __getattr__ = dict.get
|
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+# mock_statvfs():
|
|
| 15 |
+#
|
|
| 16 |
+# Gets a function which mocks statvfs and returns a statvfs result with the kwargs accessible.
|
|
| 17 |
+#
|
|
| 18 |
+# Returns:
|
|
| 19 |
+# func(path) -> object: object will have all the kwargs accessible via object.kwarg
|
|
| 20 |
+#
|
|
| 21 |
+# Example:
|
|
| 22 |
+# statvfs = mock_statvfs(f_blocks=10)
|
|
| 23 |
+# result = statvfs("regardless/of/path")
|
|
| 24 |
+# assert result.f_blocks == 10 # True
|
|
| 25 |
+def mock_statvfs(**kwargs):
|
|
| 26 |
+ def statvfs(path):
|
|
| 27 |
+ return MockAttributeResult(kwargs)
|
|
| 28 |
+ return statvfs
|
|
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+# monkey_patch()
|
|
| 32 |
+#
|
|
| 33 |
+# with monkey_patch("statvfs", custom_statvfs):
|
|
| 34 |
+# assert os.statvfs == custom_statvfs # True
|
|
| 35 |
+# assert os.statvfs == custom_statvfs # False
|
|
| 36 |
+#
|
|
| 37 |
+@contextmanager
|
|
| 38 |
+def monkey_patch(to_patch, patched_func):
|
|
| 39 |
+ orig = getattr(os, to_patch)
|
|
| 40 |
+ setattr(os, to_patch, patched_func)
|
|
| 41 |
+ try:
|
|
| 42 |
+ yield
|
|
| 43 |
+ finally:
|
|
| 44 |
+ setattr(os, to_patch, orig)
|
| 1 |
+from buildstream import _yaml
|
|
| 2 |
+from ..testutils import mock_os
|
|
| 3 |
+from ..testutils.runcli import cli
|
|
| 4 |
+ |
|
| 5 |
+import os
|
|
| 6 |
+import pytest
|
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+KiB = 1024
|
|
| 10 |
+MiB = (KiB * 1024)
|
|
| 11 |
+GiB = (MiB * 1024)
|
|
| 12 |
+TiB = (GiB * 1024)
|
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+def test_parse_size_over_1024T(cli, tmpdir):
|
|
| 16 |
+ BLOCK_SIZE = 4096
|
|
| 17 |
+ cli.configure({
|
|
| 18 |
+ 'cache': {
|
|
| 19 |
+ 'quota': 2048 * TiB
|
|
| 20 |
+ }
|
|
| 21 |
+ })
|
|
| 22 |
+ project = tmpdir.join("main")
|
|
| 23 |
+ os.makedirs(str(project))
|
|
| 24 |
+ _yaml.dump({'name': 'main'}, str(project.join("project.conf")))
|
|
| 25 |
+ |
|
| 26 |
+ bavail = (1025 * TiB) / BLOCK_SIZE
|
|
| 27 |
+ patched_statvfs = mock_os.mock_statvfs(f_bavail=bavail, f_bsize=BLOCK_SIZE)
|
|
| 28 |
+ with mock_os.monkey_patch("statvfs", patched_statvfs):
|
|
| 29 |
+ result = cli.run(project, args=["build", "file.bst"])
|
|
| 30 |
+ assert "1025T of available system storage" in result.stderr
|
