Skip to content

Commit e19d94c

Browse files
committed
Enhance docs with Buildkit
Document usage of BuildKit and update all related docs
1 parent c6eacc6 commit e19d94c

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

docs/tutorials/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ For more information about strategies see the related [docs](/docs/buildstrategi
4646

4747
* [Example with Buildpacks](/docs/tutorials/building_with_buildpacks.md)
4848

49+
* [Example with Buildkit](/docs/tutorials/building_with_buildkit.md)
50+
4951
Depending on your source code you might want to try a specific example. The following table serves as a guide to help you understand which
5052
strategy to choose:
5153

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
# Building with Buildkit
3+
4+
Before starting, make sure you have Tekton and Shipwright Build installed.
5+
6+
See the [Try It!](../../README.md#try-it) section for more information.
7+
8+
## Getting Started
9+
10+
### Registry Authentication
11+
12+
For this tutorial, we will require to create a `tutorial-secret` Kubernetes secret to access a [DockerHub](https://hub.docker.com/) registry, as follows:
13+
14+
```sh
15+
$ REGISTRY_SERVER=https://index.docker.io/v1/ REGISTRY_USER=<your_registry_user> REGISTRY_PASSWORD=<your_registry_password>
16+
$ kubectl create secret docker-registry tutorial-secret --docker-server=$REGISTRY_SERVER --docker-username=$REGISTRY_USER --docker-password=$REGISTRY_PASSWORD [email protected]
17+
```
18+
19+
_Note_: For more information about authentication, please refer to the related [docs](/docs/development/authentication.md).
20+
21+
## Create the strategy
22+
23+
Ensure all strategies are in place, see the [Try It!](../../README.md#try-it) section for more information.
24+
25+
```sh
26+
$ kubectl get cbs
27+
28+
```
29+
30+
_Note_: For more information about strategies, please refer to the related [docs](/docs/buildstrategies.md).
31+
32+
## Creating a Build
33+
34+
For the Build definition, we will require the following:
35+
36+
- A GitHub repository containing a Go [application](https://github.com/shipwright-io/sample-go/tree/main/docker-build) that requires a `Dockerfile`.
37+
- The `tutorial-secret` we just created.
38+
- The `kaniko` ClusterBuildStrategy.
39+
40+
Let's apply our Build and wait for it to be ready:
41+
42+
```bash
43+
$ export REGISTRY_ORG=<your_registry_org>
44+
$ cat <<EOF | kubectl apply -f -
45+
apiVersion: shipwright.io/v1alpha1
46+
kind: Build
47+
metadata:
48+
name: go-tutorial-using-buildkit
49+
spec:
50+
source:
51+
url: https://github.com/shipwright-io/sample-go
52+
contextDir: docker-build/
53+
dockerfile: docker-build/
54+
strategy:
55+
name: buildkit
56+
kind: ClusterBuildStrategy
57+
output:
58+
image: docker.io/${REGISTRY_ORG}/go-tutorial:latest
59+
credentials:
60+
name: tutorial-secret
61+
EOF
62+
```
63+
64+
Verify that the `go-tutorial` Build was created successfully:
65+
66+
```sh
67+
68+
```
69+
70+
_Note_: For more information about Build resources, please refer to the related [docs](/docs/build.md).
71+
72+
## Creating a BuildRun
73+
74+
Second, we will create a `BuildRun` resource that references our previous `go-tutorial` Build:
75+
76+
```sh
77+
$ cat <<EOF | kubectl create -f -
78+
apiVersion: shipwright.io/v1alpha1
79+
kind: BuildRun
80+
metadata:
81+
name: go-tutorial-using-buildkit-buildrun
82+
spec:
83+
buildRef:
84+
name: go-tutorial-using-buildkit
85+
EOF
86+
```
87+
88+
Wait until your `go-tutorial-buildrun` buildrun is completed:
89+
90+
```sh
91+
92+
```
93+
94+
To know more about the state of the BuildRun, the `.Status.Conditions` fields provide more data:
95+
96+
```sh
97+
98+
```
99+
100+
_Note_: A BuildRun is a resource that runs to completion. The `REASON` column reflects the state of the resource. If the BuildRun ran to completion successfully,
101+
a `Succeeded` `REASON` is expected.
102+
103+
_Note_: For more information about BuildRun resources, please refer to the related [docs](/docs/buildrun.md).
104+
105+
## Closing
106+
107+
Congratulations! You just created a container image from https://github.com/shipwright-io/sample-go using [Buildkit](https://github.com/moby/buildkit).
108+
109+
The new container image should now be available in your container registry.

0 commit comments

Comments
 (0)