Custom Resource Downloader#

To create your own init container to download the resources from anywhere you want, you just need to provide a download_resource.sh in the working directory.

The UCS app will then use your init container to download the resources.

  • The remoteResourcePath is available as REMOTE_RESOURCE_PATH environment variable. Note that if a single resource path is provided, the environment variable will be a string containing the resource path whereas when multiple paths are provided the environment variable value will be a map of the form: {'myFirstResource': 'my-first-resource-path', 'mySecondResource': 'my-second-resource-path', 'myThirdResource': 'my-third-resource-path'}

  • The mount path of the persistent volume is available as DESTINATION_RESOURCE_PATH environment variable. In the case when multiple resource paths are provided, every resource should be downloaded in a subdirectory named like the resource key (e.g. myFirstResource).

  • The values in the secret are available as environment variables, exactly as they are stated in the secret.

Here is an extract of the UCS manifest.yaml of an microservice using the resource downloader for illustration purposes.

image: "(($params.resourceDownload.image))"
imagePullPolicy: IfNotPresent
env:
  - name: REMOTE_RESOURCE_PATH
    value: "(($params.resourceDownload.remoteResourcePath))"
  - name: DESTINATION_RESOURCE_PATH
    value: "(($params.internal.assetMountPath))"
envFrom:
  - secretRef:
      name: "(($params.resourceDownload.secretName))"
command: ["/bin/bash", "download_resource.sh"]

Your dockerfile could look something like this. In the download_resource.sh you can freely script the download of the resources.

FROM ubuntu:22.04
WORKDIR /home/my-user
COPY download_resource.sh .
ENTRYPOINT ["/bin/bash", "download_resource.sh"]

Here is an example, how you would add your own init container as params to the UCS app.

# Single resource example (remoteResourcePath is a string)
resourceDownload:
  remoteResourcePath: my-resource-path
  secretName: my-secret
  image: my-resource-downloader:1.2.3

# Multi resources example (remoteResourcePath is a map)
resourceDownload:
  remoteResourcePath:
    myFirstResource: my-first-resource-path
    mySecondResource: my-second-resource-path
    myThirdResource: my-third-resource-path
  secretName: my-secret
  image: my-resource-downloader:1.2.3