github.com/wtsi-hgi/go-softpack-builder@v1.8.1/README.md (about)

     1  # go-softpack-builder (gsb)
     2  Go implementation of a softpack builder service.
     3  
     4  After receiving a POST to `/environments/build` (see Testing section below) with
     5  desired environment details, this service does the following:
     6  
     7  1. A singularity definition file, singularity.def, is created and uploaded to
     8     an environment-specific subdirectory of your S3 build location.
     9     The definition uses a spack image to run spack commands that install the
    10     desired versions of the spack packages specified in the POST. The results
    11     are then copied in to a smaller final image.
    12  2. A job is supplied to `wr add`. This job essentially runs `singularity build`
    13     in a fuse mount of the environment-specific subdirectory of your S3 build
    14     location. Outputs of the build end up in S3: the built image itself
    15     (singularity.sif), stdout&err of the build attempt (builder.out), a list of
    16     the executables added to PATH as a result of installing the requested
    17     packages - not their dependencies - (executables), and the spack.lock file
    18     that spack generates containing the concrete versions of everything it
    19     installed.
    20  3. In the case of build failure, builder.out containing the error message will
    21     be in the S3 location, and it will also be sent to core, which should then
    22     indicate the failure on the softpack-web frontend.
    23     In the case of build success, the remaining steps are carried out.
    24  4. A tcl module file is generated and installed in your local installation dir.
    25     This file defines help (a combination of the description specified in the
    26     POST, and a list of the executables), whatis info (listing the desired
    27     packages), and prepends to PATH the local scripts directory for this
    28     environment.
    29  5. The singularity.sif is downloaded from S3 and placed in the scripts
    30     directory, along with symlinks for each executable to your wrapper script
    31     (which as per wrapper.example, should `singularity run` the sif file,
    32     supplying the exe basename and any other args).
    33  6. A softpack.yml file is generated, containing the help text from the module as
    34     the description, and the concrete desired packages from the lock file. A
    35     README.md is also generated, with simple usage instructions in it
    36     (`module load [installed module path]`). In case step 6 fails, these are
    37     uploaded to the S3 build location.
    38  7. The main files in S3 (singularity.def, spack.lock, builder.out,
    39     softpack.yml, README.md), along with the previously generated module file are
    40     sent to the core service, so it can add them to your softpack artifacts repo
    41     and make the new environment findable with the softpack-web frontend.
    42     Note that the image is not sent to core, so the repo doesn't get too large.
    43     It can be reproduced exactly at any time using the singularity.def, assuming
    44     you configure specific images (ie. not :latest) to use.
    45  
    46  When this service starts, it triggers core to re-send "queued" environments:
    47  those that exist in the artifacts repo as just a definition but with no other
    48  build artifacts.
    49  
    50  If this service is restarted while a build is running, core's re-send will
    51  result in the running build completing normally, followed by the rest of the
    52  above 7 steps. Buried builds will remain buried.
    53  
    54  After receiving a GET to `/environments/status`, this service returns a JSON
    55  response with the following structure:
    56  
    57  ```json
    58  [
    59    {
    60      "Name": "users/foo/bar",
    61      "Requested": "2024-02-12T11:58:49.808672303Z",
    62      "BuildStart": "2024-02-12T11:58:55.430080969Z",
    63      "BuildDone": "2024-02-12T11:59:00.532174828Z"
    64    }
    65  ]
    66  ```
    67  
    68  The times are quoted strings in the RFC 3339 format with sub-second precision,
    69  or null.
    70  
    71  ## Initial setup
    72  
    73  You'll need an S3 bucket to be a binary cache, which needs GPG keys. Here's one
    74  way this could be done:
    75  
    76  ```
    77  cd /path/to
    78  git clone --depth 1 -c feature.manyFiles=true https://github.com/spack/spack.git
    79  source /software/hgi/installs/spack/share/spack/setup-env.sh
    80  spack gpg create "user" "<user@domain>"
    81  s3cmd put ~/spack/opt/spack/gpg/pubring.* s3://spack/
    82  ```
    83  
    84  You'll also need a wr cloud deployment in OpenStack running an image with
    85  singularity v3.10+ installed, to do singularity builds which need root.
    86  
    87  With a wr config file such as /path/to/openstack/.wr_config.yml:
    88  ```
    89  managerport: "46673"
    90  managerweb: "46674"
    91  managerhost: "hostname"
    92  managerdir: "/path/to/openstack/.wr"
    93  managerscheduler: "openstack"
    94  cloudflavor: "^[mso].*$"
    95  cloudflavorsets: "s4;m4;s2;m2;m1;o2"
    96  clouddns: "172.18.255.1,172.18.255.2,172.18.255.3"
    97  cloudos: "image-with-singularity"
    98  clouduser: "ubuntu"
    99  cloudram: 2048
   100  clouddisk: 1
   101  cloudconfigfiles: "~/.s3cfg,~/.aws/credentials,~/.aws/config,/path/to/spack/gpg/trustdb.gpg:~/spack/opt/spack/gpg/trustdb.gpg,/path/to/spack/gpg/pubring.kbx:~/spack/opt/spack/gpg/pubring.kbx,/path/to/spack/gpg/private-keys-v1.d/[keyname].key:~/spack/opt/spack/gpg/private-keys-v1.d/[keyname].key"
   102  ```
   103  
   104  You can do the deploy like:
   105  
   106  ```
   107  source ~/.openrc.sh
   108  export WR_CONFIG_DIR=/path/to/openstack
   109  wr cloud deploy
   110  ```
   111  
   112  Now jobs submitted to this wr manager will run in OpenStack on a node where your
   113  s3 credentials and gpg keys are copied to, and where singularity is installed,
   114  enabling builds that use the binary cache.
   115  
   116  Finally, you'll need go1.21+ in your PATH to install gsb:
   117  
   118  ```
   119  git clone https://github.com/wtsi-hgi/go-softpack-builder.git
   120  cd go-softpack-builder
   121  make install
   122  ```
   123  
   124  ## Using gsb
   125  
   126  Have a config file ~/.softpack/builder/gsb-config.yml that looks like this:
   127  
   128  ```
   129  s3:
   130    binaryCache: "spack"
   131    buildBase: "spack/builds"
   132  
   133  module:
   134    moduleInstallDir:  "/path/to/tcl_modules/softpack"
   135    scriptsInstallDir: "/different/path/for/images_and_scripts"
   136    loadPath: "softpack"
   137    dependencies:
   138      - "/path/to/modules/singularity/3.10.0"
   139  
   140  customSpackRepo: "https://github.com/org/spack-repo.git"
   141  
   142  spack:
   143    buildImage: "spack/ubuntu-jammy:v0.20.1"
   144    finalImage: "ubuntu:22.04"
   145    processorTarget: "x86_64_v3"
   146  
   147  coreURL: "http://x.y.z:9837/softpack"
   148  listenURL: "0.0.0.0:2456"
   149  ```
   150  
   151  Where:
   152  
   153  - s3.binaryCache is the name of your S3 bucket that will be used as a Spack
   154    binary cache and has the gpg files copied to it.
   155  - buildBase is the bucket and optional sub "directory" that builds will occur
   156    in.
   157  - moduleInstallDir is the absolute base path that modules will be installed to
   158    following a build. This directory needs to be accessible by your users.
   159    Directories and files that gsb creates within will be world readable and
   160    executable.
   161  - scriptsInstallDir is like moduleInstallDir, but will contain the images and
   162    wrapper script symlinks for your builds. These are kept separately from the
   163    tcl module files, because having large files alongside the tcl file will slow
   164    down the module system.
   165  - loadPath is the base that users `module load`.
   166  - dependencies are any module dependencies that need to be loaded because that
   167    software won't be part of the environments being built. Users will at least
   168    need singularity, since the modules created by softpack run singularity
   169    images.
   170  - customSpackRepo is your own repository of Spack packages containing your own
   171    custom recipies. It will be used in addition to Spack's build-in repo during
   172    builds.
   173  - buildImage is spack's docker image from their docker hub with the desired
   174    version (don't use latest if you want reproducability) of spack and desired
   175    OS.
   176  - finalImage is the base image for the OS you want the software spack builds to
   177    installed inside (it should be the same OS as buildImage).
   178  - processorTarget should match the lowest common denominator CPU for the
   179    machines where builds will be used. For example, x86_64_v3.
   180  - coreURL is the URL of a running softpack core service, that will be used to
   181    send build artifacts to so that it can store them in a softpack environements
   182    git repository and make them visible on the softpack frontend.
   183  - listenURL is the address gsb will listen on for new build requests from core.
   184  
   185  Start the builder service:
   186  
   187  ```
   188  export WR_CONFIG_DIR=/path/to/openstack
   189  gsb &
   190  ```
   191  
   192  ## Testing
   193  
   194  Without a core service running, you can trigger a build by preparing a bash
   195  script like this and running it while `gsb &` is running and your wr cloud
   196  deployment is up:
   197  
   198  ```
   199  #!/bin/bash
   200  
   201  url="http://[listenURL]/environments/build";
   202  
   203  curl -X POST -H "Content-Type: application/json" --data-binary @- "$url" <<HEREDOC
   204  {
   205  	"name": "users/user/test-build",
   206  	"version": "1.0",
   207  	"model": {
   208  		"description": "A simple description",
   209  		"packages": [{
   210  			"name": "xxhash",
   211  			"version": "0.8.1"
   212  		}]
   213  	}
   214  }
   215  HEREDOC
   216  ```
   217  
   218  This should result in a job running in your wr manager that creates the
   219  singularity image file and other artifacts in your S3 buildBase. The module
   220  wrapper for the image will be installed to your installDir.
   221  
   222  Only the last step, when gsb tries to send the artifacts to the core, will fail,
   223  but you'll at least have a usable software installation of the environment that
   224  can be tested and used.