Basics

Tasks are prefixed always with “:”. Each task can handle it’s own arguments.

Tasks arguments usage

makefile.py

from rkd.syntax import TaskDeclaration, TaskAliasDeclaration
from rkd.standardlib.python import PublishTask

IMPORTS = [
    TaskDeclaration(PublishTask())
]

TASKS = [
    TaskAliasDeclaration(':my:test', [':py:publish', '--username=...', '--password=...'])
]

Example of calling same task twice, but with different input

Notes for this example: The “username” parameter is a default defined in makefile.py in this case.

$ rkd :my:test --password=first :my:test --password=second
 >> Executing :py:publish
Publishing
{'username': '...', 'password': 'first'}

 >> Executing :py:publish
Publishing
{'username': '...', 'password': 'second'}

Example of calling same task twice, with no extra arguments

In this example the argument values “…” are taken from makefile.py

$ rkd :my:test :my:test
 >> Executing :py:publish
Publishing
{'username': '...', 'password': '...'}

 >> Executing :py:publish
Publishing
{'username': '...', 'password': '...'}

Example of –help per command:

$ rkd :my:test :my:test --help
usage: :py:publish [-h] [--username USERNAME] [--password PASSWORD]

optional arguments:
  -h, --help           show this help message and exit
  --username USERNAME  Username
  --password PASSWORD  Password

Simplified - YAML syntax

YAML syntax has an advantage of simplicity and clean syntax, custom bash tasks can be defined there easier than in Python. To use YAML you need to define makefile.yaml file in .rkd directory.

NOTICE: makefile.py and makefile.yaml can exist together. Python version will be loaded first, the YAML version will append changes in priority.

version: org.riotkit.rkd/0.3
imports:
  - rkd.standardlib.docker.TagImageTask

tasks:
  # see this task in "rkd :tasks"
  # run with "rkd :examples:bash-test"
  :examples:bash-test:
      description: Execute an example command in bash - show only python related tasks
      steps: |
             echo "RKD_DEPTH: ${RKD_DEPTH} # >= 2 means we are running rkd-in-rkd"
             echo "RKD_PATH: ${RKD_PATH}"
             rkd --silent :tasks | grep ":py"

  # try "rkd :examples:arguments-test --text=Hello --test-boolean"
  :examples:arguments-test:
      description: Show example usage of arguments in Bash
      arguments:
          "--text":
              help: "Adds text message"
              required: True
          "--test-boolean":
              help: "Example of a boolean flag"
              action: store_true # or store_false
      steps:
        - |
          #!bash
          echo " ==> In Bash"
          echo " Text: ${ARG_TEXT}"
          echo " Boolean test: ${ARG_TEST_BOOLEAN}"
        - |
          #!python
          print(' ==> In Python')
          print(' Text: %s ' % ctx.args['text'])
          print(' Text: %s ' % str(ctx.args['test_boolean']))
          return True

  # run with "rkd :examples:list-standardlib-modules"
  :examples:list-standardlib-modules:
      description: List all modules in the standardlib
      steps:
        - |
          #!python
          ctx: ExecutionContext
          this: TaskInterface

          import os

          print('Hello world')
          print(os)
          print(ctx)
          print(this)

          return True

What’s loaded first? See Paths and inheritance