Skip to content

Commit 3f38e1d

Browse files
authored
Merge pull request #2822 from marlon-gamez/pipeline-example
add example for skaffold generate-pipeline
2 parents eae79c8 + a79170c commit 3f38e1d

File tree

13 files changed

+272
-2
lines changed

13 files changed

+272
-2
lines changed

examples/generate-pipeline/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM golang:1.12.9-alpine3.10 as builder
2+
COPY main.go .
3+
RUN go build -o /app main.go
4+
5+
FROM alpine:3.10
6+
CMD ["./app"]
7+
COPY --from=builder /app .
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== Example: Getting started with skaffold and CI/CD using Tekton
2+
:icons: font
3+
4+
This is a simple example to show users how to run the generate-pipeline command
5+
6+
_Please keep in mind that the generate-pipeline command is still a WIP_
7+
8+
Prerequisites:
9+
10+
* Install tekton on your cluster (https://github.com/tektoncd/pipeline/blob/master/docs/install.md)
11+
* Have kaniko secrets setup (https://github.com/GoogleContainerTools/kaniko)
12+
* Container registry must be public
13+
* Give your default service account the cluster-admin role (necessary to have pipeline access secrets)
14+
----
15+
kubectl create clusterrolebinding serviceaccounts-cluster-admin \
16+
--clusterrole=cluster-admin \
17+
--user=system:serviceaccount:default:default
18+
----
19+
20+
To generate and run a pipeline:
21+
22+
* Run skaffold generate-pipeline
23+
* Modify skaffold.yaml to use a valid GCSbucket for kaniko
24+
* Commit and push updated skaffold.yaml
25+
* kubectl apply -f pipeline.yaml
26+
* Create a pipelinerun.yaml
27+
* kubectl apply -f pipelinerun.yaml
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: generate-pipeline
5+
spec:
6+
containers:
7+
- name: generate-pipeline
8+
image: gcr.io/k8s-skaffold/pipeline-example

examples/generate-pipeline/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
for {
10+
fmt.Println("Hello world!")
11+
12+
time.Sleep(time.Second * 1)
13+
}
14+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: skaffold/v1beta14
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: gcr.io/k8s-skaffold/pipeline-example
6+
deploy:
7+
kubectl:
8+
manifests:
9+
- k8s-*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM golang:1.12.9-alpine3.10 as builder
2+
COPY main.go .
3+
RUN go build -o /app main.go
4+
5+
FROM alpine:3.10
6+
CMD ["./app"]
7+
COPY --from=builder /app .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== Example: Getting started with skaffold and CI/CD using Tekton
2+
:icons: font
3+
4+
This is a simple example to show users how to run the generate-pipeline command
5+
6+
_Please keep in mind that the generate-pipeline command is still a WIP_
7+
8+
Prerequisites:
9+
10+
* Install tekton on your cluster (https://github.com/tektoncd/pipeline/blob/master/docs/install.md)
11+
* Have kaniko secrets setup (https://github.com/GoogleContainerTools/kaniko)
12+
* Container registry must be public
13+
* Give your default service account the cluster-admin role (necessary to have pipeline access secrets)
14+
----
15+
kubectl create clusterrolebinding serviceaccounts-cluster-admin \
16+
--clusterrole=cluster-admin \
17+
--user=system:serviceaccount:default:default
18+
----
19+
20+
To generate and run a pipeline:
21+
22+
* Run skaffold generate-pipeline
23+
* Modify skaffold.yaml to use a valid GCSbucket for kaniko
24+
* Commit and push updated skaffold.yaml
25+
* kubectl apply -f pipeline.yaml
26+
* Create a pipelinerun.yaml
27+
* kubectl apply -f pipelinerun.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
apiVersion: tekton.dev/v1alpha1
2+
kind: PipelineResource
3+
metadata:
4+
creationTimestamp: null
5+
name: source-git
6+
spec:
7+
params:
8+
- name: url
9+
value: this-is-a-test
10+
type: git
11+
status: {}
12+
---
13+
apiVersion: tekton.dev/v1alpha1
14+
kind: Task
15+
metadata:
16+
creationTimestamp: null
17+
name: skaffold-build-0
18+
spec:
19+
inputs:
20+
resources:
21+
- name: source
22+
outputImageDir: ""
23+
targetPath: ""
24+
type: git
25+
outputs:
26+
resources:
27+
- name: source
28+
outputImageDir: ""
29+
targetPath: ""
30+
type: git
31+
steps:
32+
- args:
33+
- --filename
34+
- skaffold.yaml
35+
- --profile
36+
- oncluster
37+
- --file-output
38+
- build.out
39+
command:
40+
- skaffold
41+
- build
42+
env:
43+
- name: GOOGLE_APPLICATION_CREDENTIALS
44+
value: /secret/kaniko-secret
45+
image: gcr.io/k8s-skaffold/skaffold:test-version
46+
name: run-build
47+
resources: {}
48+
volumeMounts:
49+
- mountPath: /secret
50+
name: kaniko-secret
51+
workingDir: /workspace/source
52+
volumes:
53+
- name: kaniko-secret
54+
secret:
55+
secretName: kaniko-secret
56+
---
57+
apiVersion: tekton.dev/v1alpha1
58+
kind: Task
59+
metadata:
60+
creationTimestamp: null
61+
name: skaffold-deploy-0
62+
spec:
63+
inputs:
64+
resources:
65+
- name: source
66+
outputImageDir: ""
67+
targetPath: ""
68+
type: git
69+
steps:
70+
- args:
71+
- --filename
72+
- skaffold.yaml
73+
- --build-artifacts
74+
- build.out
75+
command:
76+
- skaffold
77+
- deploy
78+
image: gcr.io/k8s-skaffold/skaffold:test-version
79+
name: run-deploy
80+
resources: {}
81+
workingDir: /workspace/source
82+
---
83+
apiVersion: tekton.dev/v1alpha1
84+
kind: Pipeline
85+
metadata:
86+
creationTimestamp: null
87+
name: skaffold-pipeline
88+
spec:
89+
resources:
90+
- name: source-repo
91+
type: git
92+
tasks:
93+
- name: skaffold-build-0-task
94+
resources:
95+
inputs:
96+
- name: source
97+
resource: source-repo
98+
outputs:
99+
- name: source
100+
resource: source-repo
101+
taskRef:
102+
name: skaffold-build-0
103+
- name: skaffold-deploy-0-task
104+
resources:
105+
inputs:
106+
- from:
107+
- skaffold-build-0-task
108+
name: source
109+
resource: source-repo
110+
taskRef:
111+
name: skaffold-deploy-0
112+
status: {}
113+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: skaffold/v1beta14
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: gcr.io/k8s-skaffold/pipeline-example
6+
deploy:
7+
kubectl:
8+
manifests:
9+
- k8s-*
10+
profiles:
11+
- name: oncluster
12+
build:
13+
artifacts:
14+
- image: gcr.io/k8s-skaffold/pipeline-example-pipeline
15+
context: .
16+
kaniko:
17+
buildContext:
18+
gcsBucket: skaffold-kaniko
19+
tagPolicy:
20+
gitCommit: {}
21+
cluster:
22+
pullSecretName: kaniko-secret
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: generate-pipeline
5+
spec:
6+
containers:
7+
- name: generate-pipeline
8+
image: gcr.io/k8s-skaffold/pipeline-example
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
for {
10+
fmt.Println("Hello world!")
11+
12+
time.Sleep(time.Second * 1)
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: skaffold/v1beta14
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: gcr.io/k8s-skaffold/pipeline-example
6+
deploy:
7+
kubectl:
8+
manifests:
9+
- k8s-*

integration/generate_pipeline_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestGeneratePipeline(t *testing.T) {
6666
input: []byte{'y', '\n', 'y', '\n'},
6767
configFiles: []string{"sub-app/skaffold.yaml"},
6868
},
69+
{
70+
description: "user example",
71+
dir: "examples/generate-pipeline",
72+
input: []byte("y\n"),
73+
},
6974
}
7075

7176
for _, test := range tests {
@@ -123,11 +128,11 @@ func writeOriginalContents(contents []configContents) {
123128
func checkFileContents(t *testing.T, wantFile, gotFile string) {
124129
wantContents, err := ioutil.ReadFile(wantFile)
125130
if err != nil {
126-
t.Errorf("Error while reading contents of file %s", wantFile)
131+
t.Errorf("Error while reading contents of file %s: %s", wantFile, err)
127132
}
128133
gotContents, err := ioutil.ReadFile(gotFile)
129134
if err != nil {
130-
t.Errorf("Error while reading contents of file %s", gotFile)
135+
t.Errorf("Error while reading contents of file %s: %s", gotFile, err)
131136
}
132137

133138
if !bytes.Equal(wantContents, gotContents) {

0 commit comments

Comments
 (0)