├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── docker-build
├── README.md
├── build-hello.yaml
├── build.yaml
├── service-account.yaml
└── template.yaml
├── getting-started
├── README.md
└── build.yaml
└── spring-boot
├── README.md
├── build-cache.yaml
└── build.yaml
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2018 Google LLC
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Knative Build Tutorials
2 |
3 | [Knative Build](https://github.com/knative/build) is an open-source project
4 | that provides an implementation of the Build [CRD](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) that runs Builds on-cluster.
5 |
6 | It's not a complete standalone product that could be used for CI/CD.
7 | Think of it as a building block to facilitate the expression of Builds as part of larger systems.
8 |
9 | **This repository contains a list of tutorials to get started with Knative Build.**
10 |
11 | ## Hello, World
12 |
13 | Learn how to install Knative Build, run a simple Build and inspect its result.
14 |
15 | [](https://console.cloud.google.com/cloudshell/open?git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fknative-build-tutorials&page=editor&tutorial=getting-started/README.md&open_in_editor=.)
16 |
17 | ## Docker Build with Kaniko
18 |
19 | Learn how to build a Docker image from a Dockerfile, using [Kaniko](https://github.com/GoogleContainerTools/kaniko).
20 |
21 | [](https://console.cloud.google.com/cloudshell/open?git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fknative-build-tutorials&page=editor&tutorial=docker-build/README.md&open_in_editor=.)
22 |
23 | ## Spring Boot Java application with Jib
24 |
25 | Learn how to build a Spring Boot application without Docker, using [Jib](https://github.com/GoogleContainerTools/jib).
26 |
27 | [](https://console.cloud.google.com/cloudshell/open?git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fknative-build-tutorials&page=editor&tutorial=spring-boot/README.md&open_in_editor=.)
28 |
--------------------------------------------------------------------------------
/docker-build/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Knative Build - Docker build
4 |
5 | The previous tutorial taught you how to setup Knative Build on a Kubernetes cluster. You ran a simple Build
6 | that prints "Hello, World!".
7 |
8 | Let's try a more concrete build: **building a Docker image**.
9 |
10 | ## What am I going to learn?
11 |
12 | 1. This new tutorial, will show you how to build a Docker image described by a **Dockerfile**.
13 | 2. You'll setup credentials to push that image to a registry.
14 | 2. It'll show you how to extract common build configuration into a Build Template.
15 |
16 | **Time to complete:**
17 |
18 | **Are you ready?** Then click the `Continue` button to get started...
19 |
20 | ## Build a Docker image
21 |
22 | We are going to build a very simple website with [nginx](https://www.nginx.com/).
23 | The sources are on [GitHub](https://github.com/dgageot/hello).
24 | A [Dockerfile](https://github.com/dgageot/hello/blob/master/Dockerfile)
25 | describes the image to be built.
26 |
27 | Open the file editor.
28 | Here's the Kubernetes yaml manifest to express such a build:
29 |
30 | ```yaml
31 | apiVersion: build.knative.dev/v1alpha1
32 | kind: Build
33 | metadata:
34 | name: docker-build
35 | spec:
36 | serviceAccountName: knative-build
37 | source:
38 | git:
39 | url: https://github.com/dgageot/hello.git
40 | revision: master
41 | steps:
42 | - name: build-and-push
43 | image: gcr.io/kaniko-project/executor:v0.1.0
44 | args:
45 | - --dockerfile=/workspace/Dockerfile
46 | - --destination=gcr.io/[PROJECT-NAME]/hello-nginx
47 | ```
48 |
49 | A few things look different than the simpler "Hello, World!" build, right?
50 |
51 | **Click the `Continue` button to understand those differences...**
52 |
53 | ## Git source
54 |
55 | This time, the build will need sources to build an artifact. So we define
56 | a source where to get those sources from:
57 |
58 | ```yaml
59 | source:
60 | git:
61 | url: https://github.com/dgageot/hello.git
62 | revision: master
63 | ```
64 |
65 | **Kaniko**
66 |
67 | [Kaniko](https://github.com/GoogleContainerTools/kaniko) will be used
68 | to build a Docker image. Just running `docker build` [would be unsafe on a
69 | shared cluster](https://github.com/kubernetes/kubernetes/issues/1806).
70 |
71 | ```yaml
72 | - name: build-and-push
73 | image: gcr.io/kaniko-project/executor:v0.1.0
74 | ```
75 |
76 | **Service Account**
77 |
78 | Once the image is built, it'll be pushed to [Google Container Registry](https://cloud.google.com/container-registry/).
79 | Or any registry in fact, but we'll demonstrate with GCR.
80 | The build requires a service account to be granted the right to push.
81 |
82 | ```yaml
83 | serviceAccountName: knative-build
84 | ```
85 |
86 | This will be done by creating a Kubernetes [Service Account](https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/)
87 | that has access to a Google Cloud [Service Account](https://cloud.google.com/iam/docs/understanding-service-accounts).
88 |
89 | **That's a lot of Service Accounts! Click the `Continue` button to do this step by step...**
90 |
91 | ## Configure access to Google Container Registry
92 |
93 | Giving a Build the permisison to push to [Google Container Registry](https://cloud.google.com/container-registry/)
94 | requires 4 steps:
95 |
96 | + Create a [Service Account](https://cloud.google.com/iam/docs/understanding-service-accounts) in your Google Cloud project. It needs to be be granted push access to GCR.
97 | + Create a [JSON key](https://cloud.google.com/container-registry/docs/advanced-authentication#json_key_file) for that Service Account.
98 | + Store this key in a [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/).
99 | + Create a Kubernetes [Service Account](https://cloud.google.com/iam/docs/understanding-service-accounts) that has access to this secret.
100 |
101 | Once those steps are done, we can create as many builds as we want that share those permissions.
102 |
103 | **Click the `Continue` button to follow those steps...**
104 |
105 | ## Create a Google Cloud Service Account
106 |
107 | The first part of the configuration is on the Google Cloud side.
108 |
109 | ### Make sure gcloud CLI talks to the right project
110 |
111 | ```bash
112 | gcloud config set project [YOUR_PROJECTID]
113 | ```
114 |
115 | ```bash
116 | PROJECTID=$(gcloud config get-value project)
117 | ```
118 |
119 | ### Create a Service Account
120 |
121 | ```bash
122 | gcloud iam service-accounts create knative-build --display-name "Knative Build"
123 | ```
124 |
125 | ### Allow it to push to GCR
126 |
127 | ```bash
128 | gcloud projects add-iam-policy-binding $PROJECTID --member serviceAccount:knative-build@$PROJECTID.iam.gserviceaccount.com --role roles/storage.admin
129 | ```
130 |
131 | ### Create a JSON key
132 |
133 | ```bash
134 | gcloud iam service-accounts keys create knative-key.json --iam-account knative-build@$PROJECTID.iam.gserviceaccount.com
135 | ```
136 |
137 | This creates a knative-key.json file on your drive.
138 |
139 | **You are almost there!** You completed the Google Cloud part.
140 |
141 | **Click the `Continue` button to complete the Kubernetes part...**
142 |
143 | ## Create a Kubernetes Service Account
144 |
145 | ### Create a secret for the JSON Key
146 |
147 | First, create a Kubernetes secret from the JSON key:
148 |
149 | ```bash
150 | kubectl create secret generic knative-build-auth --type="kubernetes.io/basic-auth" --from-literal=username="_json_key" --from-file=password=knative-key.json
151 | ```
152 |
153 | To tell the Build to use those parameters when pushing to `gcr.io`, we
154 | need to add an annotation to the secret. That's called [Guided credential selection](https://github.com/knative/docs/blob/master/build/auth.md#guiding-credential-selection).
155 |
156 | ```bash
157 | kubectl annotate secret knative-build-auth build.knative.dev/docker-0=https://gcr.io
158 | ```
159 |
160 | ### Create a Service Account
161 |
162 | We can eventually create a Service Account in Kubernetes:
163 |
164 | ```bash
165 | kubectl apply -f docker-build/service-account.yaml
166 | ```
167 |
168 | **You are done! Continue to next step to run the build...**
169 |
170 | ## Run the Build
171 |
172 | OK, we've got everything configured to let the Build push images to a registry.
173 |
174 | One last step is to edit docker-build/build.yaml
175 | and replace `[PROJECT-NAME]` with your project id.
176 | This way, the build will push the image to the Google Container Registry linked to your project.
177 |
178 | Run the build:
179 |
180 | ```bash
181 | kubectl apply -f docker-build/build.yaml
182 | ```
183 |
184 | The build is running:
185 |
186 | ```bash
187 | kubectl get builds
188 | ```
189 |
190 | Tail the logs with:
191 |
192 | ```bash
193 | logs docker-build
194 | ```
195 |
196 | **Congratulations! You have built and pushed a Docker image with Knative Build.**
197 |
198 |
199 |
200 | **Continue to next step, to improve the build file...**
201 |
202 | ## Build Templates
203 |
204 | Now that you became familiar with expressing Docker builds, you will
205 | want to avoid copy/pasting the same boilerplate yaml each time a new
206 | image needs to be built.
207 |
208 | [Build Templates](https://github.com/knative/docs/blob/master/build/build-templates.md)
209 | solve that problem by extracting the common yaml to a shared parameterized template.
210 |
211 | ### Create a Template
212 |
213 | A Build Template
214 | for a Docker build looks like that:
215 |
216 | ```yaml
217 | apiVersion: build.knative.dev/v1alpha1
218 | kind: BuildTemplate
219 | metadata:
220 | name: docker-build
221 | spec:
222 | parameters:
223 | - name: IMAGE
224 | description: Where to publish the resulting image.
225 | - name: DIRECTORY
226 | description: The directory containing the build context.
227 | default: "/workspace"
228 | - name: DOCKERFILE_NAME
229 | description: The name of the Dockerfile
230 | default: Dockerfile
231 | steps:
232 | - name: build-and-push
233 | image: gcr.io/kaniko-project/executor:v0.1.0
234 | args:
235 | - --dockerfile=/${DIRECTORY}/{DOCKERFILE_NAME}
236 | - --destination=${IMAGE}
237 | ```
238 |
239 | It's a list of steps and a list of parameters, some of which have default
240 | values that can be overriden by a build.
241 |
242 | Let's register this template into Kubernetes.
243 |
244 | ```bash
245 | kubectl apply -f docker-build/template.yaml
246 | ```
247 |
248 | ### Use the Template
249 |
250 | Now, the Build can be simplified by referencing the template and by
251 | providing the right values for each parameter.
252 |
253 | ```yaml
254 | apiVersion: build.knative.dev/v1alpha1
255 | kind: Build
256 | metadata:
257 | name: docker-build-hello
258 | spec:
259 | serviceAccountName: knative-build
260 | source:
261 | git:
262 | url: https://github.com/dgageot/hello.git
263 | revision: master
264 | template:
265 | name: docker-build
266 | arguments:
267 | - name: IMAGE
268 | value: gcr.io/[PROJECT-NAME]/hello-nginx
269 | ```
270 |
271 | **Click the `Continue` button to run the templated build...**
272 |
273 | ## Run the Templated Build
274 |
275 | *Warning*: don't forget to replace `[PROJECT-NAME]` with you actual
276 | project name in
277 | docker-build/build-hello.yaml
278 |
279 | Run the build:
280 |
281 | ```bash
282 | kubectl apply -f docker-build/build-hello.yaml
283 | ```
284 |
285 | The build is running:
286 |
287 | ```bash
288 | kubectl get builds
289 | ```
290 |
291 | Tail the logs with:
292 |
293 | ```bash
294 | logs docker-build-hello
295 | ```
296 |
297 | ## Congratulations!
298 |
299 |
300 |
301 | Woot! You've used a Build Template for the first time. You are an advanced
302 | user now!
303 |
304 | **Why not build a more complicated Java application?**
305 |
306 | [](https://console.cloud.google.com/cloudshell/open?git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fknative-build-tutorials&page=editor&tutorial=spring-boot/README.md&open_in_editor=.)
307 |
308 |
309 | Copyright 2018 Google LLC All Rights Reserved. Licensed under the Apache
310 | License, Version 2.0 (the "License"); you may not use this file except in
311 | compliance with the License. You may obtain a copy of the License at
312 | http://www.apache.org/licenses/LICENSE-2.0.
313 | Unless required by applicable law or agreed to in writing, software
314 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
315 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
316 | License for the specific language governing permissions and limitations under
317 | the License.
318 |
--------------------------------------------------------------------------------
/docker-build/build-hello.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: Build
16 | metadata:
17 | name: docker-build-hello
18 | spec:
19 | serviceAccountName: knative-build
20 | source:
21 | git:
22 | url: https://github.com/dgageot/hello.git
23 | revision: master
24 | template:
25 | name: docker-build
26 | arguments:
27 | - name: IMAGE
28 | value: gcr.io/[PROJECT-NAME]/hello-nginx
29 |
--------------------------------------------------------------------------------
/docker-build/build.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: Build
16 | metadata:
17 | name: docker-build
18 | spec:
19 | serviceAccountName: knative-build
20 | source:
21 | git:
22 | url: https://github.com/dgageot/hello.git
23 | revision: master
24 | steps:
25 | - name: build-and-push
26 | image: gcr.io/kaniko-project/executor:v0.1.0
27 | args:
28 | - --dockerfile=/workspace/Dockerfile
29 | - --destination=gcr.io/[PROJECT-NAME]/hello-nginx
30 |
--------------------------------------------------------------------------------
/docker-build/service-account.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: v1
15 | kind: ServiceAccount
16 | metadata:
17 | name: knative-build
18 | secrets:
19 | - name: knative-build-auth
--------------------------------------------------------------------------------
/docker-build/template.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: BuildTemplate
16 | metadata:
17 | name: docker-build
18 | spec:
19 | parameters:
20 | - name: IMAGE
21 | description: Where to publish the resulting image.
22 | - name: DIRECTORY
23 | description: The directory containing the build context.
24 | default: /workspace
25 | - name: DOCKERFILE_NAME
26 | description: The name of the Dockerfile
27 | default: Dockerfile
28 | steps:
29 | - name: build-and-push
30 | image: gcr.io/kaniko-project/executor:v0.1.0
31 | args:
32 | - --dockerfile=/${DIRECTORY}/{DOCKERFILE_NAME}
33 | - --destination=${IMAGE}
34 |
--------------------------------------------------------------------------------
/getting-started/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Knative Build - Getting started
4 |
5 | Welcome! This tutorial will help you get started with [Knative Build](https://github.com/knative/build) extension to Kubernetes.
6 |
7 | ## What is Knative Build?
8 |
9 | It's an [open-source project](https://github.com/knative/build) that provides an implementation
10 | of the Build [CRD](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
11 | that runs Builds on-cluster.
12 |
13 | **What is it NOT?**
14 |
15 | It's not a complete standalone product that could be used for CI/CD.
16 | Think of it as a building block to facilitate the expression of Builds as part of larger systems.
17 |
18 | **What am I going to learn?**
19 |
20 | 1. You'll learn how to install Knative Build.
21 | 2. You'll run a simple build.
22 | 3. You'll also learn a bit how it works underneath.
23 |
24 | **Time to complete:**
25 |
26 | **Are you ready?** Click the `Continue` button to get started...
27 |
28 | ## Setup Kubernetes
29 |
30 | *Warning: Those instructions assume you have a Kubernetes cluster and `kubectl` pointing at it,
31 | as well as a basic knowledge of Kubernetes and its CLI, `kubectl`.*
32 |
33 | One way to check if `kubectl` is configured properly is to run:
34 |
35 | ```bash
36 | kubectl get nodes
37 | ```
38 |
39 | It should show a list of nodes.
40 |
41 | If you don't have a Kubernetes cluster, follow the instructions below:
42 |
43 |
47 | **Creating a Cluster**
48 | This page explains how to create a cluster on Kubernetes Engine.
49 |
50 |
51 | **Click the `Continue` button to prepare the cluster...**
52 |
53 | ## Configure permissions
54 |
55 | Before Knative Build is installed, we need to grant `cluster-admin` permissions to the current user:
56 |
57 | ```bash
58 | kubectl create clusterrolebinding cluster-admin-binding \
59 | --clusterrole=cluster-admin \
60 | --user=$(gcloud config get-value core/account)
61 | ```
62 |
63 | **Install Knative Build**
64 |
65 | Next, we install the latest version of [Knative Build](https://github.com/knative/build):
66 |
67 | ```bash
68 | kubectl apply -f https://storage.googleapis.com/build-crd/latest/release.yaml
69 | ```
70 |
71 | From now one, you should be good to go!
72 |
73 | But let's check that everything was installed correctly. That'll also help you understand which
74 | new components have been installed on the cluster.
75 |
76 | **Click the `Continue` button to run those checks...**
77 |
78 | ## Verify the installation
79 |
80 | The installation process created a [Kubernetes namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)
81 | in which the Knative components run.
82 |
83 | ```bash
84 | kubectl get namespace knative-build
85 | ```
86 |
87 | Let's list the components that are running in that namespace and
88 | wait until each component is running:
89 |
90 | ```bash
91 | kubectl -n knative-build get pods -w
92 | ```
93 |
94 | CTRL+C when `STATUS` column shows `Running` for both pods.
95 |
96 | You can see that the Build [CRDs](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) are installed:
97 |
98 | ```bash
99 | kubectl get crd
100 | ```
101 |
102 | Thanks to those CRDs, now Kubernetes recognizes a new type of resource, the `Build` type:
103 |
104 | ```bash
105 | kubectl get build
106 | ```
107 |
108 | It should display `No resources found.` for now.
109 |
110 | **You are ready to run your first Build!**
111 |
112 | **Click the `Continue` button to run a simple build...**
113 |
114 | ## Hello, World!
115 |
116 | Let's start simple with a Build that has no input and produces no artifact.
117 | All it does is print "`Hello, World!`". It's enough to learn the basics!
118 |
119 | Open the file editor
120 | and take a look at the Kubernetes yaml manifest
121 | to express such a build:
122 |
123 | ```yaml
124 | apiVersion: build.knative.dev/v1alpha1
125 | kind: Build
126 | metadata:
127 | name: hello
128 | spec:
129 | steps:
130 | - image: busybox
131 | args: ['echo', 'Hello, World!']
132 | ```
133 |
134 | See, that's easy!
135 |
136 | **The `Build` kind**
137 |
138 | You can see that Kubernetes was extended with a new kind of resource: the `Build`.
139 | A Build is made of steps that run in sequence and share a common directory called the `workspace`.
140 |
141 | Each step is a Docker image that runs with the given arguments.
142 |
143 | Our sample has only one step which uses the `busybox` image to run `echo Hello, World!`.
144 |
145 | **Click the `Continue` button to start the build...**
146 |
147 | ## Let's start the build
148 |
149 | ```bash
150 | kubectl apply -f getting-started/build.yaml
151 | ```
152 |
153 | The build is running:
154 |
155 | ```bash
156 | kubectl get builds
157 | ```
158 |
159 | **Congratulations, you've started your first build with Knative Build!**
160 |
161 |
162 |
163 | Running `kubectl apply` triggered quite a few actions on the cluster side.
164 |
165 | **Continue to next steps, to understand what happened underneath...**
166 |
167 | ## Inspect the Build
168 |
169 | We can start by inspecting the Build object that was created:
170 |
171 | ```bash
172 | kubectl get build hello -o yaml
173 | ```
174 |
175 | It'll give this kind of result:
176 |
177 | ```yaml
178 | apiVersion: build.knative.dev/v1alpha1
179 | kind: Build
180 | metadata:
181 | creationTimestamp: 2018-07-06T13:12:43Z
182 | name: hello
183 | namespace: default
184 | spec:
185 | steps:
186 | - args:
187 | - echo
188 | - Hello, World!
189 | image: busybox
190 | status:
191 | builder: Cluster
192 | cluster:
193 | namespace: default
194 | podName: hello-klsqq
195 | conditions:
196 | - reason: Building
197 | state: Succeeded
198 | startTime: 2018-07-06T13:12:43Z
199 | ```
200 |
201 | **The interesting information are:**
202 |
203 | + The state of the build: **`Succeeded`**
204 | + The name of the pod that ran the job: **`hello-klsqq`**
205 |
206 | The build is described in a `Build` object but its steps actually ran in a standard
207 | [Kubernetes pod](https://kubernetes.io/docs/concepts/workloads/pods/pod/).
208 |
209 | **Continue to next step to inspect the pod...**
210 |
211 | ## Let's inspect the pod to learn more about the build
212 |
213 | ```bash
214 | kubectl get pod $(kubectl get build hello -ojsonpath={.status.cluster.podName}) -oyaml
215 | ```
216 |
217 | It'll give you the full description of the pod.
218 |
219 | **That's a lot of information!**
220 |
221 | The main information is the list of containers (think steps) that are run:
222 |
223 | ```yaml
224 | initContainers:
225 | - env:
226 | - name: HOME
227 | value: /builder/home
228 | image: gcr.io/build-crd/github.com/knative/build/cmd/creds-init@sha256:a40420845b318318f6649674fc8cc1b23c7528b8be7d1a92a97508c69dac133c
229 | name: build-step-credential-initializer
230 | volumeMounts:
231 | - mountPath: /workspace
232 | name: workspace
233 | - mountPath: /builder/home
234 | name: home
235 | workingDir: /workspace
236 | - args:
237 | - echo
238 | - Hello, World!
239 | env:
240 | - name: HOME
241 | value: /builder/home
242 | image: busybox
243 | name: build-step-unnamed-1
244 | volumeMounts:
245 | - mountPath: /workspace
246 | name: workspace
247 | - mountPath: /builder/home
248 | name: home
249 | workingDir: /workspace
250 | ```
251 |
252 | *Pro Tip: look for the **image** keyword to find the containers.*
253 |
254 | **Build steps run in containers:**
255 |
256 | We can see that the pod ran two [Init Containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) in sequential order:
257 |
258 | + One to initialize the credentials. More on that later.
259 | + One to actually run the only step of our build.
260 |
261 | **Build steps share a common workspace:**
262 |
263 | Containers all share the same two volumes:
264 |
265 | + `/builder/home` - the home folder for all containers where shared configuration is typically installed.
266 | + `/workspace` - a shared folder where to read inputs from and where to write outputs of each step.
267 |
268 | **Continue to next step to get the Build's status...**
269 |
270 | ## The pod also holds the statuses for each build step:
271 |
272 | ```yaml
273 | initContainerStatuses:
274 | - containerID: docker://94a639a6b16c69648989ff5c0d8eb94a54b0f6ac50f8484eed803d1f91b1123a
275 | image: gcr.io/build-crd/github.com/knative/build/cmd/creds-init@sha256:a40420845b318318f6649674fc8cc1b23c7528b8be7d1a92a97508c69dac133c
276 | name: build-step-credential-initializer
277 | ready: true
278 | state:
279 | terminated:
280 | containerID: docker://94a639a6b16c69648989ff5c0d8eb94a54b0f6ac50f8484eed803d1f91b1123a
281 | exitCode: 0
282 | finishedAt: 2018-07-06T11:51:07Z
283 | reason: Completed
284 | startedAt: 2018-07-06T11:51:07Z
285 | - containerID: docker://db1de3e7032da065c7e1a9dcedf6e10372389130d0fcfb1546b1cd44749bed48
286 | image: busybox:latest
287 | imageID: docker-pullable://busybox@sha256:74f634b1bc1bd74535d5209589734efbd44a25f4e2dc96d78784576a3eb5b335
288 | name: build-step-unnamed-1
289 | ready: true
290 | state:
291 | terminated:
292 | containerID: docker://db1de3e7032da065c7e1a9dcedf6e10372389130d0fcfb1546b1cd44749bed48
293 | exitCode: 0
294 | finishedAt: 2018-07-06T11:51:09Z
295 | reason: Completed
296 | startedAt: 2018-07-06T11:51:09Z
297 | phase: Succeeded
298 | ```
299 |
300 | That's useful to understand if the build went well or not.
301 |
302 | **Let's see the logs**
303 |
304 | More than the status of each step, what you want, as a user, is the logs output.
305 | It's possible to read the logs for each step with the usual `kubectl logs` command.
306 |
307 | For example:
308 |
309 | ```bash
310 | kubectl logs -f $(kubectl get build hello -ojsonpath={.status.cluster.podName}) -c build-step-unnamed-1
311 | ```
312 |
313 | It should show `Hello, World!`.
314 |
315 | **It takes a lot of time!**
316 |
317 | *Only the first build will be long to start because Knative needs to pull some Docker images that
318 | are used by each build. Once those images are pulled, the builds will be much faster.*
319 |
320 | **I see no logs!**
321 |
322 | *Sometimes, Kubernetes deletes the logs for a Build that's terminated. It makes sense in the Kubernetes world.
323 | Not so much in the user world!. Remember that Knative Build is a building block meant to be used in larger systems.
324 | In this kind of system, logs would typically be aggregated and published somewhere else.*
325 |
326 | **Continue to next step to improve the logs...**
327 |
328 | ## Let's improve the Hello, World!
329 |
330 | First, we are going to install a CLI utility to read a build's logs. This will be much easier than running
331 | lots of `kubectl` commands!
332 |
333 | ```bash
334 | go get -u github.com/knative/build/cmd/logs
335 | ```
336 |
337 | ```bash
338 | logs hello
339 | ```
340 |
341 | That's so much easier!
342 |
343 | **Continue to next step to improve the build description...**
344 |
345 | ## Build steps can have names
346 |
347 | When build steps are not given names, they get an auto-generated name such as `build-step-X`.
348 | Naming build steps will give us a more meaningful output in logs.
349 |
350 | Let's give a name to the build's unique step. Why not name it `hello-world`?
351 |
352 | Open the yaml manifest and use this content:
353 | ```yaml
354 | apiVersion: build.knative.dev/v1alpha1
355 | kind: Build
356 | metadata:
357 | name: hello
358 | spec:
359 | steps:
360 | - name: hello-world
361 | image: busybox
362 | args: ['echo', 'Hello, World!']
363 | ```
364 |
365 | We have to delete the previous build...
366 |
367 | ```bash
368 | kubectl delete build hello
369 | ```
370 |
371 | ...and start a fresh one.
372 |
373 | ```bash
374 | kubectl apply -f getting-started/build.yaml
375 | ```
376 |
377 | The logs are easy to tail:
378 |
379 | ```bash
380 | logs hello
381 | ```
382 |
383 | ## Congratulations! You know everything about simple builds.
384 |
385 |
386 |
387 | **Why not build a Docker image from a Dockerfile now?**
388 |
389 | [](https://console.cloud.google.com/cloudshell/open?git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fknative-build-tutorials&page=editor&tutorial=docker-build/README.md&open_in_editor=.)
390 |
391 |
392 | Copyright 2018 Google LLC All Rights Reserved. Licensed under the Apache
393 | License, Version 2.0 (the "License"); you may not use this file except in
394 | compliance with the License. You may obtain a copy of the License at
395 | http://www.apache.org/licenses/LICENSE-2.0.
396 | Unless required by applicable law or agreed to in writing, software
397 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
398 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
399 | License for the specific language governing permissions and limitations under
400 | the License.
401 |
--------------------------------------------------------------------------------
/getting-started/build.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: Build
16 | metadata:
17 | name: hello
18 | spec:
19 | steps:
20 | - image: busybox
21 | args: ['echo', 'Hello, World!']
--------------------------------------------------------------------------------
/spring-boot/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Knative Build - Java application
4 |
5 | The previous tutorial taught you how to build and push a Docker image from a Dockerfile,
6 | using Knative Build and Kaniko.
7 |
8 | Let's try something different and build a [Java Spring Boot web application](https://github.com/dgageot/hello-jib),
9 | without Docker. It will still produce a Docker image at the end, though.
10 |
11 | ## What am I going to learn?
12 |
13 | 1. You are going to use Knative Build with [Jib](https://github.com/GoogleContainerTools/jib),
14 | another open-source project from Google. Jib is a maven and gradle plugin that knows how to produce a Docker image
15 | from Java sources. It's easy to use as a Knative Build step.
16 |
17 | 2. You will learn how to decrease the build duration by configuring a build cache.
18 |
19 | **Time to complete:**
20 |
21 | **Are you ready?** Then click the `Continue` button to get started....
22 |
23 | ## Jib and Knative Build
24 |
25 | Open the file editor.
26 | Here's the Kubernetes yaml manifest
27 | to express such a build:
28 |
29 | ```yaml
30 | apiVersion: build.knative.dev/v1alpha1
31 | kind: Build
32 | metadata:
33 | name: jib
34 | spec:
35 | serviceAccountName: knative-build
36 | source:
37 | git:
38 | url: https://github.com/dgageot/hello-jib.git
39 | revision: master
40 | steps:
41 | - name: build-and-push
42 | image: gcr.io/cloud-builders/mvn
43 | args: ["compile", "jib:build", "-Dimage=gcr.io/[PROJECT-NAME]/hello-jib"]
44 | ```
45 |
46 | **Git source**
47 |
48 | Like for the previous tutorial, the build reads the sources from a [git repository](https://github.com/dgageot/hello-jib).
49 |
50 | **Maven**
51 |
52 | This time, we are using [Maven](https://maven.apache.org/) to do the actual build.
53 | We use the `gcr.io/cloud-builders/mvn` image that is one of the Google
54 | [curated images](https://github.com/GoogleCloudPlatform/cloud-builders).
55 |
56 | From the arguments, Maven knows it has to compile the Java sources and then call Jib
57 | to produce a Docker image.
58 |
59 | ```yaml
60 | - name: build-and-push
61 | image: gcr.io/cloud-builders/mvn
62 | args: ["compile", "jib:build", "-Dimage=gcr.io/[PROJECT-NAME]/hello-jib"]
63 | ```
64 |
65 | **Service Account**
66 |
67 | Once the image is built, it'll be pushed to [Google Container Registry](https://cloud.google.com/container-registry/),
68 | so, we are going to reuse the `knative-build` service account we've setup
69 | for previous tutorial.
70 |
71 | **Click the `Continue` button to run the build...**
72 |
73 | ## Run the Build
74 |
75 | Before we run the build, you need to edit spring-boot/build.yaml and replace `[PROJECT-NAME]`
76 | with your project name.
77 |
78 | Let's run the build:
79 |
80 | ```bash
81 | kubectl apply -f spring-boot/build.yaml
82 | ```
83 |
84 | The build is running:
85 |
86 | ```bash
87 | kubectl get builds
88 | ```
89 |
90 | Tail the logs with:
91 |
92 | ```bash
93 | logs jib
94 | ```
95 |
96 | **Congratulations! You built your first Java Application with Knative Build.**
97 |
98 |
99 |
100 | **Continue to next step, to improve the build file...**
101 |
102 | ## Clean builds are slow
103 |
104 | If you run the build a second time, you'll see that it downloads lots of files
105 | that were already downloaded the first time. It's because Maven is starting
106 | the build from the sources and nothing else.
107 |
108 | That makes the build more reproducible but also slower.
109 |
110 | Most of the time, it's safe to share the artifacts that Maven downloads across builds.
111 | And it usually makes a build much faster.
112 |
113 | **We need a cache**
114 |
115 | Because Knative Build is native to Kubernetes, it can leverage [Persistent Volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
116 | to share a cache across builds. All we have to do is make some changes to the `build.yaml`.
117 |
118 | **Click the `Continue` button to configure this cache...**
119 |
120 | ## Update the Build manifest
121 |
122 | We are going to use a more elaborate version of the Build manifest that looks like that:
123 |
124 | ```yaml
125 | apiVersion: build.knative.dev/v1alpha1
126 | kind: Build
127 | metadata:
128 | name: jib-cache
129 | spec:
130 | serviceAccountName: knative-build
131 | source:
132 | git:
133 | url: https://github.com/dgageot/hello-jib.git
134 | revision: master
135 |
136 | steps:
137 | - name: build-and-push
138 | image: gcr.io/cloud-builders/mvn
139 | args: ["compile", "jib:build", "-Dimage=gcr.io/[PROJECT-NAME]/hello-jib"]
140 | volumeMounts:
141 | - name: mvn-cache
142 | mountPath: /root/.m2
143 |
144 | volumes:
145 | - name: mvn-cache
146 | persistentVolumeClaim:
147 | claimName: cache
148 | ---
149 | kind: PersistentVolumeClaim
150 | apiVersion: v1
151 | metadata:
152 | name: cache
153 | spec:
154 | accessModes:
155 | - ReadWriteOnce
156 | volumeMode: Filesystem
157 | resources:
158 | requests:
159 | storage: 8Gi
160 | ```
161 |
162 | This configuration does two things:
163 |
164 | + It creates a Persistent Volume to be shared by builds
165 | + It mounts this volume in `/root/.m2` during a build so that files written there will be available to next build.
166 |
167 | **Continue to next step, to give it a try...**
168 |
169 | ## Run with a cache
170 |
171 | *Warning*: don't forget to replace `[PROJECT-NAME]` with you actual
172 | project name in
173 | spring-boot/build-cache.yaml
174 |
175 | Let's run the build:
176 |
177 | ```bash
178 | kubectl apply -f spring-boot/build-cache.yaml
179 | ```
180 |
181 | The build is running:
182 |
183 | ```bash
184 | kubectl get builds
185 | ```
186 |
187 | Tail the logs with:
188 |
189 | ```bash
190 | logs jib-cache
191 | ```
192 |
193 | You should still see the files being downloaded but let's
194 | run the same build a second time.
195 |
196 | ```bash
197 | kubectl delete build jib-cache
198 | ```
199 |
200 | ```bash
201 | kubectl apply -f spring-boot/build-cache.yaml
202 | ```
203 |
204 | ```bash
205 | logs jib-cache
206 | ```
207 |
208 | Now, the build should be a bit faster and you see in the logs that no file
209 | was downloaded from Maven Central!
210 |
211 | **The more dependencies your application has, the bigger the gain.**
212 |
213 | ## Congratulations!
214 |
215 |
216 |
217 | Amazing! You've used a cache to make your builds much faster.
218 | You are an expert user now!
219 |
220 | If you'd like to learn more about Knative Build, go check out the documentation
221 | [here](https://github.com/knative/docs/tree/master/build).
222 |
223 | **Have fun!**
224 |
225 |
226 | Copyright 2018 Google LLC All Rights Reserved. Licensed under the Apache
227 | License, Version 2.0 (the "License"); you may not use this file except in
228 | compliance with the License. You may obtain a copy of the License at
229 | http://www.apache.org/licenses/LICENSE-2.0.
230 | Unless required by applicable law or agreed to in writing, software
231 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
232 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
233 | License for the specific language governing permissions and limitations under
234 | the License.
235 |
--------------------------------------------------------------------------------
/spring-boot/build-cache.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: Build
16 | metadata:
17 | name: jib-cache
18 | spec:
19 | serviceAccountName: knative-build
20 | source:
21 | git:
22 | url: https://github.com/dgageot/hello-jib.git
23 | revision: master
24 |
25 | steps:
26 | - name: build-and-push
27 | image: gcr.io/cloud-builders/mvn
28 | args: ["compile", "jib:build", "-Dimage=gcr.io/[PROJECT-NAME]/hello-jib"]
29 | volumeMounts:
30 | - name: mvn-cache
31 | mountPath: /root/.m2
32 |
33 | volumes:
34 | - name: mvn-cache
35 | persistentVolumeClaim:
36 | claimName: cache
37 | ---
38 | kind: PersistentVolumeClaim
39 | apiVersion: v1
40 | metadata:
41 | name: cache
42 | spec:
43 | accessModes:
44 | - ReadWriteOnce
45 | volumeMode: Filesystem
46 | resources:
47 | requests:
48 | storage: 8Gi
--------------------------------------------------------------------------------
/spring-boot/build.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | apiVersion: build.knative.dev/v1alpha1
15 | kind: Build
16 | metadata:
17 | name: jib
18 | spec:
19 | serviceAccountName: knative-build
20 | source:
21 | git:
22 | url: https://github.com/dgageot/hello-jib.git
23 | revision: master
24 |
25 | steps:
26 | - name: build-and-push
27 | image: gcr.io/cloud-builders/mvn
28 | args: ["compile", "jib:build", "-Dimage=gcr.io/[PROJECT-NAME]/hello-jib"]
29 |
--------------------------------------------------------------------------------