Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flyer103/buildkit-demo
Explore buildkitd.
https://github.com/flyer103/buildkit-demo
Last synced: 8 days ago
JSON representation
Explore buildkitd.
- Host: GitHub
- URL: https://github.com/flyer103/buildkit-demo
- Owner: flyer103
- License: apache-2.0
- Created: 2022-07-18T09:07:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-06T08:51:53.000Z (over 2 years ago)
- Last Synced: 2024-11-14T07:12:43.069Z (2 months ago)
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
Some demos for exploring [buildkitd](https://github.com/moby/buildkit).
# Demo
## Dependencies
- Golang: https://go.dev/dl/
- Docker: https://docs.docker.com/
- Image: https://hub.docker.com/r/moby/buildkit
- CLI:
- buildctl: https://github.com/moby/buildkit
- jq: https://stedolan.github.io/jq/## hardcode-image
The demo hardcodes [LLB](https://github.com/moby/buildkit#exploring-llb) to understand how Frontends converts image source to LLB.
Get json formatted LLB:
```shell
$ go run cmd/hardcode-image/main.go | buildctl debug dump-llb | jq .
```Build:
```shell
$ docker run -d --name buildkitd --privileged moby/buildkit:v0.10.3
$ export BUILDKIT_HOST=docker-container://buildkitd
$ go run cmd/hardcode-image/main.go | buildctl build --local context=. --output type=tar,dest=out.tar
```You can unpack `out.tar` and find `README.md` and `built.txt` files which are operated in the program.
You can also modify the output type to build the type that `buildkitd` supports: [Output](https://github.com/moby/buildkit#output).
## hardcode-scratch
The demo hardcodes [LLB](https://github.com/moby/buildkit#exploring-llb) to understand how Frontends converts scratch source to LLB.
Get json formatted LLB:
```shell
$ go run cmd/hardcode-scratch/main.go | buildctl debug dump-llb | jq .
```Build:
```shell
$ docker run -d --name buildkitd --privileged moby/buildkit:v0.10.3
$ export BUILDKIT_HOST=docker-container://buildkitd
$ go run cmd/hardcode-scratch/main.go | buildctl build --local context=. --output type=tar,dest=out.tar
```You can unpack `out.tar` and find copied files which are operated in the program.
You can also get a feel for buildkitd's parallel builds and caching by looking at the execution.
Note:
- I don't understand the internals yet -_-## frontend-mockerfile
This demo uses other people's examples to see how buildkitd frontend is implemented: [detail](./cmd/frontend-mockerfile/README.md).
Get json formatted LLB:
```shell
$ go run cmd/frontend-mockerfile/main.go -filename cmd/frontend-mockerfile/Mockerfile.yaml -graph | buildctl debug dump-llb | jq .
```Build:
```shell
# You should change image registry in the following script.
$ ./build/build-frontend-mockerfile.sh# PUSH IMAGE THAT IS BUILT ABOVE.
$ docker push# Image Example: `ccr.ccs.tencentyun.com/flyer103/frontend-mocker:latest`
$ buildctl build --frontend=gateway.v0 --opt source= --local context=. --local dockerfile=./yaml/frontend-mockerfile/ --output type=oci,dest=output.tar
```If you add `# syntax=ccr.ccs.tencentyun.com/flyer103/frontend-mocker:latest` to the first line of `yaml/frontend-mockerfile/Mockerfile.yaml`, you could also use `docker build` as following:
```shell
$ docker build . -t demo:0.1 -f yaml/frontend-mockerfile/Mockerfile.yaml
```Note:
- `syntax` directive in the yaml file is not a must if we use `buildctl`