|
| 1 | +--- |
| 2 | +weight: 10 |
| 3 | +status: proposed |
| 4 | +title: Catalog Conventions |
| 5 | +creation-date: "2025-02-20" |
| 6 | +category: docs |
| 7 | +authors: |
| 8 | + - "@qingliu" |
| 9 | +--- |
| 10 | + |
| 11 | +# Catalog Conventions |
| 12 | + |
| 13 | +## Task Conventions |
| 14 | + |
| 15 | +### 1. Follow Community [Catalog](https://github.com/tektoncd/catalog) Conventions |
| 16 | + |
| 17 | +Catalog Structure |
| 18 | + |
| 19 | +1. Each resource follows the following structure |
| 20 | + |
| 21 | + ``` |
| 22 | + ./task/ 👈 the kind of the resource |
| 23 | +
|
| 24 | + /argocd 👈 definition file must have same name |
| 25 | + /0.1 |
| 26 | + /OWNERS 👈 owners of this resource |
| 27 | + /README.md |
| 28 | + /DEVELOPMENT.md 👈 development guide |
| 29 | + /argocd.yaml 👈 the file name should match the resource name |
| 30 | + /samples/deploy-to-k8s.yaml |
| 31 | + /0.2/... |
| 32 | +
|
| 33 | + /golang-build |
| 34 | + /OWNERS |
| 35 | + /README.md |
| 36 | + /0.1 |
| 37 | + /README.md |
| 38 | + /golang-build.yaml |
| 39 | + /samples/golang-build.yaml |
| 40 | + ``` |
| 41 | +
|
| 42 | +2. Resource YAML file includes following changes |
| 43 | + * Labels include the version of the resource. |
| 44 | + * Annotations include `minimum pipeline version` supported by the resource, |
| 45 | + `tags` associated with the resource and `displayName` of the resource |
| 46 | +
|
| 47 | + ```yaml |
| 48 | + |
| 49 | + labels: |
| 50 | + app.kubernetes.io/version: "0.1" 👈 Version of the resource, has to equal to the version in the file path, e.g. version == "0.1" in "example-task/0.1/example-task.yaml" |
| 51 | + |
| 52 | + annotations: |
| 53 | + tekton.dev/pipelines.minVersion: "0.12.1" 👈 Min Version of pipeline resource is compatible |
| 54 | + tekton.dev/categories: CLI 👈 Comma separated list of categories |
| 55 | + tekton.dev/tags: "ansible, cli" 👈 Comma separated list of tags |
| 56 | + tekton.dev/displayName: "Ansible Tower Cli" 👈 displayName can be optional |
| 57 | + tekton.dev/platforms: "linux/amd64,linux/s390x" 👈 Comma separated list of platforms, can be optional |
| 58 | + tekton.dev/icon: data:image/svg+xml;base64,{{ base64 icon data }} 👈 The base64 encoded svg icon, can be optional |
| 59 | + |
| 60 | + spec: |
| 61 | + description: |- |
| 62 | + ansible-tower-cli task simplifies |
| 63 | + workflow, jobs, manage users... 👈 Summary |
| 64 | + |
| 65 | + Ansible Tower (formerly 'AWX') is a ... |
| 66 | + |
| 67 | + ``` |
| 68 | +
|
| 69 | +**Note** : Categories are a generalized list and are maintained by Hub. To add new categories, please follow the procedure mentioned [here](https://github.com/tektoncd/hub/blob/main/docs/ADD_NEW_CATEGORY.md). |
| 70 | +
|
| 71 | +### 2. Use v1 Version of Task |
| 72 | +
|
| 73 | +Currently `tekton.dev/v1` is the default version, and this version does not have the `ClusterTask` resource type, therefore we recommend using the `v1` version of Task. |
| 74 | +
|
| 75 | +### 3. Specify Default Resources `computeResources` for Task |
| 76 | +
|
| 77 | +It is recommended that `Task` has a default `computeResources`, and users can override it through `TaskRun` if they need to adjust. |
| 78 | +
|
| 79 | +```yaml |
| 80 | +apiVersion: tekton.dev/v1 |
| 81 | +kind: Task |
| 82 | +metadata: |
| 83 | + name: foo |
| 84 | +spec: |
| 85 | + steps: |
| 86 | + - name: sonar-properties-create |
| 87 | + computeResources: |
| 88 | + requests: |
| 89 | + cpu: "1" |
| 90 | + memory: "1Gi" |
| 91 | + limits: |
| 92 | + cpu: "2" |
| 93 | + memory: "2Gi" |
| 94 | +``` |
| 95 | + |
| 96 | +```yaml |
| 97 | +apiVersion: tekton.dev/v1 |
| 98 | +kind: TaskRun |
| 99 | +metadata: |
| 100 | + name: foo-run |
| 101 | +spec: |
| 102 | + computeResources: |
| 103 | + requests: |
| 104 | + cpu: "2" |
| 105 | + memory: "2Gi" |
| 106 | + limits: |
| 107 | + cpu: "4" |
| 108 | + memory: "4Gi" |
| 109 | +``` |
| 110 | +
|
| 111 | +### 4. Building Custom Images with Dependencies |
| 112 | +
|
| 113 | +If Tasks in the catalog depend on custom images, we need to provide `Dockerfile` and build pipelines in the catalog. |
| 114 | + |
| 115 | +- Build environments are stored in the `images/{image-name}` directory |
| 116 | +- Image build pipeline orchestration files are stored in `.tekton/images/build-{image-name}.yaml` |
| 117 | + |
| 118 | +#### Image Security |
| 119 | + |
| 120 | +- For security considerations, it is recommended to create a `nonroot` user with ID `65532` as the default user when the image is finally executed. |
| 121 | +- It is also recommended to add `USER 65532` instead of `USER nonroot` in the `Dockerfile` to specify this user. |
| 122 | + - This is because when a Pod specifies `runAsNonRoot`, it cannot confirm that the user is non-root when using `USER nonroot`, which will result in a `CreateContainerConfigError`. |
| 123 | + |
| 124 | + ```dockerfile |
| 125 | + # Add a non-root user |
| 126 | + |
| 127 | + # For Alpine images |
| 128 | + RUN adduser -u 65532 -h /home/nonroot -D nonroot -s /sbin/nologin |
| 129 | + |
| 130 | + # For Debian, Ubuntu images |
| 131 | + RUN adduser --home /home/nonroot --uid 65532 nonroot --shell /usr/sbin/nologin --disabled-password --gecos "" |
| 132 | + |
| 133 | + # Set the default user |
| 134 | + USER 65532 |
| 135 | + ``` |
| 136 | + |
| 137 | +#### Image Tags |
| 138 | + |
| 139 | +If the image is custom, you can directly use the version number generated by `git-version` in the pipeline as the Tag. |
| 140 | + |
| 141 | +If the image is customized based on a specific community version, it is recommended to add the community version number as a prefix in the Tag. For example, `v0.56.0-{version}` |
| 142 | + |
| 143 | +In the pipeline, you can specify the image prefix by configuring the `tag-prefix` parameter. |
| 144 | + |
| 145 | +#### Image Path |
| 146 | + |
| 147 | +It is recommended to uniformly use `/devops/tektoncd/hub/` as the image path prefix for convenient image management in the future. |
| 148 | + |
| 149 | +### 5. Not Recommended to Specify `runAsUser` in Task Definitions that Support User Custom Images |
| 150 | + |
| 151 | +```yaml |
| 152 | +apiVersion: tekton.dev/v1 |
| 153 | +kind: Task |
| 154 | +metadata: |
| 155 | + name: foo |
| 156 | +spec: |
| 157 | + steps: |
| 158 | + - name: bar |
| 159 | + securityContext: |
| 160 | + runAsNonRoot: true |
| 161 | + # runAsUser: 65532 # Not recommended to specify in Task |
| 162 | +``` |
| 163 | + |
| 164 | +This is because after specifying the `runAsUser` configuration in the `step` of a `Task`, it is equivalent to configuring this property for a specific `Container` of the Pod. |
| 165 | +However, the `podTemplate` of `TaskRun` can currently only override this configuration at the `Pod` level and cannot override this configuration for a specific `Container`. |
| 166 | + |
| 167 | +If the user's base image must require a specific user (non-65532) to work properly, then this configuration may prevent users from using this `Task`. |
| 168 | + |
| 169 | +#### Exceptions |
| 170 | + |
| 171 | +For general script execution Tasks like `run-script`, **it is recommended to specify `runAsUser` in the Task** for the following reasons: |
| 172 | + |
| 173 | +1. The main purpose of such Tasks is to execute general scripts, and users usually don't need to customize base images for them |
| 174 | +2. Specifying `runAsUser` allows users to: |
| 175 | + - Directly use various standard images |
| 176 | + - Avoid additional configuration in `TaskRun` or `PipelineRun` |
| 177 | + - Improve ease of use |
| 178 | + |
| 179 | +> **Note**: This recommendation only applies to general script execution Tasks, other types of Tasks should still follow the above conventions. |
| 180 | + |
| 181 | +### 6. Tasks Need Integration Test Coverage |
| 182 | + |
| 183 | +Integration test pipelines can be placed in the `.tekton/integrations/{task-name}.yaml` directory. |
| 184 | + |
| 185 | +### 7. Unified Use of `registry.alauda.cn:60070` for Image Registry Addresses Referenced in Tasks |
| 186 | + |
| 187 | +Although the currently built images are usually `build-harbor.alauda.cn`, considering that this image address is inconvenient for integration testing. |
| 188 | +Therefore, it is temporarily recommended to uniformly use `registry.alauda.cn:60070` as the image registry address in Tasks. |
| 189 | + |
| 190 | +### 8. Task Display Names |
| 191 | + |
| 192 | +Task display names follow PascalCase convention, meaning the first letter is capitalized. |
| 193 | + |
| 194 | +| Description | Bad Case | Good Case | |
| 195 | +| --------------------------------------- | ----------------- | ----------------- | |
| 196 | +| First letter capitalized | buildah | Buildah | |
| 197 | +| First letter of each word capitalized | Sonarqube scanner | Sonarqube Scanner | |
| 198 | +| Multiple words separated by spaces, not `-`, `_` | RunScript | Run Script | |
| 199 | + |
| 200 | +### 9. Task HTTPS Certificates Handling |
| 201 | + |
| 202 | +When adding a new Task, cover the following cases: |
| 203 | + |
| 204 | +- Allow skipping certificate verification for HTTPS: expose a toggle parameter and clearly document the risks and when to use it. |
| 205 | +- Trust HTTPS via user-provided certificates: expose a workspace for mounting custom CAs/truststores. |
| 206 | +- If the tool uses a “full replacement” trust-store strategy: implement append/merge logic in the Task so user certificates are added to the default trust chain rather than overwriting it, preventing breaks to other HTTPS endpoints and improving UX. |
0 commit comments