Sometime users may want to execute a script in their operation or to generate a file that can be used as an input for an init container or the main container without cloning a repo.

Running a python script

This example shows how to initialize a python script without cloning a repo or uploading code:

version: 1.1
kind: component
run:
  kind: job
  init:
    - file:
        content: |
          print("Hello World")
        filename: script.py
  container:
    image: polyaxon/polyaxon-quick-start
    workingDir: "{{ globals.artifacts_path }}"
    command: [python3, -u, script.py]

This example creates a file script.py in the init section and executes it in the main container.

Similar to all other init containers, we could provide a custom path where the file should be initializer:

init:
  - file:
      content: |
        print("Hello World")
      filename: script.py
    path: custom/path/to/use

Running a bash script

version: 1.1
kind: component
run:
  kind: job
  init:
    - file:
        content: |
          echo 'This is a test.' | wc -w
        filename: script.sh
        chmod: "+x"
  container:
    image: polyaxon/polyaxon-quick-start
    workingDir: "{{ globals.artifacts_path }}"
    command: ['/bin/bash', '-c']
    args: ['./script.sh']

Initializing a YAML file

version: 1.1
kind: component
run:
  kind: job
  init:
    - file:
        content: |
          version: 1.1
          kind: component
          run:
            kind: job
            init:
              - file:
                  content: |
                    echo 'This is a test.' | wc -w
                  filename: script.sh
                  chmod: "+x"
            container:
              image: polyaxon/polyaxon-quick-start
              workingDir: "{{ globals.artifacts_path }}"
              command: ['/bin/bash', '-c']
              args: ['./script.sh']
        filename: polyaxonfile.yaml
        chmod: "+x"
  container:
    image: polyaxon/polyaxon-cli
    workingDir: "{{ globals.artifacts_path }}"
    command: ['polyaxon', "check", '-f']
    args: ['polyaxonfile.yaml']