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 customization examples #122

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

Conversation

Hyperkid123
Copy link

@Hyperkid123 Hyperkid123 commented Aug 27, 2024

Based on a conversation with the Konflux engineers, I've added a couple of examples to the docs which might help others in the future.

Changes

  • added an example of how to add a task that generates TA and how to consume it
  • added an example of how to add a task with sidecar containers

@lcarva
Copy link
Contributor

lcarva commented Aug 27, 2024

/ok-to-test

Copy link

github-actions bot commented Sep 9, 2024

🚀 Preview is available at https://pr-122--konflux-docs.netlify.app

Copy link
Member

@arewm arewm left a comment

Choose a reason for hiding this comment

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

Do you think that it would make adding content like this easier if we split up customizing the build pipeline more? For example, we can have a generic customization and then a separate one which is specific to the OCI trusted artifacts?

Comment on lines 196 to 219
- name: clone-repository-oci-ta
params:
- name: url
value: $(params.git-url)
- name: revision
value: $(params.revision)
- name: ociStorage
# needs to be unique storage name
value: $(params.output-image).git
runAfter:
- init
taskRef:
params:
- name: name
value: git-clone-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-git-clone-oci-ta@sha256:0f4360ce144d46171ebd2e8f4d4575539a0600e02208ba5fc9beeb2c27ddfd4c
- name: kind
value: task
resolver: bundles
workspaces:
# use the git-auth workspace for credentials
- name: basic-auth
workspace: git-auth
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the definition for the default git-clone task. Are you suggesting that users add this or are you just using this as an example to show the different parts? If the latter, I think we should use a different pattern.

Copy link
Author

Choose a reason for hiding this comment

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

If we want to use the TA for custom tasks to comply with the EC, we have to use the quay.io/konflux-ci/tekton-catalog/task-git-clone-oci-ta. We had to add it as a new task.

It is practically the same as the default task. But the default task uses workspaces which means custom tasks will breach the EC.

Comment on lines 203 to 204
# needs to be unique storage name
value: $(params.output-image).git
Copy link
Member

Choose a reason for hiding this comment

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

It needs to be globally unique within the pipeline definition, righ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I'll make the comment more specific

Comment on lines 232 to 234
# make sure the task runs after the artifact is created
runAfter:
- clone-repository-oci-ta
Copy link
Member

Choose a reason for hiding this comment

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

Is this strictly necessary? Tekton should be able to order the TaskRuns (but the visualization may be better with the runAfters defined.

Copy link
Author

Choose a reason for hiding this comment

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

I wanted to make it obvious and follow the pattern of the generated tekton config provided by Konflux.

runAfter:
- clone-repository-oci-ta
params:
# store the trusted artifact
Copy link
Member

Choose a reason for hiding this comment

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

This implies that we are storing the artifact here, but we are not. We are resolving the OCI artifact that has been previously stored, right?

Copy link
Author

Choose a reason for hiding this comment

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

Correct. Poor choice of words.

Comment on lines 239 to 270
taskSpec:
params:
- description: The Trusted Artifact URI pointing to the artifact with the application source code.
name: SOURCE_ARTIFACT
type: string
volumes:
# New volume to store a copy of the source code accessible only to this Task.
- name: workdir
emptyDir: {}

stepTemplate:
volumeMounts:
- mountPath: /var/workdir
name: workdir
steps:
# Add the trusted artifact to the task volume
- name: use-trusted-artifact
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:8391272c4e5011120e9e7fee2c1f339e9405366110bf239dadcbc21e953ce099
args:
- use
- $(params.SOURCE_ARTIFACT)=/var/workdir/source
- name: task-run
# set the working directory to value from previous step
workingDir: /var/workdir/source
# Use image that suites your use case
image: registry.access.redhat.com/ubi8/minimal
securityContext:
# If the task step needs write access to the volume, set the runAsUser to 0 (root).
runAsUser: 0
script: |
#!/bin/bash
# Execute the task
Copy link
Member

Choose a reason for hiding this comment

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

This ends up being a lot of rendered yaml content. Would it be better to just reference an example in some repository that has the content annotated, to reference some annotated "sample" task definition that has the required steps, or to just have smaller snippets of code isolated to the specific requirements?

Copy link
Author

Choose a reason for hiding this comment

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

We have a sample here: https://github.com/RedHatInsights/chrome-service-backend/blob/main/.tekton/chrome-service-pull-request.yaml#L476-L514

If you prefer linking to an existing example I ok with that.

Comment on lines 341 to 343
You can add sidecar containers to the build pipeline to run additional tasks alongside the main container. For example, you can add a sidecar container to run a database to enable your unit tests to run against a real database.

In the example, we add a sidecar container to task to run a PostgreSQL database. Such sidecar can be used to test database seeding, migrations, etc.
Copy link
Member

Choose a reason for hiding this comment

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

Is the primary use case for this unit tests? If so, should we add this to the testing pages?

Copy link
Author

Choose a reason for hiding this comment

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

Is the primary use case for this unit tests?

Correct.

Comment on lines 398 to 402
- name: use-trusted-artifact
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:8391272c4e5011120e9e7fee2c1f339e9405366110bf239dadcbc21e953ce099
args:
- use
- $(params.SOURCE_ARTIFACT)=/var/workdir
Copy link
Member

Choose a reason for hiding this comment

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

I guess that this is just needed if your sidecar content is pulled from the git source? This code snippet isn't in the TA section so we need to be careful about the actual content we include without explaining it further.

Copy link
Author

Choose a reason for hiding this comment

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

It is yeah. The main purpose of these examples is to show how to extend pipelines with custom tasks and comply with the EC. But I can see your point. Maybe instead of these full examples, it should be made very obvious that pipeline customizations need a different approach, especially if the builds are using "external" policies not defined by the project itself.

- mountPath: /var/workdir
name: workdir
# define the sidecar containers
sidecars:
Copy link
Member

Choose a reason for hiding this comment

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

The content of this feels too specific again which results in the snippet being too large.

Copy link
Author

Choose a reason for hiding this comment

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

We can link to an existing example if you'd like.

steps:
# Add the trusted artifact to the task volume
- name: use-trusted-artifact
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:8391272c4e5011120e9e7fee2c1f339e9405366110bf239dadcbc21e953ce099
Copy link
Member

Choose a reason for hiding this comment

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

We should use pullspecs from quay.io/konflux-ci wherever possible.

Copy link
Author

Choose a reason for hiding this comment

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

Is there an equivalent spec in the konflux-ci org? I did not find any.

If you are using the Enterprise Contract (EC) to verify your builds, you can extend the build pipeline with your own tasks using Trusted Artifacts. Trusted Artifacts allow you to share data between Tasks in a secure way. For example, the `task-git-clone` task, has Trusted Artifacts version called `task-git-clone-oci-ta`.
[NOTE]
====
You can find more tasks link:https://quay.io/organization/konflux-ci[here]. Task generating Trusted Artifacts have `-oci-ta` suffix.
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 link to quay or to the build definitions?

Copy link
Author

Choose a reason for hiding this comment

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

We could link here: https://github.com/konflux-ci/build-definitions/tree/main/task, these do not have the image repository links. So one does not really know form where to pull the images. So right now, probably link to both?

Signed-off-by: Martin Marosi <[email protected]>

Signed-off-by: Martin Marosi <[email protected]>
@Hyperkid123
Copy link
Author

@arewm I've updated the PR. Removed some of the YAML and moved the sidecar example to the testing section. I've also added links to existing pipelines so folks can get the full context. I am not linking directly to the task's code lines. They will likely change in the future and the links might lead to a different spec.

Let me know what you think 🙂 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants