# Software images of the tools

Make a pull-through cache of the software images of the tools and point Platforma to it.

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 the tools from software images in `containers.pl-open.science/milaboratories/pl-containers`. This host passes each request to `quay.io/milaboratories/pl-containers`, so both give the same images with the same digests. There are thousands of images, and some are large. There is no list of the images that Platforma needs: a new version of a Block (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) often brings its own image, and scientists choose the Block versions in their projects. Thus the mirror must get the images on demand:

- a **pull-through cache** (recommended): the registry gets an image from the original registry at the first pull and keeps it;
- a **sync**: a job of the company copies the new tags of `quay.io/milaboratories/pl-containers` to the mirror at regular intervals.

Each job pulls its image on a node that does not have it. So keep the mirror available for as long as Platforma runs.

A mirror in the company gives two benefits:

- **Security checks.** The company can scan each image for known vulnerabilities (CVE) when the image comes into the mirror.
- **Less traffic.** When the cluster adds many nodes for a large computation, the image comes from the internet only one time, and the nodes get it from the local cache. This decreases the outbound traffic and its cost. For example, in AWS the traffic between the nodes and a cache in the same region stays inside the region.

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.) make this cache by default: see [Caches of the cloud-specific modules](/install-cloud-terraform/#caches-of-the-cloud-specific-modules). Use the steps below when you make the cache yourself.

1. Make a pull-through cache in a registry service that supports one. For example:

   - a proxy cache project in Harbor;
   - a Docker proxy repository in Nexus;
   - a remote repository in Google Artifact Registry;
   - a pull-through cache rule in Amazon ECR;
   - a Docker Distribution registry in proxy mode.

   Use `https://quay.io` as the original registry. `https://containers.pl-open.science` gives the same images, but Amazon ECR cannot use it.

   **Example:**

   A Docker Distribution registry (`registry:2`) in proxy mode, as a container:

   ```sh
   docker run -d --name pl-containers-cache -p 5000:5000 \
     -e REGISTRY_PROXY_REMOTEURL=https://quay.io registry:2
   ```

   A registry in proxy mode is read-only and proxies only one original registry. For a service in production, add TLS and storage to it: see the documentation of the registry.

2. Find the path of the images in the cache. It is the address of the cache, then the path of the image in the original registry, `milaboratories/pl-containers`. For example:

   | Cache                                                      | Path of the images                                                           |
   | ---------------------------------------------------------- | ---------------------------------------------------------------------------- |
   | Docker Distribution registry                               | `registry.example.com/milaboratories/pl-containers`                          |
   | Harbor proxy cache project `quay`                          | `registry.example.com/quay/milaboratories/pl-containers`                     |
   | Amazon ECR, pull-through cache rule with the prefix `quay` | `<account>.dkr.ecr.<region>.amazonaws.com/quay/milaboratories/pl-containers` |

   The path must end with `/pl-containers` and give the same tags as the original.

3. Pull one small image through the cache to check it:

   ```sh
   docker pull registry.example.com/milaboratories/pl-containers:busybox.1.37.0
   ```

   Result: the pull is successful, and the digest is the same as the digest of `quay.io/milaboratories/pl-containers:busybox.1.37.0`.

4. Give the nodes read access to the cache: the cloud identity (The identity that the cloud gives to the Platforma pod (IAM roles for service accounts on AWS, Workload Identity on Google Cloud). With it, Platforma needs no access keys.) of the nodes, or an image pull Secret for the jobs. 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.), sign in (To show the Backend who you are, with a sign-in provider or a single-user token. The verb is "sign in"; the noun and the adjective are "sign-in".) to the cache with Docker as the user of the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.). See [Credentials of a mirror](/configuration-registries/#credentials-of-a-mirror).

5. Set the default Docker registry to the path of the images. The Backend replaces `containers.pl-open.science/milaboratories/pl-containers` in each image name with this path, and keeps the tag:

   #### 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, {}), {
         default_docker_registry = "registry.example.com/milaboratories/pl-containers"
       })
     })
     backend_service = {
       jobs = { image = { pull_secrets = [{ name = "regcred" }] } }   # only with a pull Secret
     }
   }
   ```

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

   With the cloud-specific modules, set `registries.default_docker_registry` of `platforma-tf-cloud-base` instead.

   #### Variant: Helm chart

   *values.yaml*

   ```yaml
   registries:
     defaultDockerRegistry: registry.example.com/milaboratories/pl-containers
   jobs:
     image: { pullSecrets: [{ name: regcred }] }   # only with a pull Secret
   ```

   #### Variant: Single Server

   The setting is used only when the jobs run in Docker. Start the Backend with the option, or set the environment variable `PL_DEFAULT_DOCKER_REGISTRY`:

   ```sh
   platforma --default-docker-registry registry.example.com/milaboratories/pl-containers \
             <other options>
   ```

   The Backend uses the new value after it starts again. For the details of this setting, see [Software images of the jobs](/configuration-registries/#software-images-of-the-jobs).

6. Run a Block in a project.

   Result: the job starts, and its image is in the cache.

In a Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) cluster, the helper images of Platforma are also in `pl-containers`: the cleanup job, the AppWrapper (A Kubernetes add-on that wraps the pods of one job into a single unit, so that Kueue admits and starts them together.) controller, the GPU node startup image and the workspace (The storage where the Backend and all jobs keep the working files of running jobs. The Backend and the jobs use it at the same time. In Kubernetes, it is a network file system; in Single Server mode, it is a folder on the server.) init image. So they can come from the same cache. Set each one, as in [Backend and controller images](/registries-mirroring-images/).

## Next

- [Static assets](/registries-mirroring-assets/)

Source: https://docs.platforma.bio/registries-mirroring-tool-images/
