catalog icon indicating copy to clipboard operation
catalog copied to clipboard

Add a script to help managing embedded scripts externally

Open chmouel opened this issue 3 years ago • 16 comments

The idea of this script is if you have inside your script something like this :

It will replace this #include with the content of python/script.py

This make it easier to write your tasks and use linters/code checkers from your editor on your included script.

This sparked from @afrittoli discussion here https://github.com/tektoncd/catalog/discussions/715

Currently this is a helper so this would be up to the contributor to uses it before commit but i think we can maybe think on how to do this post merge so to be transparent.

chmouel avatar May 26 '21 12:05 chmouel

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: To complete the pull request process, please assign chmouel You can assign the PR to them by writing /assign @chmouel in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

tekton-robot avatar May 26 '21 12:05 tekton-robot

a script to trigger this and write the output in the right place

how would that work tho?

In main we have the "#include script.py" template files? But users (including ides/tkn hub or even curl people) would expect to be able to run the task directly from main branch, isnt it ?

maybe we can have both, we could have a comment above the script: which would tell how to replace the script field to the CI jobs at post merge time, it would not matter the script content because the source of truth would be the #include script content.

Maybe that's a bit confusing, so let me rephrase my thinking :

  • Dev have task/foo/0.1/task.yaml
  • task.yaml has something like this :
steps:
   - name: foo
     #include foo.py
     script : | 
       #!/usr/bin/env python
       print("helo world")
  • dev do some changes inside the foo.py and submit as PR,
  • test-runner sees the #include and automatically test it with the new content from foo.py in script
  • We merge the PR
  • A post merge job would replace the script portion with the content from foo.py and commit back to catalog.

This allows user to have the latest task working directly and devs being able to develop into a real file for the script portion.

Let me know if that make sense 🙇🏻

chmouel avatar May 26 '21 14:05 chmouel

a script to trigger this and write the output in the right place

how would that work tho?

In main we have the "#include script.py" template files? But users (including ides/tkn hub or even curl people) would expect to be able to run the task directly from main branch, isnt it ?

maybe we can have both, we could have a comment above the script: which would tell how to replace the script field to the CI jobs at post merge time, it would not matter the script content because the source of truth would be the #include script content.

Maybe that's a bit confusing, so let me rephrase my thinking :

  • Dev have task/foo/0.1/task.yaml
  • task.yaml has something like this :
steps:
   - name: foo
     #include foo.py
     script : | 
       #!/usr/bin/env python
       print("helo world")
  • dev do some changes inside the foo.py and submit as PR,
  • test-runner sees the #include and automatically test it with the new content from foo.py in script
  • We merge the PR
  • A post merge job would replace the script portion with the content from foo.py and commit back to catalog.

I don't like this approach too much because it means that we need two commits to do a change, and in between commits the repo is in an inconsistent state.

This allows user to have the latest task working directly and devs being able to develop into a real file for the script portion.

Let me know if that make sense 🙇🏻

The workflow I had in mind is very much similar to what we have to generated golang files in pipeline and other repos.

  • Dev creates / updates the task in task/foo/0.1/task.yaml.template
  • task.yaml.template has something like this :
steps:
   - name: foo
     #include foo.py
     script : | 
       #!/usr/bin/env python
       print("helo world")
  • Dev creates / updates the script in task/foo/0.1/foo.py

  • Before committing, dev runs tools/embed-scripts.sh, which generates task/foo/0.1/task.yaml

  • CI runs tools/embed-scripts.sh and diffs. If differences are found it fails. Differences could happen if:

    • if the dev updated the script and did not run the embed tool
    • if the dev made changes into the generated task.yaml instead of the template / script
  • task/foo/0.1/task.yaml alone is published to the bundle

  • users only ever refer to task/foo/0.1/task.yaml

The paths / naming might change, we could have the template defined in a subfolder for instance, to "hide" it from users.

afrittoli avatar Jul 23 '21 13:07 afrittoli

@tektoncd/catalog-maintainers it would be nice to move forward on this - can we have a second reviewer?

afrittoli avatar Oct 15 '21 08:10 afrittoli

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale with a justification. Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

tekton-robot avatar Jan 13 '22 10:01 tekton-robot

/remove-lifecycle stale

i didnt see your review @vinamra28 🙇🏻

chmouel avatar Jan 13 '22 12:01 chmouel

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale with a justification. Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

tekton-robot avatar Apr 13 '22 12:04 tekton-robot

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten with a justification. Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle rotten

Send feedback to tektoncd/plumbing.

tekton-robot avatar May 13 '22 12:05 tekton-robot

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen with a justification. Mark the issue as fresh with /remove-lifecycle rotten with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/close

Send feedback to tektoncd/plumbing.

tekton-robot avatar Jun 12 '22 13:06 tekton-robot

@tekton-robot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen with a justification. Mark the issue as fresh with /remove-lifecycle rotten with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/close

Send feedback to tektoncd/plumbing.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Jun 12 '22 13:06 tekton-robot

/remove-lifecycle rotten /lifecycle frozen /reopen @chmouel any updates on this?

vinamra28 avatar Jun 13 '22 06:06 vinamra28

@vinamra28: Reopened this PR.

In response to this:

/remove-lifecycle rotten /lifecycle frozen /reopen @chmouel any updates on this?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Jun 13 '22 06:06 tekton-robot

@chmouel: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-tekton-catalog-integration-tests 3d32e30e86d477f8447338560d98cbb45492d550 link /test pull-tekton-catalog-integration-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

tekton-robot avatar Jun 13 '22 07:06 tekton-robot

I don't think it's trivial to do this, this will broke the "kuebctl apply -f https://github.com/tektoncd/catalog/path/to/task.yaml" maybe with this TEP which split the structure from the implementation we may be able to achive that but this probably need something extras on the hub end...

chmouel avatar Jun 13 '22 08:06 chmouel

I don't think it's trivial to do this, this will broke the "kuebctl apply -f https://github.com/tektoncd/catalog/path/to/task.yaml"

Not necessarily, it depends on how it's implemented. My suggestion would be:

  • store in the catalog the template (YAML without the scripts), the script and the rendered version
  • the rendered version would be stored in the same location as today
  • add a CI job that renders the final task (template + script) and checks that it matches the rendered version in the repo
  • provide catalog authors with a script to run to update all rendered tasks

maybe with this TEP which split the structure from the implementation we may be able to achive that but this probably need something extras on the hub end...

afrittoli avatar Jun 13 '22 10:06 afrittoli

Not necessarily, it depends on how it's implemented. My suggestion would be:

store in the catalog the template (YAML without the scripts), the script and the rendered version
the rendered version would be stored in the same location as today
add a CI job that renders the final task (template + script) and checks that it matches the rendered version in the repo

I think it may be a bit cumbersome for non frequent contributor, we have generation on cli for mans/golden etc.. and it's already a source of annoyances since it's easy to forget to run the command before sending the iteration.

What about CI job commiting to the repo the final rendered version directly to a branch?

alternatively if hub could do this transparently and we say that hub is the "only" trusted source, then we would not have to store the yaml in repo.

provide catalog authors with a script to run to update all rendered tasks

chmouel avatar Jun 13 '22 11:06 chmouel