-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dockerfile-llb-frontend): Add the initial LLB frontend code (#706)
Reviewed-by: Alexander Jung <alex@unikraft.io> Approved-by: Alexander Jung <alex@unikraft.io>
- Loading branch information
Showing
14 changed files
with
2,715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: tools/dockerfile-llb-frontend | ||
|
||
on: | ||
push: | ||
branches: [stable] | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: [staging] | ||
paths: | ||
- 'tools/dockerfile-llb-frontend/**' | ||
- '.github/workflows/dockerfile-llb-frontend.yaml' | ||
|
||
jobs: | ||
plugin-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Registry | ||
if: ${{ github.event_name == 'push' }} | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: index.unikraft.io | ||
username: ${{ secrets.REG_USERNAME }} | ||
password: ${{ secrets.REG_TOKEN }} | ||
|
||
- name: Build OCI image for the LLB plugin | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./tools/dockerfile-llb-frontend | ||
file: ./tools/dockerfile-llb-frontend/Dockerfile | ||
tags: index.unikraft.io/kraftkit.sh/llb:latest | ||
push: ${{ github.event_name == 'push' }} | ||
platforms: linux/amd64 | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*/.vscode* | ||
test/ | ||
*_test.go | ||
*.bak | ||
*.swp | ||
*.idea | ||
*.orig | ||
.DS_Store | ||
*.md | ||
.git/ | ||
.gitignore | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2022, NEC Europe Ltd., Unikraft GmbH, and The KraftKit Authors. | ||
# Licensed under the BSD-3-Clause License (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
|
||
FROM golang:1.20 AS builder | ||
|
||
WORKDIR /src | ||
COPY . ./ | ||
RUN CGO_ENABLED=0 go build -o /kraft-llb-plugin --ldflags "-s -w" | ||
|
||
FROM scratch | ||
COPY --from=builder /kraft-llb-plugin /bin/kraft-llb-plugin | ||
ENTRYPOINT ["/bin/kraft-llb-plugin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# KraftKit LLB Plugin | ||
|
||
This KraftKit LLB Plugin enables running Unikraft builds using Docker commands. | ||
|
||
It eliminates the need for installing KraftKit or Unikraft-specific dependencies on your machine by executing builds in containers. | ||
|
||
The result is a Unikraft image saved in your local Docker registry. | ||
|
||
**Please note:** If you are unfamiliar with Unikraft, KraftKit, or unikernels, kindly refer to the [Unikraft Documentation](https://unikraft.org/docs/getting-started/). | ||
|
||
## Prerequisites | ||
|
||
- Docker with BuildKit enabled (this is the default setting from Docker v23.0 onwards) | ||
- Go v1.20 or later | ||
|
||
## Usage | ||
|
||
There are two ways to use the LLB plugin: | ||
|
||
### 1. Docker-based Usage | ||
|
||
Build the Docker image containing the plugin: | ||
|
||
```sh | ||
docker build . -t kraftkit.sh/llb | ||
``` | ||
|
||
Modify your Kraftfile file by adding the following line at the top: | ||
|
||
```yaml | ||
#syntax=kraftkit.sh/llb:latest | ||
``` | ||
|
||
Now, run the Docker build: | ||
|
||
```sh | ||
docker build -f test/apps/app-helloworld/kraft.yaml test/apps/app-helloworld | ||
``` | ||
|
||
See [Docker docs about dynamic frontends](https://docs.docker.com/build/dockerfile/frontend/) for more information. | ||
|
||
### 2. Direct Binary Usage (Debug Mode) | ||
|
||
In this mode, you can output the LLB graph for inspection with buildkit. | ||
|
||
First, build the project: | ||
|
||
```sh | ||
go build . | ||
``` | ||
|
||
Then, run the built binary from within a Unikraft app directory: | ||
|
||
```sh | ||
dockerfile-llb-frontend --llb-stdout=true | buildctl debug dump-llb | ||
``` | ||
|
||
To learn more about this, see this [BuildKit doc](https://github.com/moby/buildkit/blob/master/examples/README.md). | ||
|
||
## Contributing | ||
|
||
We warmly welcome contributions in the form of tests, bug reports, and feature requests. | ||
|
||
For discussions or queries, join us on Discord: https://bit.ly/UnikraftDiscord | ||
|
||
### Testing | ||
|
||
The project has unit tests for the core build part (./build/build_test.go) and end-to-end | ||
tests suites in the test/apps directory, one for BuildKit and one for Docker. | ||
|
||
The Docker suite calls the docker-backing BuildKit daemon so in a way the BuildKit tests | ||
are redundant, thus we omit them from the CI flow. They come in handy if you want to | ||
run a BuildKit daemon with a debugger. | ||
|
||
To run these tests: | ||
|
||
Docker: | ||
|
||
```sh | ||
go test ./test/docker -v | ||
``` | ||
|
||
BuildKit (you have to run buildkit daemon): | ||
|
||
To spawn a BuildKit daemon, run: | ||
|
||
```sh | ||
buildkitd | ||
``` | ||
|
||
Then run the test suite: | ||
|
||
```sh | ||
go test ./test/buildkit -v | ||
``` | ||
|
||
The -v option gives you the output of the BuildKit or Docker runs. |
Oops, something went wrong.