[Notes] [Git][BuildStream/buildstream][Qinusty/491] 7 commits: cascache.py: Raise ArtifactError on grpc error



Title: GitLab

Qinusty pushed to branch Qinusty/491 at BuildStream / buildstream

Commits:

5 changed files:

Changes:

  • README.rst
    ... ... @@ -25,7 +25,7 @@ BuildStream offers the following advantages:
    25 25
     
    
    26 26
     * **Declarative build instructions/definitions**
    
    27 27
     
    
    28
    -  BuildStream provides a a flexible and extensible framework for the modelling
    
    28
    +  BuildStream provides a flexible and extensible framework for the modelling
    
    29 29
       of software build pipelines in a declarative YAML format, which allows you to
    
    30 30
       manipulate filesystem data in a controlled, reproducible sandboxed environment.
    
    31 31
     
    
    ... ... @@ -61,25 +61,29 @@ How does BuildStream work?
    61 61
     ==========================
    
    62 62
     BuildStream operates on a set of YAML files (.bst files), as follows:
    
    63 63
     
    
    64
    -* loads the YAML files which describe the target(s) and all dependencies
    
    65
    -* evaluates the version information and build instructions to calculate a build
    
    64
    +* Loads the YAML files which describe the target(s) and all dependencies.
    
    65
    +* Evaluates the version information and build instructions to calculate a build
    
    66 66
       graph for the target(s) and all dependencies and unique cache-keys for each
    
    67
    -  element
    
    68
    -* retrieves elements from cache if they are already built, or builds them in a
    
    69
    -  sandboxed environment using the instructions declared in the .bst files
    
    70
    -* transforms/configures and/or deploys the resulting target(s) based on the
    
    67
    +  element.
    
    68
    +* Retrieves previously built elements (artifacts) from a local/remote cache, or
    
    69
    +  builds the elements in a sandboxed environment using the instructions declared
    
    70
    +  in the .bst files.
    
    71
    +* Transforms/configures and/or deploys the resulting target(s) based on the
    
    71 72
       instructions declared in the .bst files.
    
    72 73
     
    
    73 74
     
    
    74 75
     How can I get started?
    
    75 76
     ======================
    
    76
    -The easiest way to get started is to explore some existing .bst files, for example:
    
    77
    +To start using BuildStream, first,
    
    78
    +`install <https://buildstream.gitlab.io/buildstream/main_install.html>`_
    
    79
    +BuildStream onto your machine and then follow our
    
    80
    +`tutorial <https://buildstream.gitlab.io/buildstream/using_tutorial.html>`_.
    
    81
    +
    
    82
    +We also recommend exploring some existing BuildStream projects:
    
    77 83
     
    
    78 84
     * https://gitlab.gnome.org/GNOME/gnome-build-meta/
    
    79 85
     * https://gitlab.com/freedesktop-sdk/freedesktop-sdk
    
    80 86
     * https://gitlab.com/baserock/definitions
    
    81
    -* https://gitlab.com/BuildStream/buildstream-examples/tree/master/build-x86image
    
    82
    -* https://gitlab.com/BuildStream/buildstream-examples/tree/master/netsurf-flatpak
    
    83 87
     
    
    84 88
     If you have any questions please ask on our `#buildstream <irc://irc.gnome.org/buildstream>`_ channel in `irc.gnome.org <irc://irc.gnome.org>`_
    
    85 89
     

  • buildstream/_artifactcache/cascache.py
    ... ... @@ -240,7 +240,8 @@ class CASCache(ArtifactCache):
    240 240
     
    
    241 241
                 except grpc.RpcError as e:
    
    242 242
                     if e.code() != grpc.StatusCode.NOT_FOUND:
    
    243
    -                    raise
    
    243
    +                    raise ArtifactError("Failed to pull artifact {}: {}".format(
    
    244
    +                        element._get_brief_display_key(), e)) from e
    
    244 245
     
    
    245 246
             return False
    
    246 247
     
    
    ... ... @@ -285,6 +286,7 @@ class CASCache(ArtifactCache):
    285 286
     
    
    286 287
                         except grpc.RpcError as e:
    
    287 288
                             if e.code() != grpc.StatusCode.NOT_FOUND:
    
    289
    +                            # Intentionally re-raise RpcError for outer except block.
    
    288 290
                                 raise
    
    289 291
     
    
    290 292
                         missing_blobs = {}
    

  • buildstream/_context.py
    ... ... @@ -197,29 +197,55 @@ class Context():
    197 197
                                 "\nValid values are, for example: 800M 10G 1T 50%\n"
    
    198 198
                                 .format(str(e))) from e
    
    199 199
     
    
    200
    -        # If we are asked not to set a quota, we set it to the maximum
    
    201
    -        # disk space available minus a headroom of 2GB, such that we
    
    202
    -        # at least try to avoid raising Exceptions.
    
    200
    +        # Headroom intended to give BuildStream a bit of leeway.
    
    201
    +        # This acts as the minimum size of cache_quota and also
    
    202
    +        # is taken from the user requested cache_quota.
    
    203 203
             #
    
    204
    -        # Of course, we might still end up running out during a build
    
    205
    -        # if we end up writing more than 2G, but hey, this stuff is
    
    206
    -        # already really fuzzy.
    
    207
    -        #
    
    208
    -        if cache_quota is None:
    
    209
    -            stat = os.statvfs(artifactdir_volume)
    
    210
    -            # Again, the artifact directory may not yet have been
    
    211
    -            # created
    
    212
    -            if not os.path.exists(self.artifactdir):
    
    213
    -                cache_size = 0
    
    214
    -            else:
    
    215
    -                cache_size = utils._get_dir_size(self.artifactdir)
    
    216
    -            cache_quota = cache_size + stat.f_bsize * stat.f_bavail
    
    217
    -
    
    218 204
             if 'BST_TEST_SUITE' in os.environ:
    
    219 205
                 headroom = 0
    
    220 206
             else:
    
    221 207
                 headroom = 2e9
    
    222 208
     
    
    209
    +        stat = os.statvfs(artifactdir_volume)
    
    210
    +        available_space = (stat.f_bsize * stat.f_bavail)
    
    211
    +
    
    212
    +        # Again, the artifact directory may not yet have been created yet
    
    213
    +        #
    
    214
    +        if not os.path.exists(self.artifactdir):
    
    215
    +            cache_size = 0
    
    216
    +        else:
    
    217
    +            cache_size = utils._get_dir_size(self.artifactdir)
    
    218
    +
    
    219
    +        # Ensure system has enough storage for the cache_quota
    
    220
    +        #
    
    221
    +        # If cache_quota is none, set it to the maximum it could possibly be.
    
    222
    +        #
    
    223
    +        # Also check that cache_quota is atleast as large as our headroom.
    
    224
    +        #
    
    225
    +        if cache_quota is None:  # Infinity, set to max system storage
    
    226
    +            cache_quota = cache_size + available_space
    
    227
    +        if cache_quota < headroom:  # Check minimum
    
    228
    +            raise LoadError(LoadErrorReason.INVALID_DATA,
    
    229
    +                            "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
    
    230
    +                            "BuildStream requires a minimum cache quota of 2G.")
    
    231
    +        elif cache_quota > cache_size + available_space:  # Check maximum
    
    232
    +            raise LoadError(LoadErrorReason.INVALID_DATA,
    
    233
    +                            ("Your system does not have enough available " +
    
    234
    +                             "space to support the cache quota specified.\n" +
    
    235
    +                             "You currently have:\n" +
    
    236
    +                             "- {used} of cache in use at {local_cache_path}\n" +
    
    237
    +                             "- {available} of available system storage").format(
    
    238
    +                                 used=utils._pretty_size(cache_size),
    
    239
    +                                 local_cache_path=self.artifactdir,
    
    240
    +                                 available=utils._pretty_size(available_space)))
    
    241
    +
    
    242
    +        # Place a slight headroom (2e9 (2GB) on the cache_quota) into
    
    243
    +        # cache_quota to try and avoid exceptions.
    
    244
    +        #
    
    245
    +        # Of course, we might still end up running out during a build
    
    246
    +        # if we end up writing more than 2G, but hey, this stuff is
    
    247
    +        # already really fuzzy.
    
    248
    +        #
    
    223 249
             self.cache_quota = cache_quota - headroom
    
    224 250
             self.cache_lower_threshold = self.cache_quota / 2
    
    225 251
     
    

  • buildstream/utils.py
    ... ... @@ -608,6 +608,27 @@ def _parse_size(size, volume):
    608 608
         return int(num) * 1024**units.index(unit)
    
    609 609
     
    
    610 610
     
    
    611
    +# _pretty_size()
    
    612
    +#
    
    613
    +# Converts a number of bytes into a string representation in KB, MB, GB, TB
    
    614
    +# represented as K, M, G, T etc.
    
    615
    +#
    
    616
    +# Args:
    
    617
    +#   size (int): The size to convert in bytes.
    
    618
    +#   dec_places (int): The number of decimal places to output to.
    
    619
    +#
    
    620
    +# Returns:
    
    621
    +#   (str): The string representation of the number of bytes in the largest
    
    622
    +def _pretty_size(size, dec_places=0):
    
    623
    +    psize = size
    
    624
    +    unit = 'B'
    
    625
    +    for unit in ('B', 'K', 'M', 'G', 'T'):
    
    626
    +        if psize < 1024:
    
    627
    +            break
    
    628
    +        else:
    
    629
    +            psize /= 1024
    
    630
    +    return "{size:g}{unit}".format(size=round(psize, dec_places), unit=unit)
    
    631
    +
    
    611 632
     # A sentinel to be used as a default argument for functions that need
    
    612 633
     # to distinguish between a kwarg set to None and an unset kwarg.
    
    613 634
     _sentinel = object()
    

  • doc/source/main_install.rst
    1 1
     Install
    
    2 2
     =======
    
    3
    -This section covers how to install BuildStream onto your machine, how to run BuildStream inside a docker image and also how to configure an artifact server.
    
    3
    +This section covers how to install BuildStream onto your machine, how to run
    
    4
    +BuildStream inside a docker image and also how to configure an artifact server.
    
    4 5
     
    
    6
    +.. note::
    
    7
    +
    
    8
    +   BuildStream is not currently supported natively on macOS and Windows. Windows
    
    9
    +   and macOS users should refer to :ref:`docker`.
    
    5 10
     
    
    6 11
     .. toctree::
    
    7 12
        :maxdepth: 2
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]