1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-21 05:55:35 +00:00
catalog/task/replace-tokens/0.1
vinamra28 e763a4473e Use latest git-clone in Task's tests
With git-clone version 0.8 and onwards, it started running as non-root
and GKE clusters were having some issues, so, we temporarily moved all
tasks to use git-clone version 0.7. Ref: https://github.com/tektoncd/catalog/pull/1079

Since we have now moved to kind clusters in our CI, this issue is now
resolved and thus moving all tasks to use latest version of git-clone

Signed-off-by: vinamra28 <jvinamra776@gmail.com>
2023-09-22 09:32:22 +01:00
..
tests Use latest git-clone in Task's tests 2023-09-22 09:32:22 +01:00
README.md [TEP-0110] Update Tekton Catalog installation instructions 2022-08-16 16:25:52 +01:00
replace-tokens.yaml Add linux/amd64 platform annotation to the rest of the tasks 2021-10-29 17:08:38 +01:00

Replace Tokens

This task can be used to replace tokens in a file. The supported file types are YAML and JSON. The following task can be explained by taking an example of a JSON file :-

config.json

{
  "image": "$(image)",
  "server": "$(server)",
  "dbname": "$(dbname)",
  "password": "$(dbpass)"
}

token.json

{
  "image": "ubuntu",
  "server": "localhost:3306",
  "dbname": "tektondb",
  "dbpass": "tektonpass"
}

After replacing the config.json becomes:-

{
  "image": "ubuntu",
  "server": "localhost:3306",
  "dbname": "tektondb",
  "password": "tektonpass"
}

The above same can be done for the YAML file also.

Install the Task

kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/replace-tokens/0.1/raw

Parameters

  • inputFilePath: The file path whose value needs to be replaced.

Resources

  • Persistent Volume claim to store the json file, in which token is replaced.
  • ConfigMap contains file tokens.json or token.yaml which stores the tokens and corresponding value that need to be replaced.
  • Workspace to mount file containing tokens and its corresponding value, and PVC to store the replaced file.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: replace-tokens-source-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi

Platforms

The Task can be run on linux/amd64 platform.

Usage

This task will use the input param inputFilePath, this is provided by the git clone task, which clones the target repository containing the json or yaml file to be replaced.

ConfigMap is created from the tokens.json or tokens.yaml file, which contains tokens and its corresponding value that needs to be replaced. ConfigMap is mounted in the workspace, which is used in the task to access the tokens.json or tokens.yaml file. ConfigMap should be created using this file. Following command can be used to create congfigmap from the file.

kubectl create configmap tokens-configmap --from-file=tokens.json

or

apiVersion: v1
kind: ConfigMap
metadata:
  name: tokens-configmap
data:
  tokens.json: |
    { "hello":"bye", "fortnite":"league of legends", "github":"tekton" }

Create the Pipeline and PipelineRun

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: replace-tokens-pipeline
spec:
  workspaces:
    - name: shared-workspace
    - name: json-workspace
  tasks:
    - name: fetch-repository
      taskRef:
        name: git-clone
      workspaces:
        - name: output
          workspace: shared-workspace
      params:
        - name: url
          value: https://github.com/vinamra28/replace-tokens-plugin.git
        - name: subdirectory
          value: ""
        - name: deleteExisting
          value: "true"
    - name: replace-tokens
      taskRef:
        name: replace-tokens
      params:
        - name: inputFilePath
          value: "./sample1.json"
      runAfter:
        - fetch-repository
      workspaces:
        - name: source
          workspace: shared-workspace
        - name: token
          workspace: json-workspace
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: replace-tokens-pipeline-run
spec:
  pipelineRef:
    name: replace-tokens-pipeline
  workspaces:
    - name: shared-workspace
      persistentvolumeclaim:
        claimName: replace-tokens-source-pvc
    - name: json-workspace
      configmap:
        name: tokens-configmap