Cloud MTA Build Tool (MBT)

repository·master·Indexed 41 days ago

https://github.com/sap/cloud-mta-build-tool

A CLI tool designed to build deployment-ready Multi-Target Application (.mtar) archives from MTA project artifacts using mta.yaml or mtad.yaml descriptors. It provides capabilities for validating descriptors, building individual modules, generating deployment descriptors, and assembling archives.

Tokens
16.9K
Snippets
76
Records
96
Agent score
94%

What's inside MBT

  1. What is the Cloud MTA Build Tool (MBT)?

    master

    The Cloud MTA Build Tool (MBT) is a standalone command-line tool used to create deployment-ready Multitarget Application (MTA) archives in the .mtar format.

    It can generate these archives in two ways:

    1. From an MTA project: Using the MTA development descriptor (mta.yaml) to build modules and package them.
    2. From prebuilt artifacts: Using an MTA deployment descriptor (mtad.yaml) to assemble existing module build artifacts, dependencies, and resources into a single MTAR.

    The tool is designed to run on file systems independent of the original development environment and is supported on Windows and Linux.

  2. Overview of the Cloud MTA Build Tool

    master

    The Cloud MTA Build Tool is a standalone command-line tool used to build deployment-ready Multi-Target Application (MTA) archives (.mtar files).

    It operates based on:

    1. An MTA development descriptor (mta.yaml file).
    2. Module build artifacts according to an MTA deployment descriptor (mtad.yaml file).

    Key capabilities include:

    • Validating mta.yaml files.
    • Building individual modules based on development descriptor configurations.
    • Generating deployment descriptors.
    • Running intermediate build process steps.
  3. Define module build order and dependencies

    master

    To ensure modules are built in a specific sequence, use the requires section within build-parameters. A module will only be built after all modules listed in its requires section have completed their build.

    Key Rules:

    • The order of modules in the mta.yaml file does not matter; only the requires relationships define the order.
    • Cyclical dependencies are not allowed and will cause the build to fail.

    Using build results from dependencies: You can pass artifacts from a required module to the current module using artifacts and target-path.

    ID: myproject
    _schema-version: '3.1'
    version: 0.0.1
    
    modules:
     
     - name: A
       type: html5 
       path: pathtomoduleA
       build-parameters:
          requires:
            - name: B
              artifacts: ["*"]
              target-path: "newfolder"
              
     - name: B
       type: html5 
       path: pathtomoduleB
  4. Prepare a development environment for MBT

    master

    To contribute to the Cloud MTA Build Tool (MBT), ensure you meet the following prerequisites:

    1. Go: Install Go version v1.13 or higher.
    2. Git: Familiarity with Git version control.

    Before starting development, fork the repository and create your feature branch from the master branch.

  5. Build an MTA archive from project sources (Two-step build)

    master

    The two-step build approach allows you to manually control the build process by generating a Makefile first and then using the standard make command.

    Step 1: Generate the Makefile

    Use mbt init to generate the Makefile.mta file based on your mta.yaml descriptor.

    Usage: mbt init <flags>

    • -s, --source: Path to the MTA project (defaults to current path).
    • -t, --target: Path to the folder where the generated Makefile will be placed (defaults to current path).
    • -e, --extensions: Path(s) to .mtaext files.

    Step 2: Execute the build with Make

    Use the make command pointing to the generated Makefile.mta.

    Usage: make -f Makefile.mta <parameters>

    Parameters:

    ParameterDescription
    -f <path>Mandatory. Path to the Makefile.mta file.
    pMandatory. Target platform: cf, neo, or xsa.
    tFolder for the generated .mtar file.
    mtarFilename for the generated archive.
    strict(Default: true) Set to false to treat schema errors as warnings.
    mbt init
    make -f Makefile.mta p=cf
  6. Generate Software Bill of Materials (SBOM)

    master

    The npm, maven, and golang builders support SBOM generation. To generate an SBOM, use the --sbom-file-path flag with the mbt build or mbt sbom-gen command.

    For java or nodejs modules, the default builders (maven or npm) will automatically trigger SBOM generation if the flag is provided during the build command.

    mbt build --sbom-file-path sbom-path/test.sbom.xml
    
    # OR
    
    mbt sbom-gen --sbom-file-path sbom-path/test.sbom.xml
  7. Configure environment variables for build tools

    master

    To ensure the Cloud MTA Build Tool can locate the required prerequisite tools, you must correctly configure the following environment variables in your build environment:

    • Java SE Development Kit: Set <JAVA_HOME> and ensure the bin directory is in your <PATH>.
    • Apache Maven: Set <M2_HOME> and ensure the bin directory is in your <PATH>.
    • Node.js and npm: Ensure the installation directories are included in your <PATH>.
  8. Configure global build steps (before-all)

    master

    To execute build steps before any specific module builders run, define a global build-parameters section at the root level of your mta.yaml file using the before-all key.

    You can run a single builder or a list of builders that will execute in the specified order.

    Note on Global Configuration: When configuring builders at the global level, only the following parameters are supported:

    • timeout
    • commands (for the custom builder only)
    • fetcher-opts (for the fetcher builder only)
    ID: myproject
    _schema-version: '3.1'
    version: 0.0.1
    
    build-parameters:
      before-all:
        builders:
          - builder: custom
            commands: 
              - npm run script1
          - builder: grunt
  9. Install GNU Make on Windows

    master

    To build an MTA archive from source code in a Windows environment, you must have GNU Make 4.2.1 installed. You can install it using one of the following methods:

    Method 1: Manual Installation

    1. Download the GNU Make 4.2.1 executable (32-bit or 64-bit) from a trusted source.
    2. Save the executable to a local folder.
    3. Rename the file to make.exe.
    4. Add the folder containing make.exe to your system's PATH environment variable.

    Method 2: Using Chocolatey

    Use the Chocolatey package manager to install or upgrade GNU Make by running:

    choco install make
    choco install make
  10. Replace unsupported build parameters with a custom builder

    master

    If you were using unsupported parameters like maven-opts or if you replace a maven builder with a custom builder, you must explicitly set the build-result parameter.

    Example for a Java module using a custom builder:

    - name: module1
      type: java
      build-parameters:     
         builder: custom
         build-result: target/*.war
  11. Resolve naming conflicts between modules and property sets

    master

    The Cloud MTA Build Tool requires unique names for modules and their provided property sets. If your mta.yaml uses the same name for both, you must rename one of them.

    Incorrect (Legacy):

    - name: SOME_NAME
        type: java
        path: srv
        provides:
          - name: SOME_NAME
            properties:
              url: ${default-url}

    Correct (New):

    - name: SOME_NAME
        type: java
        path: srv
        provides:
          - name: SOME_NAME_API
            properties:
              url: ${default-url}
    - name: SOME_NAME
        type: java
        path: srv
        provides:
          - name: SOME_NAME_API # New name
            properties:
              url: ${default-url}