# Static assets

Make an HTTPS mirror of the static assets and point the Backend to it.

The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) downloads the static assets, for example reference genomes and gene annotations, from `https://bin.pl-open.science/`, when a Block (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) needs an asset. Each asset is a file at a fixed path, for example `assets/platforma-open/milaboratories.gene-annotations.drosophila-melanogaster/main/1.1.0.zip`. A mirror is an HTTPS service that gives the same files at the same paths below its own address. When you set the mirror, the Backend replaces `https://bin.pl-open.science/` at the start of each address with the address of the mirror, and keeps the rest of the path.

There is no list of the assets that the Blocks need, so the mirror gets them in one of these ways:

- a **caching proxy** (recommended): an HTTPS proxy of `https://bin.pl-open.science/` that keeps each file after the first download;
- a **copy**: the company copies the files of the assets that its Blocks use, with the same paths, to an HTTPS service, for example a web server or a bucket behind HTTPS.

The Backend downloads an asset each time a Block needs one that it does not have. So keep the mirror available for as long as Platforma runs.

1. Make the mirror: a caching proxy or a copy with the same paths.

   **Example:**

   A caching proxy with nginx. It keeps each file for one year: an asset version does not change.

   *bin-mirror.conf*

   ```nginx
   proxy_cache_path /var/cache/nginx/bin levels=1:2 keys_zone=bin:10m max_size=100g inactive=365d use_temp_path=off;
   server {
     listen 443 ssl;
     server_name bin-mirror.example.com;
     # ssl_certificate and ssl_certificate_key of the company
     location / {
       proxy_pass https://bin.pl-open.science;
       proxy_set_header Host bin.pl-open.science;
       proxy_ssl_server_name on;
       proxy_cache bin;
       proxy_cache_valid 200 365d;
     }
   }
   ```

2. Check that the mirror gives the same file as the original:

   ```sh
   path=assets/platforma-open/milaboratories.gene-annotations.drosophila-melanogaster/main/1.1.0.zip
   curl -fSLo mirror.zip https://bin-mirror.example.com/$path
   curl -fSLo original.zip https://bin.pl-open.science/$path
   sha256sum mirror.zip original.zip
   ```

   Result: both downloads finish without an error, and the two checksums are the same.

3. Give the Backend network access to the mirror. When the mirror uses a certificate of a private CA, give the Backend the CA bundle (One PEM file with the certificate authorities that a program trusts. In Kubernetes, Platforma can give the Backend and all jobs one bundle with the public and the corporate certificate authorities.): see [Proxy and custom CA](/configuration-proxy-and-custom-ca/).

4. Set the address of the mirror. It must end with `/`, as `https://bin.pl-open.science/` does: otherwise the Backend does not start.

   #### Variant: Terraform modules

   *platforma-tf-services*

   ```hcl
   locals {
     infra = jsondecode(file("infrastructure.json"))
   }


   module "platforma" {
     # ...
     infrastructure = merge(local.infra, {
       registries = merge(try(local.infra.registries, {}), {
         assets_registry_url = "https://bin-mirror.example.com/"
       })
     })
   }
   ```

   The inner `merge` keeps the other registry settings of the file.

   With the cloud-specific Terraform modules (The Terraform modules platforma-tf-cloud-base and platforma-tf-cloud-cluster. There is one pair for each cloud, AWS and Google Cloud. The roots cloud and cluster apply them. They make the network, the Kubernetes cluster, the storage, the cloud identities and the registry caches. They give the hand-off file cluster_config to the cloud-agnostic Terraform modules.), set `registries.assets_registry_url` of `platforma-tf-cloud-base` instead.

   #### Variant: Helm chart

   *values.yaml*

   ```yaml
   registries:
     assetsRegistryURL: https://bin-mirror.example.com/
   ```

   #### Variant: Single Server

   Start the Backend with the option, or set the environment variable `PL_ASSETS_REGISTRY_URL`:

   ```sh
   platforma --assets-registry-url https://bin-mirror.example.com/ <other options>
   ```

   The Backend uses the new value after it starts again. See [Software packages and assets](/configuration-registries/#software-packages-and-assets).

5. Run a Block that uses an asset, for example a Block that needs a reference genome.

   Result: the Block runs, and the access log of the mirror shows the download of the asset.

## Software packages in Single Server mode

In Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.), when the jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) run without Docker, the Backend also downloads the software packages of the tools from `https://bin.pl-open.science/`. A caching proxy of this host gives the packages too; a copy must also hold the packages. Point the Backend to the mirror with `--package-registry platforma-open=https://bin-mirror.example.com/`, or the environment variable `PL_PACKAGE_REGISTRY`: see [Software packages and assets](/configuration-registries/#software-packages-and-assets).

## Next

- [Block registry](/registries-mirroring-block-registry/)

Source: https://docs.platforma.bio/registries-mirroring-assets/
