はじめに
TektonのCatalogを使ってGitHubの公開レポジトリからクローンする。
Tektonの実行
こちらのコードを参考に、GitHubの公開レポジトリからクローンする。
クローンするレポジトリは適当に以下を選択した。
https://github.com/vaadin/hello-world.git
# catalogのデプロイ $ git clone https://github.com/tektoncd/catalog $ kubectl apply -f catalog/task/git-clone/0.9/git-clone.yaml #task作成 $ cat > task-clone-read.yaml << "EOF" apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: show-readme spec: description: Read and display README file. workspaces: - name: source steps: - name: read image: alpine:latest script: | #!/usr/bin/env sh cat $(workspaces.source.path)/README.md EOF #pipeline作成 $ cat > pipline-clone-read.yaml << "EOF" apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: name: clone-read spec: description: | This pipeline clones a git repo, then echoes the README file to the stout. params: - name: repo-url type: string description: The git repo URL to clone from. workspaces: - name: shared-data description: | This workspace contains the cloned repo files, so they can be read by the next task. # - name: git-credentials # description: My ssh credentials tasks: - name: fetch-source taskRef: name: git-clone workspaces: - name: output workspace: shared-data # - name: ssh-directory # workspace: git-credentials params: - name: url value: $(params.repo-url) - name: show-readme runAfter: ["fetch-source"] taskRef: name: show-readme workspaces: - name: source workspace: shared-data EOF #pipelinerun作成 $ cat > piplinerun-clone-read.yaml << "EOF" apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: clone-read-run spec: pipelineRef: name: clone-read podTemplate: securityContext: fsGroup: 65532 workspaces: - name: shared-data volumeClaimTemplate: spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi # - name: git-credentials # secret: # secretName: git-credentials params: - name: repo-url value: https://github.com/vaadin/hello-world.git EOF #デプロイ $ kubectl apply -f task-clone-read.yaml $ kubectl apply -f pipline-clone-read.yaml $ kubectl apply -f piplinerun-clone-read.yaml
これにより、taksでデプロイされたpodのlogにGitHubのREADME.mdの内容が出力されていることを確認した。