defenseunicorns / maru-runner

The Unicorn Task Runner
Apache License 2.0
11 stars 1 forks source link

Improve Task dependency logic #166

Open JaseKoonce opened 3 weeks ago

JaseKoonce commented 3 weeks ago

As of right now I find it very difficult to architect tasks in a way that they work well if they are invoked from either the main task file or independently (uds run deploy-all vs uds run deploy:deploy-uds-core).

Sorry for the long example, struggling to explain in a simpler or less verbose manner. example:

Tasks.yaml

includes:
  - setup: ./tasks/setup.yaml
  - deploy: ./tasks/deploy.yaml

tasks:
  - name: deploy-all
    description: "Use the pre-published Bundle and deploy all uds-core prerequisites and the uds-bundle"
    actions:
      - task: setup:complete-setup
      - task: deploy:complete-deploy
deploy.yaml

tasks:

  - name: complete-deploy
    description: "Chain together all the tasks needed for a regular uds core deployment"
    actions:
      - task: deploy-base-bundle
      - task: deploy-core-bundle

  - name: deploy-base-bundle
    description: "Deploy the UDS Core Standard Bundle"
    actions:
      - cmd: echo "deploying uds bundle for ${ENV}"
      - cmd: sleep 7 # give time to cancel if its the wrong environment
      - cmd: "uds deploy ${BASE_BUNDLE_OCI_URL} --confirm --no-progress"
        dir: "bundles/${ENV}"

  - name: deploy-core-bundle
    description: "Deploy the UDS Core Standard Bundle"
    actions:
      - cmd: echo "deploying uds bundle for ${ENV}"
      - cmd: sleep 7 # give time to cancel if its the wrong environment
      - cmd: "uds deploy ${CORE_BUNDLE_OCI_URL} --confirm --no-progress && echo succeeded || echo failed"
        dir: "bundles/${ENV}"
        setVariables:
          - name: STATUS

Explanation of issue:

Based on the files I provided you can run uds run deploy-all and everything will work fine. A pre-req for either of the deployment tasks are the setup tasks. What I am struggling with is how I can extend this pattern in a way that my tasks work well when invoked from either a global task or the individual task (uds run deploy-all vs uds run deploy:deploy-uds-core) . To dive further into the issues my options to fix the issue is to add the "setup" tasks as actions for all of the deploy tasks:

 - name: deploy-core-bundle
    description: "Deploy the UDS Core Standard Bundle"
    actions:
      - task: *all the setup pre-reqs
      - cmd: echo "deploying uds bundle for ${ENV}"
      - cmd: sleep 7 # give time to cancel if its the wrong environment
      - cmd: "uds deploy ${CORE_BUNDLE_OCI_URL} --confirm --no-progress && echo succeeded || echo failed"
        dir: "bundles/${ENV}"
        setVariables:
          - name: STATUS

Once you do this all the tasks will work both from the global or individual task, but now I repeat unnecessary tasks when i invoke the global tasks. Another option is to remove the setup task from the global task and instead only include them in the deploy task. This is probably the best way to do it currently, but could really muddy up our task files.

Tasks.yaml

includes:
   // ~REMOVED~//
  - deploy: ./tasks/deploy.yaml

tasks:
  - name: deploy-all
    description: "Use the pre-published Bundle and deploy all uds-core prerequisites and the uds-bundle"
    actions:
      // ~REMOVED~//
      - task: deploy:complete-deploy
deploy.yaml # We now have to include the setup tasks in this file

 - name: deploy-core-bundle
    description: "Deploy the UDS Core Standard Bundle"
    actions:
      - task: *all the setup pre-reqs
      - cmd: echo "deploying uds bundle for ${ENV}"
      - cmd: sleep 7 # give time to cancel if its the wrong environment
      - cmd: "uds deploy ${CORE_BUNDLE_OCI_URL} --confirm --no-progress && echo succeeded || echo failed"
        dir: "bundles/${ENV}"
        setVariables:
          - name: STATUS

Describe the solution you'd like

Possibly adding a way to define task dependencies and detect whether or not they have ran previously.