Skip to content

Own Block registry

guideconfiguration-block-registry

Set up a Block registry for the Blocks that the company develops, so that developers can publish them and users can add them in the Desktop App.

When the company develops its own BlocksBlock — A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools. Glossary, it can give them to users through its own Block registry. Users then see the Blocks of the company next to the Blocks of MiLaboratories in the Desktop AppDesktop App — The program that each user installs on their own computer to work with Platforma. It is a client of the Backend. Glossary, while the company decides who can publish a Block and who can read it. To set it up:

How to write, build and test a Block is not on this page.

What a Block registry is

A Block registryBlock registry — A service from which the Desktop App downloads Blocks. MiLaboratories runs the main one; a company can add its own. Glossary is a folder of files in an object storage bucket: Amazon S3, an S3-compatible storage or Google Cloud Storage. There is no registry program to install and run. block-toolsblock-tools — The console tool of the Platforma SDK that builds Blocks and publishes them to a Block registry. It is the npm package @platforma-sdk/block-tools. Glossary writes the files when a developer or the CI of the company publishes a Block. The Desktop App reads them over HTTPS as a plain website, without credentials. So the company runs the registry with the storage and the web services that it already has.

block-tools keeps the layout of the folder. Do not change the files by hand:

Layout of a Block registry
<registry folder>/
v2/overview.json all Blocks
v2/<org>/<name>/overview.json one Block
v2/<org>/<name>/<version>/ one version
kinds/ interfaces of the Blocks
_updates_v2/, _overview_snapshots_v2/ internal

<org> (the organization) and <name> come from the npm package name of the Block, @<npm scope>/<organization>.<name>. for example The package @example/example.qc-report gives the Block example/qc-report.

Each version can be in the stable channel. In the Desktop App, each user chooses in “Block Updates Channel” which versions to get: stable (the default) or any, which also gives the versions that are not stable.

Read access for users

The Desktop App on the computer of each user reads the registry with plain HTTPS GET requests, and it does not send credentials. Thus the files must be readable without a sign-in from the computers of the users. Choose how far the company opens them:

  • A site in the corporate network. An HTTPS service that only the corporate network or VPN can reach serves the files of the bucket, for example a reverse proxy or a CDN with access rules. The Blocks stay inside the company.
  • A CDN in front of a private bucket. for example On AWS, Amazon CloudFront with origin access control reads a private S3 bucket and serves it at an HTTPS domain of the company, such as https://blocks.example.com/. Only the CDN can read the bucket, while anyone who knows the address can download the Blocks.
  • A public bucket. for example On Google Cloud, give allUsers the role roles/storage.objectViewer on the bucket, and use the address https://storage.googleapis.com/example-blocks/registry/. Anyone who knows the address can download the Blocks.

The Desktop App reads only the files whose paths it knows: the site does not need to allow the listing of the bucket. Use HTTPS: the Desktop App then checks the certificate of the site.

When a CDN is in front of the bucket, give the overview.json files and the files under channels/ a short cache time, for example 60 seconds, or turn the cache off for them. block-tools changes these files in place at each publish, and with a long cache time users see new versions late. On Google Cloud Storage, block-tools writes all files with Cache-Control: no-cache. On Amazon S3, it does not set a cache time: set it in the CDN.

The Desktop App reads the registry through the proxy of its network settings: see Desktop App network settings.

Write access for publishers

Only the CI pipelines and the developers that publish Blocks need write access: everyone with this access can change the Blocks that users get. block-tools reads, lists, writes and deletes the files in the registry folder. It takes the credentials from the default chain of the cloud, so a command does not hold a key:

  • Amazon S3, address s3://<bucket>/<folder>?region=<region>: the AWS SDK chain, for example environment variables or a profile on a developer computer, or a role through OIDC in the CI.
  • Google Cloud Storage, address gs://<bucket>/<folder>: Application Default Credentials, for example gcloud auth application-default login on a developer computer, or Workload Identity Federation in the CI.
  • An S3-compatible storage, address s3es://<key>:<secret>@<endpoint>/<bucket>/<folder>: the access key and the secret are in the address, percent-encoded. Keep this address in a secret of the CI.

Give the publishers this IAM policy. It allows the bucket example-blocks and its folder registry:

IAM policy of the publishers
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListRegistryBucket",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::example-blocks"
},
{
"Sid": "WriteRegistryFolder",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:AbortMultipartUpload"
],
"Resource": "arn:aws:s3:::example-blocks/registry/*"
}
]
}

block-tools needs s3:ListBucket also to find out that a file does not exist: without it, S3 answers “403 Forbidden” instead of “404 Not Found”, and the publish stops. When the bucket uses encryption with a KMS key, also allow kms:GenerateDataKey and kms:Decrypt on this key.

Publishing with block-tools

Developers publish a Block with one command, or the CI of the company does it at each release: block-tools puts the files into the registry and updates the lists that the Desktop App reads. block-tools is the npm package @platforma-sdk/block-tools, with the command block-tools; each Block repository has it as a development dependency. The block/ package of a Block repository, the package that holds the whole Block, runs block-tools publish in its prepublishOnly script: pnpm publish of this package first puts the Block into the Block registry, then the package into the npm registry.

  1. Set the two addresses of the company registry in block/package.json:

    block/package.json (part)
    {
    "scripts": {
    "prepublishOnly": "block-tools publish -r s3://example-blocks/registry?region=eu-central-1 --registry-serve-url https://blocks.example.com/registry/"
    }
    }
    • -r: the address to write to, in one of the forms of Write access for publishers.
    • --registry-serve-url: the HTTPS address of the same folder, which users read. block-tools writes it into the npm package of the Block, so that other Blocks find this Block in the registry.

    Instead of the options, the environment variables PL_REGISTRY and PL_REGISTRY_SERVE_URL can give the addresses.

  2. Give the publisher the credentials of the bucket, for example a role of the CI pipeline.

  3. Publish the package:

    Terminal window
    cd block
    pnpm publish

    Result: the version is in the registry and in the stable channel, and the lists of the registry are rebuilt. To publish a version that only users of the any channel get, add --unstable to the block-tools publish command, or set PL_PUBLISH_UNSTABLE=true.

  4. Check that the registry shows the version:

    Terminal window
    curl -s https://blocks.example.com/registry/v2/overview.json

    Result: the output has the Block and its new version. In the Desktop App, the version appears within a minute on the computers that have this registry.

Other commands keep the registry in order. Each takes the write address with -r or PL_REGISTRY:

Command What it does
block-tools mark-stable -r <address> -i block Adds the version of block/package.json to the stable channel. --unmark takes it out
block-tools refresh-registry -r <address> Rebuilds the lists of the registry from the published files. -m dry-run shows the changes and does not write; -m force rebuilds all lists
block-tools list-overview-snapshots -r <address> Lists the copies of the list of all Blocks: block-tools keeps one at each rebuild
block-tools restore-overview-from-snapshot -r <address> -s <timestamp> Puts back the list of all Blocks from a copy

Block packages in npm

Blocks of the company can use each other, for example in tests, and share their software, as the Blocks of MiLaboratories do: through npm packages. Keep these packages in the npm registry of the company, so that the code stays private. Any npm registry works: a self-hosted one, the package service of the code hosting, or the artifact registry of a cloud.

A Block repository publishes these packages:

  • block/, named @<npm scope>/<organization>.<name>: the whole Block, and the address of the Block registry that holds it. Other Blocks use this package to find the Block in the registry.
  • software/: the tools that the Block runs. They also go to a software registrysoftware registry — A service from which the Backend downloads the software packages of the tools that Blocks use. Only Single Server mode without Docker uses it; in a Kubernetes cluster and with Docker, the tools come as container images. Glossary: see Software packages and assets.

The other packages of the repository (model, UI, workflowworkflow — The part of a Block that runs in the Backend. It starts the tools on the data and collects the results. Users do not edit it. Glossary, tests) are private: they go into the block/ package and are not published alone.

The packages of the Platforma SDK come from npmjs.org. Map only the npm scope of the company to its npm registry, in the .npmrc file at the root of each Block repository:

.npmrc
@example:registry=https://npm.example.com/
//npm.example.com/:_authToken=${NPM_TOKEN}
@platforma-sdk:registry=https://registry.npmjs.org/
@milaboratories:registry=https://registry.npmjs.org/
@platforma-open:registry=https://registry.npmjs.org/

pnpm publish then puts the packages of @example into the npm registry of the company. When the npm registry of the company is also a mirror of npmjs.org, map all scopes to it instead.

Desktop App and Backend

Desktop App. On each computer, users add the HTTPS address of the registry, the same as --registry-serve-url, to “Additional Registries” in the settings of the Desktop App. Then they see the Blocks of the company next to the Blocks of MiLaboratories. For this setting and the other Block registry settings, see Block registries in the Desktop App.

BackendBackend — The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs. Glossary. The Backend also reads the Block registry: it gets the workflow template packs of the Blocks from it. Thus the Backend must have access to the registry too (see Registries mirroring). It also needs the software of the Blocks of the company:

  • when the Blocks use their own image registry, add it to the trusted registries: see Registries of custom Blocks;
  • in Single Server modeSingle Server mode — The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster. Glossary without Docker, when they use their own software package registry, set it on the Backend: see Software packages and assets.

Changes on a running installation

Change What happens What to do
Publish a version Within a minute, users see it as a new version or an update of the Block. A CDN cache can add its cache time Nothing
Publish with --unstable Only users with the any channel see the version Run mark-stable when the version is ready for all users
Take a version out of stable (mark-stable --unmark) The Desktop App does not offer this version to users with the stable channel any more Publish a fixed version
Restore the list of all Blocks from a copy Users see the Blocks and versions of the copy Find the copy with list-overview-snapshots first
Add the registry to the Desktop App Users see the Blocks of the company Tell users the address; each user sets it on each computer
Change who can publish Users do not see a change Change the IAM policy or the role binding of the bucket

Problems

The Desktop App does not show the Blocks of the registry, with the error Failed to read <address>: HTTP 403 or HTTP 404. Cause: the files are not readable without a sign-in, or the address is wrong. The address is the folder that holds v2/: the Desktop App adds v2/ itself. Fix: on a computer of a user, run curl -I <address>/v2/overview.json. It must answer “200”. Then correct the address or the read access (see Read access for users).

block-tools stops with “AccessDenied”, “failed to put object into S3 bucket” or “failed to put object into GCS bucket”. Cause: the publisher does not have credentials, or its policy does not allow all the actions. Fix: check the credentials of the CI pipeline or of the developer, and the policy (see Write access for publishers).

block-tools stops with “Malformed package name”. Cause: the name of the block/ package is not in the form @<npm scope>/<organization>.<name>. Fix: rename the package.

Users do not see a new version. Causes: the version was published with --unstable, and the user has the stable channel; a CDN keeps the old overview.json files; the Desktop App keeps the list for 45 seconds. Fix: mark the version stable, give the overview files a short cache time in the CDN, or wait a minute.

Next