Red Hat OpenShift Pipelines は、Kubernetes リソースをベースとしたクラウドネイティブの継続的インテグレーションおよび継続的デリバリー (CI/CD) ソリューションです。これは Tekton ビルディングブロックを使用し、基礎となる実装の詳細を抽象化して、複数のプラットフォームでのデプロイメントを自動化します。Tekton では、Kubernetes ディストリビューション間で移植可能な CI/CD パイプラインを定義するための標準のカスタムリソース定義 (CRD) が多数導入されています。
注記
Red Hat OpenShift Pipelines は OpenShift Container Platform とは異なる頻度でリリースされるため、Red Hat OpenShift Pipelines ドキュメントは製品のマイナーバージョンごとに個別のドキュメントセットとして利用できるようになりました。
Step は、イメージのビルドなど、Task によって順次実行され、特定の目的を達成するための一連のコマンドです。各タスクは Pod として実行され、各ステップは同じ Pod 内のコンテナーとして実行されます。Step は同じ Pod 内で実行されるため、ファイル、設定マップ、およびシークレットをキャッシュするために同じボリュームにアクセスできます。
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: guarded-pr-
spec:
taskRunTemplate:
serviceAccountName: pipeline
pipelineSpec:
params:
- name: path
type: string
description: The path of the file to be created
workspaces:
- name: source
description: |
This workspace is shared among all the pipeline tasks to read/write common resources
tasks:
- name: create-file
when:
- input: "$(params.path)"
operator: in
values: ["README.md"]
workspaces:
- name: source
workspace: source
taskSpec:
workspaces:
- name: source
description: The workspace to create the readme file in
steps:
- name: write-new-stuff
image: ubuntu
script: 'touch $(workspaces.source.path)/README.md'
- name: check-file
params:
- name: path
value: "$(params.path)"
workspaces:
- name: source
workspace: source
runAfter:
- create-file
taskSpec:
params:
- name: path
workspaces:
- name: source
description: The workspace to check for the file
results:
- name: exists
description: indicates whether the file exists or is missing
steps:
- name: check-file
image: alpine
script: |
if test -f $(workspaces.source.path)/$(params.path); then
printf yes | tee /tekton/results/exists
else
printf no | tee /tekton/results/exists
fi
- name: echo-file-exists
when:
- input: "$(tasks.check-file.results.exists)"
operator: in
values: ["yes"]
taskSpec:
steps:
- name: echo
image: ubuntu
script: 'echo file exists'
...
- name: task-should-be-skipped-1
when:
- input: "$(params.path)"
operator: notin
values: ["README.md"]
taskSpec:
steps:
- name: echo
image: ubuntu
script: exit 1
...
finally:
- name: finally-task-should-be-executed
when:
- input: "$(tasks.echo-file-exists.status)"
operator: in
values: ["Succeeded"]
- input: "$(tasks.status)"
operator: in
values: ["Succeeded"]
- input: "$(tasks.check-file.results.exists)"
operator: in
values: ["yes"]
- input: "$(params.path)"
operator: in
values: ["README.md"]
taskSpec:
steps:
- name: echo
image: ubuntu
script: 'echo finally done'
params:
- name: path
value: README.md
workspaces:
- name: source
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 16Mi
apiVersion: tekton.dev/v1
kind: PipelineRun
1
metadata:generateName: guarded-pr-spec:taskRunTemplate:serviceAccountName: pipeline
pipelineSpec:params:-name: path
type: string
description: The path of the file to be created
workspaces:-name: source
description:|
This workspace is shared among all the pipeline tasks to read/write common resourcestasks:-name: create-file
2
when:-input:"$(params.path)"operator: in
values:["README.md"]workspaces:-name: source
workspace: source
taskSpec:workspaces:-name: source
description: The workspace to create the readme file in
steps:-name: write-new-stuff
image: ubuntu
script:'touch $(workspaces.source.path)/README.md'-name: check-file
params:-name: path
value:"$(params.path)"workspaces:-name: source
workspace: source
runAfter:- create-file
taskSpec:params:-name: path
workspaces:-name: source
description: The workspace to check for the file
results:-name: exists
description: indicates whether the file exists or is missing
steps:-name: check-file
image: alpine
script:|
if test -f $(workspaces.source.path)/$(params.path); then
printf yes | tee /tekton/results/exists
else
printf no | tee /tekton/results/exists
fi-name: echo-file-exists
when:
3
-input:"$(tasks.check-file.results.exists)"operator: in
values:["yes"]taskSpec:steps:-name: echo
image: ubuntu
script:'echo file exists'...-name: task-should-be-skipped-1when:
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: build-and-deploy
spec:
workspaces:
- name: shared-workspace
params:
- name: deployment-name
type: string
description: name of the deployment to be patched
- name: git-url
type: string
description: url of the git repo for the code of deployment
- name: git-revision
type: string
description: revision to be used from repo of the code for deployment
default: "pipelines-1.19"
- name: IMAGE
type: string
description: image to be built from the code
tasks:
- name: fetch-repository
taskRef:
resolver: cluster
params:
- name: kind
value: task
- name: name
value: git-clone
- name: namespace
value: openshift-pipelines
workspaces:
- name: output
workspace: shared-workspace
params:
- name: URL
value: $(params.git-url)
- name: SUBDIRECTORY
value: ""
- name: DELETE_EXISTING
value: "true"
- name: REVISION
value: $(params.git-revision)
- name: build-image
taskRef:
resolver: cluster
params:
- name: kind
value: task
- name: name
value: buildah
- name: namespace
value: openshift-pipelines
workspaces:
- name: source
workspace: shared-workspace
params:
- name: TLSVERIFY
value: "false"
- name: IMAGE
value: $(params.IMAGE)
runAfter:
- fetch-repository
- name: apply-manifests
taskRef:
name: apply-manifests
workspaces:
- name: source
workspace: shared-workspace
runAfter:
- build-image
- name: update-deployment
taskRef:
name: update-deployment
workspaces:
- name: source
workspace: shared-workspace
params:
- name: deployment
value: $(params.deployment-name)
- name: IMAGE
value: $(params.IMAGE)
runAfter:
- apply-manifests
apiVersion: tekton.dev/v1
1
kind: Pipeline
2
metadata:name: build-and-deploy
3
spec:
4
workspaces:
5
-name: shared-workspace
params:
6
-name: deployment-name
type: string
description: name of the deployment to be patched
-name: git-url
type: string
description: url of the git repo for the code of deployment
-name: git-revision
type: string
description: revision to be used from repo of the code for deployment
default:"pipelines-1.19"-name: IMAGE
type: string
description: image to be built from the code
tasks:
apiVersion: tekton.dev/v1
kind: StepAction
metadata:
name: apply-manifests-action
spec:
params:
- name: working_dir
description: The working directory where the source is located
type: string
default: "/workspace/source"
- name: manifest_dir
description: The directory in source that contains yaml manifests
default: "k8s"
results:
- name: output
description: The output of the oc apply command
image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
env:
- name: MANIFEST_DIR
value: $(params.manifest_dir)
workingDir: $(params.working_dir)
script: |
#!/usr/bin/env bash
oc apply -f "$MANIFEST_DIR" | tee $(results.output)
apiVersion: tekton.dev/v1
kind: StepAction
metadata:name: apply-manifests-action
spec:params:-name: working_dir
description: The working directory where the source is located
type: string
1
default:"/workspace/source"-name: manifest_dir
description: The directory in source that contains yaml manifests
default:"k8s"results:-name: output
description: The output of the oc apply command
image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
env:-name: MANIFEST_DIR
value: $(params.manifest_dir)
workingDir: $(params.working_dir)
script:|
#!/usr/bin/env bash
oc apply -f "$MANIFEST_DIR" | tee $(results.output)
Copy to ClipboardCopied!Toggle word wrapToggle overflow
たとえば、アプリケーションの Red Hat OpenShift Pipelines を使用して CI/CD ワークフローを定義します。アプリケーションリポジトリーで新たな変更を有効にするには、パイプラインを開始する必要があります。トリガーは変更イベントをキャプチャーし、処理することにより、また新規イメージを最新の変更でデプロイするパイプライン実行をトリガーして、このプロセスを自動化します。
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: vote-app
spec:
params:
- name: git-repo-url
description: The git repository url
- name: git-revision
description: The git revision
default: pipelines-1.19
- name: git-repo-name
description: The name of the deployment to be created / patched
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: build-deploy-$(tt.params.git-repo-name)-$(uid)
spec:
taskRunTemplate:
serviceAccountName: pipeline
pipelineRef:
name: build-and-deploy
params:
- name: deployment-name
value: $(tt.params.git-repo-name)
- name: git-url
value: $(tt.params.git-repo-url)
- name: git-revision
value: $(tt.params.git-revision)
- name: IMAGE
value: image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/$(tt.params.git-repo-name)
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
apiVersion: triggers.tekton.dev/v1beta1
1
kind: TriggerTemplate
2
metadata:name: vote-app
3
spec:params:
4
-name: git-repo-url
description: The git repository url
-name: git-revision
description: The git revision
default: pipelines-1.19-name: git-repo-name
description: The name of the deployment to be created / patched
resourcetemplates:
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.