Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to help managing embedded scripts externally #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented May 26, 2021

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 #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.

@tekton-robot
Copy link

[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 tekton-robot requested review from kimsterv and a user May 26, 2021 12:54
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 26, 2021
Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for starting this!

I think it's fine to have it under a test folder at least for now - eventually we might want some way to make it easier for contributors to include this in their workflow... perhaps a make target or a shell script.

Eventually we'll need

  • unit tests for this python
  • a script to trigger this and write the output in the right place
  • a CI job to run the script and check that generated YAMLs are up to date

But not in this PR :)

/lgtm

script: "#include script.sh"
```

The script will see it and includes the `script.sh` in place of your "#include script.sh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to document that the result is sent to stdout and that if more than one YAML docs is in the source, all be parsed and separated by ---.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 👍🏻

REGEXP = r"^#include\s*([^$]*)"


def replace(filename: str) -> typing.List:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we should have unit tests 🙏

Copy link
Member Author

@chmouel chmouel May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I added some, i didn't bother because we don't have ways to run them yet 😅

I usually use pytest but i guess python builtin unittest should be enough for this so we can just python3 the test file directly and it will run them.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 26, 2021
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.
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label May 26, 2021
@chmouel
Copy link
Member Author

chmouel commented May 26, 2021

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 🙇🏻

@afrittoli
Copy link
Member

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.

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great start, thank you!
We'll need to create an infra image that embeds the script, so we can use it to run a CI job.
For that we'll need a docker file and a requirements.txt, but we can add those in a follow up.
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2021
@afrittoli
Copy link
Member

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

spec:
steps:
- name: step1
script: "#include script.sh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about keeping it like ⬇️ ?

Suggested change
script: "#include script.sh"
script: "#include /path/to/script.sh"

script: "#include script.sh"
```

The "embed_script" script will see it and includes the `script.sh` in place of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The "embed_script" script will see it and includes the `script.sh` in place of
The "embed_script" script will see it in the specified path and includes the `script.sh` in place of

Comment on lines +2 to +14
# Author: Chmouel Boudjnah <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change this as well to Tekton Authors?

@tekton-robot
Copy link

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 tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 13, 2022
@chmouel
Copy link
Member Author

chmouel commented Jan 13, 2022

/remove-lifecycle stale

i didnt see your review @vinamra28 🙇🏻

@tekton-robot tekton-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 13, 2022
@tekton-robot
Copy link

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 tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 13, 2022
@tekton-robot
Copy link

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 tekton-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 13, 2022
@tekton-robot
Copy link

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
Copy link

@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.

@vinamra28
Copy link
Member

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

@tekton-robot
Copy link

@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 tekton-robot reopened this Jun 13, 2022
@tekton-robot tekton-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Jun 13, 2022
@tekton-robot
Copy link

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

Test name Commit Details Rerun command
pull-tekton-catalog-integration-tests 3d32e30 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.

@chmouel
Copy link
Member Author

chmouel commented Jun 13, 2022

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...

@afrittoli
Copy link
Member

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...

@chmouel
Copy link
Member Author

chmouel commented Jun 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants