Search code examples
cloud-foundrycf-bosh

How to copy multiple template files in BOSH?


In Bosh Job Spec files you can list templates to be copied, like this.

templates:
  ctl.sh: bin/ctl
  config.json: config/config.json

Is there a way to copy multiple files maybe using a wildcard or somthing?

A way like this...

templates:
  *.sh: bin/
  *.xml: config/ 

Solution

  • The template section in a job spec is a 1:1 mapping, and does not (currently) support wild cards, though I suppose target path could be assumed, they are intended to be explicit. But these files are only intended where you need ERB configuration files to ingest properties from the manifest/yml that allow flexibility between uses.

    But if you want lots of files that don't need dynamic properties you may consider if those are templates or dependencies. You can use packages to include an entire archive or folder needed as dependencies, including use of wildcards, and those can be automatically extracted as part of the job's lifecycle. See https://bosh.io/docs/create-release.html#pkg-skeletons

    Each package has a packaging script to tell bosh where to place the files.

    # abort script on any command that exits with a non zero value
    set -e
    
    tar -xzf $BOSH_COMPILE_TARGET/xml/all-files.tar.gz
    cp -a all-files/* $BOSH_INSTALL_TARGET
    

    And that file(s) are defined in the package spec

    ---
    name: xml-files
    
    dependencies:
    
    files:
    - xml/all-files.tar.gz 
    

    files : A list of files this package contains, which can contain globs. A * matches any file and can be restricted by other values in the glob, e.g. *.rb only matches files ending with .rb. A ** matches directories recursively.

    And you just reference from your job spec.

    ---
    name: myjob
    templates:
      ctl.sh: bin/ctl
      config.json: config/config.json
    
    packages:
    - xml-files