Skip to content

Commit b6daece

Browse files
committed
update
1 parent 1193970 commit b6daece

File tree

1 file changed

+78
-108
lines changed

1 file changed

+78
-108
lines changed

doc/design.md

+78-108
Original file line numberDiff line numberDiff line change
@@ -202,127 +202,97 @@ def build_docker_image_from_git_source(
202202

203203
A Pipeline object is like function declaration.
204204

205-
A Pipeline in Tekton defined an ordered series of Tasks. A valid Pipeline declaration
206-
must include a reference to at last one `Task`, The `Pipeline Tasks` in a Pipeline can be connected and run as a Directed Acyclic Graph(DAG), each of the Pipeline Tasks is a node, which can be connected with:
205+
A Pipeline in Tekton defined an ordered series of Tasks. Users can specify whether
206+
the output of a `Task` is used as an input for the next `Task` using `from` property on `PipelineResources`
207207

208-
- `runAfter` clauses on the `Pipeline Tasks`.
209-
- `from` clauses on the `PipelineResources` needed by a `Task`.
210-
211-
The following example `Pipeline` spec comes from [Tekton's Pipeline tutorial](https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md):
208+
As the following example comes from [Tekton's tutorial](https://github.com/tektoncd/pipeline/blob/master/docs/tutorial.md#creating-and-running-a-pipeline)
212209

213210
``` yaml
214-
- name: lint-repo
215-
taskRef:
216-
name: pylint
217-
resources:
218-
inputs:
219-
- name: workspace
220-
resource: my-repo
221-
- name: test-app
222-
taskRef:
223-
name: make-test
224-
resources:
225-
inputs:
226-
- name: workspace
227-
resource: my-repo
228-
- name: build-app
229-
taskRef:
230-
name: kaniko-build-app
231-
runAfter:
232-
- test-app
233-
resources:
234-
inputs:
235-
- name: workspace
236-
resource: my-repo
237-
outputs:
238-
- name: image
239-
resource: my-app-image
240-
- name: build-frontend
241-
taskRef:
242-
name: kaniko-build-frontend
243-
runAfter:
244-
- test-app
245-
resources:
246-
inputs:
247-
- name: workspace
248-
resource: my-repo
249-
outputs:
250-
- name: image
251-
resource: my-frontend-image
252-
- name: deploy-all
253-
taskRef:
254-
name: deploy-kubectl
211+
apiVersion: tekton.dev/v1beta1
212+
kind: Pipeline
213+
metadata:
214+
name: tutorial-pipeline
215+
spec:
255216
resources:
256-
inputs:
257-
- name: my-app-image
258-
resource: my-app-image
259-
from:
260-
- build-app
261-
- name: my-frontend-image
262-
resource: my-frontend-image
263-
from:
264-
- build-frontend
265-
```
266-
267-
This will result the following execution graph:
268-
269-
``` text
270-
| |
271-
v v
272-
test-app lint-repo
273-
/ \
274-
v v
275-
build-app build-frontend
276-
\ /
277-
v v
278-
deploy-all
217+
- name: source-repo
218+
type: git
219+
- name: web-image
220+
type: image
221+
tasks:
222+
- name: build-skaffold-web
223+
taskRef:
224+
name: build-docker-image-from-git-source
225+
params:
226+
- name: pathToDockerFile
227+
value: Dockerfile
228+
- name: pathToContext
229+
value: /workspace/docker-source/examples/microservices/leeroy-web #configure: may change according to your source
230+
resources:
231+
inputs:
232+
- name: docker-source
233+
resource: source-repo
234+
outputs:
235+
- name: builtImage
236+
resource: web-image
237+
- name: deploy-web
238+
taskRef:
239+
name: deploy-using-kubectl
240+
resources:
241+
inputs:
242+
- name: source
243+
resource: source-repo
244+
- name: image
245+
resource: web-image
246+
from:
247+
- build-skaffold-web
248+
params:
249+
- name: path
250+
value: /workspace/source/examples/microservices/leeroy-web/kubernetes/deployment.yaml #configure: may change according to your source
251+
- name: yamlPathToImage
252+
value: "spec.template.spec.containers[0].image"
279253
```
280254

281-
In Python, a function is like a node of the DAG, which connected by the input
282-
and of output of the functions.
283-
284-
We hope Fluid users can write the following program to express a DAG with `fluid.pipeline` as the following code:
255+
We hope Fluid users can write the following program to express the above YAML file:
285256

286257
``` python
287-
288-
WORKSPACE = fluid.git_resource(
289-
url="https://github.com/GoogleContainerTools/skaffold",
290-
revision="master")
291-
292-
APP_IMAGE = fluid.image_resource()
293-
294-
FRONTED_IMAGE = fluid.image_resource()
295-
296-
@fluid.task
297-
def pylint(workspace:"input,git"):
298-
fluid.step(image="ubuntu", cmd=["pylint"])
299-
300-
@fluid.task
301-
def make_test(workspace:"input,git"):
302-
fluid.step(image="ubuntu", cmd=["make"], args=["test"])
303-
304258
@fluid.task
305-
def kaniko_build_app(workflow:"input,git", image:"output,image"):
306-
fluid.step(...)
307-
308-
@fluid.task
309-
def kaniko_build_frontend(workflow:"input,git", image:"output,image"):
310-
fluid.step(...)
259+
def build_docker_image_from_git_source(
260+
docker_source: "input,git",
261+
built_image: "output,image",
262+
path_to_dockerfile="/workspace/docker-source/Dockerfile",
263+
path_to_context="/workspace/docker-source"):
264+
'''Define a Tekton Task that builds a Docker image from a Git repo'''
265+
couler.step(image="gcr.io/kaniko-project/executor:v0.14.0",
266+
cmd=["/kaniko/executor"],
267+
args=[f"--dockerfile={path_to_dockerfile}",
268+
f"--destination={built_image.url}",
269+
f"--context={path_to_context}"],
270+
env={"DOCKER_CONFIG": "/tekton/home/.docker/"})
311271
312272
@fluid.task
313-
def deploy_kubectl(my_frontend_image:"input,image", my_app_image:"input,image"):
314-
fluid.step(...)
273+
def deploy_using_kubectl(
274+
docker_source:"input,git",
275+
web_image:"input,image",
276+
path_to_deployment="/workspace/source/examples/microservices/leeroy-web/kubernetes/deployment.yaml"):
277+
fluid.step(image="mikefarah/yq",
278+
cmd=["yq"],
279+
args=["w",
280+
"-i",
281+
f"{path_to_deployment}",
282+
"spec.template.spec.containers[0].image",
283+
f"{web_image.url}"])
284+
fluid.step(image="lachlanevenson/k8s-kubectl",
285+
cmd=["kubectl"],
286+
args=["--apply",
287+
"-f",
288+
f"{path_to_deployment}"])
315289
316290
@fluid.pipeline
317-
def dag_demo():
318-
lint_repo = pylint(WORKSPACE)
319-
test_app = make_test(WORKSPACE)
320-
build_app = kaniko_build_app(WORKSPACE, APP_IMAGE).run_after(test_app)
321-
build_frontend = kaniko_build_frontend(WORKSPACE, FRONTEND_IMAGE).run_after(test_app)
322-
323-
deploy_all = deploy_kubectl(APP_IMAGE, FRONTEND_IMAGE)
324-
deploy_all.my_frontend_image.from(build_app)
325-
deploy_all.my_app_image.from(build_frontend)
291+
def tutorial(source_repo:"resource,git", web_image="resource,image"):
292+
build_skaffold_web = build_docker_image_from_git_source(source_repo, web_image)
293+
294+
deploy_web = deploy_using_kubectl(source_repo, web_image)
295+
deploy_web.web_image.from(build_skaffold_web)
326296
```
327297

328298
### PipelineRun

0 commit comments

Comments
 (0)